No results found. Try again with different words?

Search must be at least 3 characters.

How To Hide Astra Settings for Specific User Roles?

Sidebar Image

Did not find a solution? We are here to help you succeed.

Astra Settings that you can find on each page or post of your website contain meta settings that give the user more control and the possibility of even overriding some customizer settings on each page or post. This document will show you how to hide Astra Settings for specific user roles on your website, thus limiting their access to these settings.

Why Would I Have a Need To Hide These Settings?

Meta settings are handy for additional customization of a specific page or post that needs to be different from the rest of your website. But, on the other hand, this can impact the design and even disturb the functioning of your website (for example, Disabling Primary Header on Homepage). 

If your website has a more significant number of users with different user roles, or you’re giving access to outside service providers, these users would probably require access to your content on all or some pages or posts. At the same time, they would typically have access to the meta settings too. Thus, your website might require limiting access to Astra’s Meta Settings for specific user roles while still allowing them access to pages or posts content. This might be a security measure or just the prevention of accidental issues with a website design and functions.

How To Do This?

Achieving this would require adding in a little bit of custom code to your website. Please follow these steps:

Step 1 – Check your User Roles and the exact names of the User Roles you would like to limit. WordPress comes with some default user roles:

  • Super Administrator
  • Administrator
  • Editor
  • Author
  • Contributor
  • Subscriber

Also, some plugins could add additional User Roles to this list. You can check your Users and User Roles at Dashboard > Users.

Step 2 – Add the following filter to the functions.php file of your Child Theme:

add_action( 'do_meta_boxes', 'ast_remove_plugin_metaboxes' );

/**
* Remove Astra settings meta box for users that are not administrators
*/
function ast_remove_plugin_metaboxes(){
    if ( ! current_user_can( 'administrator' ) ) {
        remove_meta_box( 'astra_settings_meta_box', 'page', 'side' ); // Remove Astra Settings in Pages
        remove_meta_box( 'astra_settings_meta_box', 'post', 'side' ); // Remove Astra Settings in Posts
    }
}

The code mentioned above will be applied to the user roles lower than the Administrator user role – to apply this to different user roles, you can change the bolded role name “administrator” to any user role you wish. This will limit access to Astra’s Meta Settings for all lower roles that the one set in the code. For example, if we would want to set this limit to lower roles than Editor, this line of the code would look like this:

if ( ! current_user_can( 'editor' ) ) {

This change will now allow access to Astra’s Meta Settings to Administrators and Editors but limit it for all other (lower) roles.

Also, the code above will hide Astra Settings on both pages and posts. If you wish to, for example, leave access to these settings in Posts but hide it on Pages for a specific user role, you can do this by removing the line of code related to Posts:

remove_meta_box( 'astra_settings_meta_box', 'post', 'side' ); // Remove Astra Settings in Posts

Block based meta settings

The above filter will work for the classic editor. However, the Block based metabox should prevent the changes in some cases. In that case, you will need to use the following filter.

/**
 * Remove Astra settings (Block based) meta box for users that are not administrators.
 */
add_filter( 'astra_settings_metabox_register', 'ast_remove_block_metabox' );
function ast_remove_block_metabox( $to_show ) {
	if ( ! current_user_can( 'administrator' ) ) {
		$to_show = false;
	}
	return $to_show;
}

If you don’t have your Child Theme installed, please check this article on how to do it.
If you are not sure how to add this code, please check this article.

Was this article helpful?
Sidebar Image

Did not find a solution? We are here to help you succeed.

Related Docs

Join 1,653,898+ Happy Site Owners Using Astra

Whether you are a beginner, small business owner, or professional web developer, Astra provides all the tools you need to easily build your beautiful WordPress website.

REWIND

YEAR IN REVIEW

Download is Just A Click Away!

Membership Retention Checklist Download

Download is Just A Click Away!

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

Download Free Astra Theme - Modal Popup Form
Scroll to Top
Now choose your preferred
page builder addon
Choose your preferred page builder addon

Download is Just A Click Away!

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

Download Free Astra Theme - Modal Popup Form