Created
May 14, 2019 11:46
-
-
Save itsmikita/a64f5a5ea532f5827b4c4189b89c08a8 to your computer and use it in GitHub Desktop.
Create new Admin user in WordPress
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 | |
/** | |
* Creates new user with Administrator capabilities | |
* | |
* Put this code snippet to your theme's functions.php | |
* and change $username, $password and $email. The code | |
* checks if $username does not exist and creates a new | |
* user. | |
* | |
* NOTE: This runs on every page load, so don't forget | |
* to comment this code out or remove it after you | |
* create the new user to save load time. | |
*/ | |
add_action( "init", function() { | |
$username = "itsmikita"; | |
$password = "passwort"; | |
$email = "[email protected]"; | |
if( ! username_exists( $username ) ) { | |
$userId = wp_create_user( | |
$username, | |
$password, | |
); | |
$user = get_user_by( "id", $userId ); | |
$user->remove_role( "subscriber" ); | |
$user->add_role( "administrator" ); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment