Created
April 30, 2019 18:47
-
-
Save bcreeves/bdb11f46efaa7ccd6a2cdfd5c375af22 to your computer and use it in GitHub Desktop.
Quick and dirty way to add yourself as 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 | |
add_action('init', function () { | |
$username = ''; | |
$password = ''; | |
$email = ''; | |
// Reset pass if exist | |
// $id = get_user_by('email', $email)->ID; | |
// wp_set_password('', $id); | |
if (username_exists($username) == null && email_exists($email) == false) { | |
$user_id = wp_create_user($username, $password, $email); | |
$user = get_user_by('id', $user_id); | |
$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