Last active
June 7, 2017 05:30
-
-
Save remcotolsma/a3b83433a659bfe8a374 to your computer and use it in GitHub Desktop.
WordPress create an multisite/network super user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ADD NEW ADMIN USER TO WORDPRESS | |
// ---------------------------------- | |
// Put this file in your Wordpress root directory and run it from your browser. | |
// Delete it when you're done. | |
require_once 'wp-load.php'; | |
require_once 'wp-includes/registration.php'; | |
$user_id = 5; | |
$blogs = get_blog_list( 0, 'all' ); | |
foreach ( $blogs as $blog ) { | |
add_user_to_blog( $blog['blog_id'], $user_id, 'administrator' ); | |
} | |
$admins = get_super_admins(); | |
if ( ! in_array( $email, $admins ) ) { | |
$admins[] = '[email protected]'; | |
update_site_option('site_admins', $admins); | |
} | |
function grant_super_admin( $user_id ) { | |
global $super_admins; | |
// If global super_admins override is defined, there is nothing to do here. | |
if ( isset($super_admins) ) | |
return false; | |
do_action( 'grant_super_admin', $user_id ); | |
// Directly fetch site_admins instead of using get_super_admins() | |
$super_admins = get_site_option( 'site_admins', array( 'admin' ) ); | |
$user = new WP_User( $user_id ); | |
if ( ! in_array( $user->user_login, $super_admins ) ) { | |
$super_admins[] = $user->user_login; | |
update_site_option( 'site_admins' , $super_admins ); | |
do_action( 'granted_super_admin', $user_id ); | |
return true; | |
} | |
return false; | |
} | |
grant_super_admin($user_id); | |
//http://wordpress.org/support/topic/recover-super-admin-access-after-username-change?replies=13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment