Skip to content

Instantly share code, notes, and snippets.

@amityweb
Last active March 18, 2024 16:25
Show Gist options
  • Save amityweb/55a861434f8836eed780f12df1040d44 to your computer and use it in GitHub Desktop.
Save amityweb/55a861434f8836eed780f12df1040d44 to your computer and use it in GitHub Desktop.
Function to add new user to Wordpress
/***********************
ADD USER
Useful script to programatically add an admin user to Wordpress if you dont have access to the admin, but do have access to the file system
***********************/
function wpb_admin_account()
{
$user = 'adminusername'; // Your username
$pass = 'adminpassword'; // Your password
$email = '[email protected]'; // Your email
if ( !username_exists( $user ) && !email_exists( $email ) )
{
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
}
add_action('init','wpb_admin_account');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment