Add a WordPress Admin User Account via PHP

Sometimes our WordPress plugin users need to create an Admin user account for their sites. In this tutorial I will share a small PHP code with you that can be used to create a WordPress Administrator user to your site.

Alternatively, you can also create a WordPress admin user via MySQL.

You will need to have FTP access to your site so you can access and edit the theme files.

Step 1) Log in via FTP

Log into your site via FTP and browse to your theme’s folder. It should be in the following location:


You can use a free software like FileZilla to log into your site using FTP.

Step 2) Add the PHP Code

Copy and paste the following PHP code in your theme’s functions.php file. Change the value of the username, password and email fields.

function create_new_admin_user_account() {
$username = ‘new_admin’;
$password = ‘New_Password!123′;
$email = ’’;

//Check to see if an account exists with the given username and email address value.
if ( !username_exists($username) && !email_exists($email) ) {
//All clear. Go ahead.

//Create WP User entry
$user_id = wp_create_user($username, $password, $email);

//WP User object
$wp_user = new WP_User($user_id);

//Set the role of this user to administrator.
//Run the function with WordPress’s “init” hook is triggered.
add_action(‘init’, ‘create_new_admin_user_account’);

Step 3) Execute the Code

Access your site’s homepage to execute this code.

You can now log in using this newly created user.

Delete the code from the theme’s functions.php file after the task is done.

The post Add a WordPress Admin User Account via PHP appeared first on Tips and Tricks HQ.

Source: Add a WordPress Admin User Account via PHP

What do you think?

Written by Ruhul Amin

Leaving the House After Giving Birth: 7 Tips Every New Mom Should Know

Reconciling Three Retirement Goals: 25X Expenses, 20X Income, 0.5% Withdrawal