Skip to content

Instantly share code, notes, and snippets.

@apermo
Created September 8, 2021 10:11
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 apermo/fa9e7a53154f817de93726eecf4b68dc to your computer and use it in GitHub Desktop.
Save apermo/fa9e7a53154f817de93726eecf4b68dc to your computer and use it in GitHub Desktop.
Self Destructing Create Admin User for WordPress
<?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