Add a Team Member to Every New Site
Adds a chosen user, such as your support or editorial account, to each newly created site with the role you pick.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
$wpide_login = 'support'; // Existing username to add.
$wpide_role = 'editor'; // Role on the new site.
add_action( 'wp_initialize_site', function ( $site ) use ( $wpide_login, $wpide_role ) {
$user = get_user_by( 'login', $wpide_login );
if ( $user && ! is_user_member_of_blog( $user->ID, $site->blog_id ) ) {
add_user_to_blog( $site->blog_id, $user->ID, $wpide_role );
}
}, 200 );
Notes
Set $wpide_login to an existing username and $wpide_role to any role that exists on new sites.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.