0

I took over an existing multisite network and I don't have the privileges to promote anyone to network admin through the WP Admin UI directly. How can I promote my site administrator to network admin via MySQL and/or WP CLI?

6
  • you want to create a Network Admin (aka Super Admin) ? Feb 7, 2017 at 22:34
  • no, I want to promote an existing admin to Super Admin
    – acobster
    Feb 7, 2017 at 22:40
  • 2
    Possible duplicate of Add Wordpress MU Network Admin via Database
    – acobster
    Feb 7, 2017 at 23:03
  • then why did you asked? Use google first, that's what recommended here! Feb 7, 2017 at 23:05
  • Understood, I got linked to the other question from WP IRC after posting this one
    – acobster
    Feb 7, 2017 at 23:06

3 Answers 3

2

You might use grant_super_admin()

To add an admin by user ID you can use grant_super_admin. Simple put grant_super_admin in your theme’s functions.php file (usually in /wp-content/themes/CURRENT THEME NAME/functions.php). You’ll need to put the ID of the user as a variable, the example below we’re using the user ID of 1.

grant_super_admin(1);

https://drawne.com/add-super-admin-wordpress-network/

Or Some variation of this should do the trick:

INSERT INTO `databasename`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('4', 'demo', MD5('demo'), 'Your Name', '[email protected]', 'http://www.test.com/', '2011-06-07 00:00:00', '', '0', 'Your Name');


INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');



INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_user_level', '10');

http://www.wpbeginner.com/wp-tutorials/how-to-add-an-admin-user-to-the-wordpress-database-via-mysql/

2
  • I already have a user with those capabilities. What I need is to promote the user to MULTISITE admin.
    – acobster
    Feb 7, 2017 at 22:28
  • 1
    See updated answer Feb 7, 2017 at 22:48
2

If you have access to the command line and can use wp-cli, then you need to run two commands (assuming your site ID is 1):

wp network meta get 1 site_admins

This will return an array of all the site admins. Here is a sample array:

array (
  0 => 'user',
  1 => 'tedmasterweb',
  2 => 'fredflintston',
  3 => 'jcollins',
)

You then need to execute the following command setting the key as 4 (one more than the highest number in the array above), e.g.:

wp network meta patch insert 1 site_admins 4 myusername

You might then need to log out and log back in to see the change.

Related documentation

https://developer.wordpress.org/cli/commands/network/meta/update/

1

Can you see this in user edit?

enter image description here

1
  • no, as I said in the original question I don't have the privileges to promote anyone to network admin through the WP Admin UI directly.
    – acobster
    Feb 7, 2017 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.