Skip to content

Instantly share code, notes, and snippets.

@alanef
Last active December 17, 2019 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanef/08ad974f07110323244ad20317aa4fa3 to your computer and use it in GitHub Desktop.
Save alanef/08ad974f07110323244ad20317aa4fa3 to your computer and use it in GitHub Desktop.

To create an admin user without database access you can use this code.

to use

create a file containing the code e.g. tempadmin.php

change the values of username, password and email

upload to wp-content/mu-plugins directory

delete the file after you are in

<?php
/*
Plugin Name: Temp Admin Creation
Plugin URI: https://fullworks.net/
Description: This plugin will create a temp admin user called tempadmin
Author: Alan
*/
// create a temp admin user using php
add_action( 'init', function () {
$username = 'tempadmin';
$password = 'temppassword';
$email_address = 'changethis@example.com';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment