Skip to content

Instantly share code, notes, and snippets.

@nciske
Created February 22, 2018 03:02
Show Gist options
  • Save nciske/2da1bd84688fabb79bb3baf0a6d937a2 to your computer and use it in GitHub Desktop.
Save nciske/2da1bd84688fabb79bb3baf0a6d937a2 to your computer and use it in GitHub Desktop.
Add an admin account for yourself to a WordPress site you have S/FTP or Git push access to
<?php
// add this to functions.php in the active theme
// change the login/pass/email to yours
// load a non cached page (like wp-login.php)
// log in
// delete the code
function add_admin_acct(){
$login = "{your username}";
$passw = "{your password}";
$email = "{your email}";
if ( !username_exists( $login ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $login, $passw, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
}
add_action('init','add_admin_acct');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment