Skip to contentSkip to main navigation Skip to footer

4 Easy Ways To Add Admin User in WordPress

Want to add an admin user in WordPress?

In the initial setup for the WordPress site as a user, we would have not had a concern about having the user as a prime user or an Admin user. But later, necessities may lead to the need to change the regular user settings to an admin user for authorization, security accessing specific options, and controlling access to all files.

So, if you are facing this difficulty in changing a regular user to an ā€˜Admin userā€™ or a ā€˜Super Admin userā€™ then here are different methods through which you can make this same query committed to your website.

Add Admin User Programmatically in WordPress

Add Admin User

Add this code to the themes functions.php file and enter the username, password, and email address along with your credentials set for the admin login and eventually add user admin capabilities.

 /*
 * Create an admin user add programmatically
 */
 add_action('init', 'xyz1234_my_custom_add_user');
 function xyz1234_my_custom_add_user() {
     $username = 'username123';
     //set usename as per preference
     $password = 'pasword123';
     //set password as per preference
     $email = '[email protected]';
     //set email as per preference
     if (username_exists($username) == null && email_exists($email) == false) {
         // Create the new user
         $user_id = wp_create_user($username, $password, $email);
         // Get current user object
         $user = get_user_by('id', $user_id);
         // Remove role
         $user->remove_role('subscriber');
         // Add role
         $user->add_role('administrator');
     }
 } 

Pasting this code snippet in the functions.php file will eventually add the user with the $username, $password, and $email as the admin programmatically.

Change User to Admin WordPress (Phpmyadmin)

A stepwise guide to adding an admin user includes the following:

  1. Access the tool phpMyAdmin and access the MySQL database. In phpMyAdmin, edit your database as preferred.
  2. wp_users table: Select the WordPress database for your site from the list of databases sorted, and click on the wp_users table. Once done,  
  3. Insert a new WordPress admin user in the user’s table and name it accordingly.
  4. The details that are mandatory for creating an admin on the WordPress site include:
    • user_login: or username for the admin access
    • user_pass: or password for the admin access
    • user_email: or prime email address
    • user_registered: or date and time of registration.
    • user_status: zero is the value to be set.
  5. Once filled click on ā€œGoā€ to head over to the success acknowledgment page.
  6. Now returning to the wp_users table, you can find the new user added to the users existing. Note the ID provided.
  7. Now head over to the wp_usermeta table to fill away the meta details of the admin user.
  8. Click on Insert >> search for x_usermeta. Inside fill out these:
    • user_id: ID of the admin user that you noted in the wp_users table.
    • meta_key: add wp_capabilities as value.
    • meta key value: add a:1:{ s:13:ā€administratorā€; s:1:ā€™1ā€™;} as value.
  9. Click ā€œGoā€ to complete the user creation. By this, you add admin user settings to your preferred user and thus it is an admin user now.

Struggling to log into WordPress admin? Read How to Log Into WordPress Admin? 2 Easy Approaches.

Add Admin User WordPress Functions (PHP) Using FTP

The first and foremost necessity to add an admin user is being an FTP client. If you are a new user of FTP, refer to some basic concepts for a better understanding of the upcoming process.

<?php
 function wpb_admin_account(){
 $user = 'Username';
 $pass = 'Password';
 $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');
 ?>
  • Search for the themeā€™s functions.php file and download the file.
  • Open the downloaded file in a code editor or text editor and replace the username, password, and email ID with your admin accountā€™s values (the values set for the admin account are created).
  • Save the changes and upload the file again in the same location. Once done, try signing in with the credentials just entered in the file with the WordPress login page. If logged in the process is complete. Once entered via the credentials, delete the changed code piece that you added right now to the file. By this, you add admin user settings to your preferred user and thus it is an admin user now.

WordPress Admin Account

Adding a common account is fairly easy to adopt. Always adopting a temporary or expiring user admin account is best preferred for security reasons.

  1. Log in to the WordPress site and reach the dashboard
  2. Click on the user’s option in the menu bar located on the left side of your dashboard.
  3. Click ā€œAdd Userā€ click on the ā€œAdd Newā€ button fill out the details required and finally set the role of the user as ā€œAdministratorā€. When done, click on ā€œAdd New Userā€.
  4. Now, use the User ID and Password to log in and you will log in to the site as an administrator. By this, you add admin user settings to your preferred user and thus it is an admin user now.

WordPress Create Super Admin in Database – Additional Addon.

Adding a Super Admin user is possible by adding a script to your functions.php, phpMyAdmin, or via the network to add an admin user.

Using Network Admin for Creating Super Admin:

In the settings, below the username option, you can find the super admin option where it will ask for ā€œGrant this user super admin privileges for the networkā€. Tick the checkbox and refresh the page. Now your user is a Super Admin User.

MYSQL Create Admin User - Add User PHPMYADMIN - Add admin user

Using phpMyAdmin for creating Super Admin:

"a:2:{i:1;s:5:"admin";i:2;s:4:"Andy";}"

 Add this code snippet and refresh to see the changes.

Here,

  • a:2 refers to the number of entries entered admin user. You will change this no. once an admin is entered as a new entry.
  • i:1 and s:5 are simply the copied code from the previous entries and refer to the number of characters.
  • Andy refers to the sample username entered. You should enter your username which should be changed to Super Admin(Or)
  • Open the portal select ā€˜the environment name and click through phpMyAdmin which is located at the top of the site.
  • Select your database by clicking on any of the databases. wp_environment is the primary database for the environment. Then is this snapshot_environment which is the legacy staging database for the environment. Choose the right database that suits you.
  • Select wp_users and customize the database prefix or your youprefix_users.
  • Insert a user and add the login details as given in the previous sections.
  • Additionally, you will be requested to add the display_name, user_status, and user_nicename apart from user_email, user_name, and user_pass.
  • Now click on ā€œGoā€ and Go again in the query page display, Once done a green tick mark will appear to confirm your userā€™s activation as Super Admin. By this, you add user super admin settings to your preferred user and thus it is a super admin user now.

Wrapping Up

We hope you liked this blog. After reading this blog you might be able to add admin user to your WordPress website. Sometimes your website or WordPress might get hacked and you may lose your admin account. To avoid such vulnerabilities, adding an admin user can be a savior as it can help you restore the site quickly.

If you like reading this blog on how you can easily add admin user in WordPress, you may also read our expert’s detailed guide on How to create a Gravatar for WordPress ā€“ A Simplified Guide. and How to Find the Hosting Company of a Website? (3 Easy Ways).

icons icons icons icons icons icons icons

Stuck Somewhere?
Connect With JustHyre

Hire WordPress Engineers for custom jobs like Website Customization, SEO Optimization, Clearing a Hacked Website, Installation & Configuration & more.

Connnect with JustHyre
0 Comments

There are no comments yet

Leave a comment

Your email address will not be published. Required fields are marked *