Skip to content

Instantly share code, notes, and snippets.

@wilnaweb
Created February 6, 2020 23:01
Show Gist options
  • Save wilnaweb/ed8d16f0bc23629716f17e6471b21f50 to your computer and use it in GitHub Desktop.
Save wilnaweb/ed8d16f0bc23629716f17e6471b21f50 to your computer and use it in GitHub Desktop.
Add new wordpress user with functions.php
## Add code in functions.php
## Define user, password and email account
function my_admin_account(){
$user = 'myuser';
$pass = 'mypass';
$email = '[email protected]';
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');
}
}
add_action('init','wpb_admin_account');
## Enter login page mysite.com/wp-admin.
## Enter user and pass.
## Remove function after create user.
## After logged wordpress admin, create new password.
## Reference: https://www.wpbeginner.com/wp-tutorials/how-to-add-an-admin-user-in-wordpress-using-ftp/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment