Last active
November 25, 2019 21:13
-
-
Save MogulChris/c32644939990fabce9e8629b5dfea27c to your computer and use it in GitHub Desktop.
Create a WordPress administrator user via FTP
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 | |
//Need WordPress access but only have FTP access? | |
//This snippet will let you create an administrator user, as long as you can get it onto the server in the root of the site | |
//Then visit https://www.site.com/newadmin.php | |
//Finally, DELETE THE SCRIPT when you have gained access. | |
require_once('wp-load.php'); | |
$userdata = array( | |
'user_login' => 'newadmin', | |
'user_email' => '[email protected]', | |
'user_pass' => 'Secretpassword!!1' | |
); | |
$user_id = wp_insert_user( $userdata ); | |
if(is_wp_error($user_id)){ | |
echo $user_id->get_error_message(); | |
die(); | |
} | |
$user = new WP_User( $user_id ); | |
$user->add_role( 'administrator' ); | |
echo "Successfully created user {$userdata['user_login']}"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment