|
/ Documentation /Blocks/ How to Register High-Privileged Users on Your Website

How to Register High-Privileged Users on Your Website

Spectra prevents high-privileged users like “admin,” from registering through the Registration Form block. This is due to security reasons, as it’s crucial not to allow unknown users to have admin privileges.

Only certain user roles are allowed to register on your site. Moreover, the option to select a user role is visible only to existing admins/super admins:

As you can see, we’ve also removed the ‘admin’ and ‘editor’ user roles from the “New User Role” list. This way, you can easily manage other site user roles.

Low-level users like subscribers, contributors, and others won’t even see this dropdown:

However, we recognize that there may be situations where you need a high-privilege “admin” user to sign up on your site.

For example, if you’re providing personalized training, you might want a customer to briefly have admin access to grasp the website’s features better.

To do this, we offer a filter that allows you to bypass these rules and register any user role you need. You can also show the user role dropdown to low-level users like Editors or Contributors.

In this article, we will cover both these topics:

Allowing High-Privileged Users to Register on Your Site

To do this, paste the following code snippet in your child theme’s functions.php file.

add_filter( 'spectra_pro_registration_form_change_new_user_role', 'spectra_enforce_admin_user' );

function spectra_enforce_admin_user( $role ) {

return 'administrator'; // Update your user role slug here as required.

}

For Astra users, functions.php will be available at Appearance > Theme File Editor.

Click on the Update File button once done.

Now, anyone registering through the form will have “Administrator” access.

Note: This approach is not recommended as a first resort. Before implementing it, carefully assess and explore alternative solutions. If no other workaround is feasible, then use this code.

If you want to show the “New User Role” option to users with low privileges, add the following code to your child theme’s functions.php file.

add_filter( 'spectra_pro_registration_form_role_manager', 'provide_field_access_to_user_role', 10, 1 );

function provide_field_access_to_user_role( $handle_user_role ) {

    $current_user  = wp_get_current_user();

    if ( $current_user instanceof WP_User ) {

        $user_roles = $current_user->roles;

        // Adjust your desired user roles in the following condition, so they can access the "New User Role" field in the editor UI.

        if (

            in_array( 'editor', $user_roles, true ) || 

            in_array( 'author', $user_roles, true ) 

        ) {

            $handle_user_role = true;

        }

    }

    return $handle_user_role;

}

The code above lets low-privileged users choose the user role. To add desired user roles, modify the above code as dictated. 

Note: If you choose ‘Select’, it picks the default role for new users, as set in WordPress Settings under General > New User Default Role.

That’s it! At Spectra, we care about your security. That’s why, we always recommend our users to update themes & plugins with their latest versions to get better stability.

For any doubts, please feel free to open a support ticket below.

Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

On this page

🔥 Extended Cyber Savings: Shop Before It’s Gone!

00
Months
00
Days
00
Hours
00
Minutes
00
Seconds

WAIT!!

You’re Missing the Biggest Discount of the Year!

00
Months
00
Days
00
Hours
00
Minutes
00
Seconds

Grab this rare opportunity to save up to 50%

100% Risk-Free Money Back Guarantee!

Get Notified When Available

Note - You can purchase the Essential Toolkit now and easily upgrade to the Business Toolkit once it becomes available.

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Get your hands on Spectra Pro

Enter your name and email address to get access to Spectra Pro.