Created
March 15, 2016 17:33
-
-
Save yawalkar/4c55f42973f8632112bc to your computer and use it in GitHub Desktop.
Create New Admin User if you forgot username and password of admin user. You need to have cpanel / FTP access of your site.
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 | |
/* | |
* Create Admin User | |
*/ | |
$wp_password = 'PASSWORD'; #enter your desired password here, if you don't line 16 makes sure nothing bad happens like setting you actual password to 'PASSWORD' | |
$wp_username = 'new-admin'; | |
$wp_email = '[email protected]'; | |
if ( $wp_password === 'PASSWORD' ) | |
die; | |
require_once('wp-blog-header.php'); | |
if ( !username_exists($wp_username) && !email_exists($wp_email) ) { | |
$user_id = wp_create_user( $wp_username, $wp_password, $wp_email); | |
if ( is_int($user_id) ) { | |
$wp_user_object = new WP_User($user_id); | |
$wp_user_object->set_role('administrator'); | |
echo 'Success!'; | |
} else { | |
echo 'Error with wp_insert_user. No users were created.'; | |
} | |
} else { | |
echo 'This user or email already exists. Nothing was done.'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment