Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Created November 20, 2022 19:27
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 damiencarbery/f4a5833d3ade85ccc68553a6ca4c4cb3 to your computer and use it in GitHub Desktop.
Save damiencarbery/f4a5833d3ade85ccc68553a6ca4c4cb3 to your computer and use it in GitHub Desktop.
Create a new admin user programmatically - If you have ftp access you can create an admin user for yourself.
<?php
/*
Plugin Name: Create a new admin user programmatically
Plugin URI: https://www.damiencarbery.com/2022/11/create-a-new-admin-user-programmatically/
Description: If you have ftp access you can create an admin user for yourself.
Author: Damien Carbery
Version: 0.1
*/
// Code originally from https://wphub.me/create-new-wordpress-admin-user-programmatically/
function wpb_admin_account(){
$user = 'damiencarbery'; // Change these values before you upload this file.
$pass = 'Hb57%b9nc$4W'; // I've never used this password :-)
$email = 'damien@damiencarbery.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
}
add_action( 'init', 'wpb_admin_account' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment