Created
August 13, 2025 18:14
-
-
Save kpirnie/96191b38e8ec75397747bf727d8be2fa to your computer and use it in GitHub Desktop.
WordPress - Create Admin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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