How to Add a WordPress User Account With a Specific Role Using cPanel

How to Add a WordPress User Account With a Specific Role Using cPanel

Whenever you’re not able to access your WordPress wp-admin panel due to the wrong login credentials, either you need to recover the password or create a new account.

If you want to create an administrator account, you can use the MySQL database, but if you wish to add a subscriber, contributor, or an editor, you have to deal with some coding lines.

Writing an SQL query for a specific user role can be tricky. You may be wondering as if what’s the easiest way to accomplish such a task.

Well, if you’re aware of the functions.php file of your WordPress theme, you can easily add a new user with a specific user role.

You may be wondering to edit the file from your WordPress admin panel, but due to security reasons, you may not see the editor.

To remove a vulnerability, WordPress experts suggest disabling the file editing. So, the best option is to use cPanel. I am sure; you know how to do it.

A Step By Step Guide to Add a New User

Before you proceed, you must have a backup of your WordPress website and its database. You should know that functions.php is one of the most important files, which controls all the functions of the site’s layout.

If you add a wrong code, the website layout may get disrupted. That’s why it’s vital to learn the correct way to copy and paste a custom code.

I am sure, you have seen the different layout of cPanel, it’s because every web hosting tries to improvise the default cPanel design to match its brand color.

Follow These Steps

Step 1:

Access your cPanel account and search for the file manager.

I hope you know that the data of a website resides in the file manager.

How to Add a WordPress User Account With a Specific Role Using cPanel

In most of the cases, you can see it under the Files’ section. Some web hosting companies offer a different spot.

Step 2:

Depending on your cPanel settings, you may see the home directory.

But you need to open publc_html, navigate to it from the left-side vertical menu.

How to Add a WordPress User Account With a Specific Role Using cPanel

Note: If you host multiple websites and try to update any other domain than a primary domain, you have to open the folder where WordPress installation is available.

For a single website, the data is available in the pulic_html directory.

Step 3:

As you know, all the themes, plugins, and media files are present in the wp-content folder, so open it.

How to Add a WordPress User Account With a Specific Role Using cPanel

Step 4:

You can see tons of folders. Click on Themes.

How to Add a WordPress User Account With a Specific Role Using cPanel

Step 5:

On this page, you can see all the inactive and the active themes of your WordPress site.

Right now, you need to edit the active theme, click on its folder to open.

How to Add a WordPress User Account With a Specific Role Using cPanel

Step 6:

Search for the functions.php and right-click to edit.

How to Add a WordPress User Account With a Specific Role Using cPanel

Step 7:

A new tab appears on the browser having all the WordPress functions of your site.

Now, let me show you a code to add a contributor.

functioncontributor_new_account(){
$user = 'Username';
$pass = 'Password';
$email = 'email@yoursite.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'contributor' );
} }
add_action('init','contributor_new_account');

Note: Don’t forget to replace the username , password, and the email address with the ones you want to use as your login credentials.


If you have noticed, there is a coding line displaying the user role.

$user->set_role( 'contributor' );



You can replace it to set any user role. For a subscriber, the code is as follow.

functioncontributor_new_account(){
$user = 'Username';
$pass = 'Password';
$email = 'email@yoursite.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'subscriber' );
} }
add_action('init','contributor_new_account');

If you’re wondering about the contributor_new_account() function, it’s just a name, you can change it if you want. But if you have no idea about WordPress codex, please copy and paste the code to your file.


You need to change the user role, nothing else. For example, the code to add an editor is as follow.

functioneditor_new_account(){
$user = 'Username';
$pass = 'Password';
$email = 'email@yoursite.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'editor' );
} }
add_action('init','editor_new_account');

Depending on your requirement, you can add a user with its role, and click on the Save Changes button to save the file.

Try clearing the browser cache and cookies before logging in to your WordPress website. If you see such a new user, congrats, you have successfully learned to create a new user with a specific role.

Conclusion

Whether you create an administrator or an editor, you can use the code by a little bit of modification. If you understand the concept of WordPress codex, changing the function and the user role is easy.

For a non-techie person, the only requirement is to choose the user role, and save the code. I hope it’s not so hard.

Check out these top 3 WordPress hosting services:

A2 Hosting
$2.99 /mo
Starting price
Visit A2 Hosting
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.8
  • Pricing
    4.0
IONOS
$1.00 /mo
Starting price
Visit IONOS
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.3
HostArmada
$2.49 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0

How to Add a WordPress Administrator User Using FTP

This how-to guide provides you an alternative to add a new WordPress administrat
3 min read
Arvind Singh
Arvind Singh
Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top