Skip to content

Instantly share code, notes, and snippets.

@soderlind
Last active November 23, 2017 00:20
Show Gist options
  • Select an option

  • Save soderlind/b0a7abc91eaa2646db38b81acfb532a1 to your computer and use it in GitHub Desktop.

Select an option

Save soderlind/b0a7abc91eaa2646db38b81acfb532a1 to your computer and use it in GitHub Desktop.
Add All WordPress Super-Admins to a New Site, put file in wp-content/mu-plugins
<?php
/**
* Plugin Name: Add All Super-Admins to a New Site
* Description: Will attempt to add all super-admins to a site when it's created.
* Version: 0.1.0
* Plugin URI: https://gist.github.com/soderlind/b0a7abc91eaa2646db38b81acfb532a1
* Author: Per Soderind
* Author URI: https://soderlind.no
* Requires PHP: 7.0.0
*/
add_action( 'wpmu_new_blog', function( int $blog_id, int $user_id, string $domain, string $path, int $network_id, array $meta ) {
$super_admins = get_super_admins();
foreach ( $super_admins as $super ) {
$user = get_user_by( 'login', $super );
if ( ! is_user_member_of_blog( $user->ID, $blog_id ) ) {
add_user_to_blog( $blog_id, $user->ID, 'administrator' );
}
}
}, 10, 6 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment