Skip to content

Instantly share code, notes, and snippets.

@ideadude
Created February 13, 2018 17:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ideadude/b65cb51984db740bd9fe5de2fd4b2a0e to your computer and use it in GitHub Desktop.
Save ideadude/b65cb51984db740bd9fe5de2fd4b2a0e to your computer and use it in GitHub Desktop.
Create a WordPress administrator user account via PHP/FTP.
<?php
/*
Sometimes you have FTP access to a site, but don't have a WP administrator account.
You can use this code to create one.
1. Add this code into any plugin or theme file that you know will be run.
2. Visit /?createmyadministratoruser=1.
3. Delete the code you added.
*/
function init_create_my_administrator_user() {
if(!empty($_REQUEST['createmyadinistratoruser'])) {
wp_insert_user(array(
'user_login' => 'tempadmin', //change this
'user_pass' => 'temppass123', //change this
'user_email' => 'temp@temp.com', //change this
'role' => 'administrator',
));
echo "Admin user created. Remember to delete the code you added for this.";
exit;
}
}
add_action('init', 'init_create_my_administrator_user');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment