Grant only Editor role to WordPress Multisite admins

50 Views Asked by At

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.

2

There are 2 best solutions below

0
On
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

0
On

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();
    }