Last active
April 26, 2022 20:29
-
-
Save sbruner/36a5310f4ea4d7a44ed4742e4be402c1 to your computer and use it in GitHub Desktop.
Creates administrator and super administrator role (WP Multisite)
This file contains 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 | |
/** | |
* sfire_create_user | |
* | |
* Auto create a user | |
* Creates administrator and super administrator role (WP Multisite) | |
* Can be used when you have SFTP access but no user access | |
* 1. create a wp-content/mu-plugins folder | |
* 2. Upload this file | |
* 3. Visit your site and log in. | |
*/ | |
function sfire_create_user() { | |
$username = 'YOUR_USER_NAME'; | |
$password = 'YOUR_PASSWORD'; | |
if ( username_exists( $username ) ) { | |
return; | |
} else { | |
$userdata = array( | |
'user_login' => $username, | |
'user_pass' => $password, | |
'role' => 'administrator', | |
); | |
$user_id = wp_insert_user( $userdata ); | |
grant_super_admin( $user_id ); | |
} | |
} | |
add_action( 'init', 'sfire_create_user' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment