Skip to content

Instantly share code, notes, and snippets.

@bcreeves
Created April 30, 2019 18:47
Show Gist options
  • Save bcreeves/bdb11f46efaa7ccd6a2cdfd5c375af22 to your computer and use it in GitHub Desktop.
Save bcreeves/bdb11f46efaa7ccd6a2cdfd5c375af22 to your computer and use it in GitHub Desktop.
Quick and dirty way to add yourself as user in Wordpress
<?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