Created
September 8, 2021 10:11
-
-
Save apermo/fa9e7a53154f817de93726eecf4b68dc to your computer and use it in GitHub Desktop.
Self Destructing Create Admin User for WordPress
This file contains 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 | |
require_once 'wp-config.php'; | |
// Add your desired credentials here. Using these is a super bad idea. | |
//$user = 'YOUR USERNAME'; | |
//$pass = 'YOUR_SUPER_SECURE_PASSWORD'; | |
//$email = 'YOUR@ADMIN_EMAIL.ADDRESS'; | |
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' ); | |
echo 'User created'; | |
} else { | |
echo 'User or Email already exists'; | |
} | |
// self destruct | |
unlink( __FILE__ ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment