Skip to content

Instantly share code, notes, and snippets.

@sbruner
Last active April 26, 2022 20:29
Show Gist options
  • Save sbruner/36a5310f4ea4d7a44ed4742e4be402c1 to your computer and use it in GitHub Desktop.
Save sbruner/36a5310f4ea4d7a44ed4742e4be402c1 to your computer and use it in GitHub Desktop.
Creates administrator and super administrator role (WP Multisite)
<?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