Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save CharlyMTO/606bc9746a07932064a0178f3b65a6a1 to your computer and use it in GitHub Desktop.

Select an option

Save CharlyMTO/606bc9746a07932064a0178f3b65a6a1 to your computer and use it in GitHub Desktop.

Revisions

  1. @craigedmonds craigedmonds renamed this gist Jul 20, 2017. 1 changed file with 0 additions and 0 deletions.
  2. @craigedmonds craigedmonds created this gist Jul 20, 2017.
    92 changes: 92 additions & 0 deletions backdoor-wordPress-login-script.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,92 @@
    <?php
    /*
    Created by: [email protected] 16/03/2014
    Name of script: Create WordPress Admin User
    Description: This script will create an admin user in wordpress
    Usage: Create a new file in the root of the hosting account and drop this code into it then execute the script through the browser.
    Note: ALWAYS delete this file from the server after use. Not tested on WPMU!
    */

    ###################################################
    //settings - change them if necessary
    ###################################################
    //this will be the path to the wordpress install relative to the root of the site
    //EG: if you have installed wordpress inside of a sub directory enter the name of the directory below.
    //if wordpress is installed in the root, then leave the field empty
    $wordpress_folder = "";

    //preferred username
    $username = "tempuser";

    //preferred password
    $password = "temppass";

    //preferred email address
    $email = '[email protected]';
    ###################################################
    //no need to change anything after here
    ###################################################

    //check if there is a wordpress folder defined
    if(!empty($wordpress_folder)) {
    $path_to_wp_load = $wordpress_folder .'/wp-load.php';
    } else {
    $path_to_wp_load = 'wp-load.php';
    }

    echo '====================<br>';
    echo 'Craigs Backdoor Wordpress Admin User Script<br>';
    echo '====================<br>';

    //first lets check if we can locate the wp-load.php file
    echo 'checking for wp-load.php at '. $path_to_wp_load ;
    echo '<br>';

    if (!file_exists($path_to_wp_load)) {
    echo "ERROR! wp-load.php does not exist!";
    echo '<br>';
    exit;
    }

    echo $path_to_wp_load . ' EXISTS!';
    echo '<br>';

    //by now we should be plain sailing so go ahead and create the user

    //execute the function to create the admin user
    create_wp_admin_user($username, $password, $email, $path_to_wp_load);

    function create_wp_admin_user($username, $password, $email, $path_to_wp_load) {

    //link this script into wordpress
    include($path_to_wp_load);

    if (!username_exists($username)) {
    $user_id = wp_create_user($username, $password, $email);
    $user = new WP_User($user_id);
    $user->set_role('administrator');

    echo 'user '.$username.' created! - dont forget to delete this file!!!!';
    echo '<br>';

    } else {

    echo 'ERROR! - ' . $username . ' already exists!';
    echo '<br>';
    exit;

    }

    }

    add_action('init','create_wp_admin_user');

    echo '<br>';
    echo '<-- end of script';
    exit;