ken4ward
ken4ward

Reputation: 2296

Grant only Editor role to WordPress Multisite admins

My question is simple when a user creates a new blog/website, the user is granted an Administrator role over that site/blog, is there a way to reduce their role to Editor and not an administrator on creating a site?

This should be restricted to only their site and not when they are on any other sites on the WordPress multisite network.

Upvotes: 1

Views: 46

Answers (2)

StudioHeads
StudioHeads

Reputation: 31

function user_role_to_new_blog($blog_id, $user_id) {
    add_user_to_blog($blog_id, $user_id, 'editor' );
}

add_action( 'wpmu_new_blog', 'user_role_to_new_blog', 10, 2 );

Be careful as 'wpmu_new_blog' is now depreciated

Upvotes: 1

Lotem Vanunu
Lotem Vanunu

Reputation: 11

yes.

you can use the hook: wpmu_new_blog. this hook is run after new website created.

add_action( 'wpmu_new_blog', 'wpmu_reduce_to_editor');
function wpmu_reduce_to_editor( $blog_id, $user_id, $domain, $path, $site_id, 
$meta ) {
    switch_to_blog( $blog_id );
    // Change user role to editor
    wp_update_user( array(
            'ID'        => $user_id,
            'role'     => 'editor'
        ) 
    );
   restore_current_blog();
    }

Upvotes: 1

Related Questions