Skip to content

Instantly share code, notes, and snippets.

@alanef

alanef/readme.md

Last active Dec 17, 2019
Embed
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

<?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
You can’t perform that action at this time.