Skip to content

Instantly share code, notes, and snippets.



Last active Dec 17, 2019
What would you like to do?

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

Plugin Name: Temp Admin Creation
Plugin URI:
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 = '';
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
You can’t perform that action at this time.