Skip to content

Instantly share code, notes, and snippets.

@kpirnie
Created August 13, 2025 18:14
Show Gist options
  • Save kpirnie/96191b38e8ec75397747bf727d8be2fa to your computer and use it in GitHub Desktop.
Save kpirnie/96191b38e8ec75397747bf727d8be2fa to your computer and use it in GitHub Desktop.
WordPress - Create Admin
<?php
// include the wp-config.php file
include "/CHANGE_THIS_PATH/wp-config.php";
// set a username
$username = 'CHANGE_THIS';
// set a password
$password = 'CHANGE_THIS';
// set the email address
$email = 'CHANGE_THIS@CHANGE_THIS.ext';
//Check to see if an account exists with the given username and email address value.
if ( ! username_exists( $username ) && ! email_exists( $email ) ) {
//All clear. Go ahead.
//Create WP User entry
$user_id = wp_create_user( $username, $password, $email );
//WP User object
$wp_user = new WP_User( $user_id );
//Set the role of this user to administrator.
$wp_user -> set_role( 'administrator' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment