- What is Astra Pro Add on?
- What Is a Child Theme and How To Install It for Astra?
- How to Activate Astra Pro Addon License?
- How to Get License Key of Astra Pro?
- How to Install Astra Pro Plugin?
- Getting Started with Astra Pro Addon Plugin
- Getting error – The package could not be installed. The theme is missing the style.css stylesheet?
- Do Not See License Activation Form for Astra Pro Addon Plugin?
- How to Install Astra Theme?
- Astra – Customize the Submenu
- The Blank Screen in the Customizer Area
- How to use the color palette of the Astra theme
- How to Import / Export Astra Customizer Settings
- How To Disable Logo Cropping
- How to Create a Sticky Sidebar for Your WooCommerce Shop Page
- How to use dynamic customizer from Astra 4.0.0
- How to Change the Typography of the Astra Menu
- Simplify Your Site Design with the New Style Guide
- How to Translate Astra Theme / Plugins in Your Own Language using GlotPress?
- How to Turn Astra Multilingual with WPML?
- How To Translate Site Builder With WPML?
- How to Translate Astra Strings with WPML?
- How Translations can be Manually Exported and Uploaded to the Site?
- How to Turn Astra Website Multilingual with Polylang?
- How to Translate Categories, Tags, and Astra Strings with Polylang
- How to Turn Astra Website Multilingual with TranslatePress?
- How to translate the WooCommerce string?
- Footer Custom Text Helper Strings
- Does Astra support Beaver Themer Plugin?
- Increasing the PHP Memory Limit of Your Website
- How to Disable Header or Footer for a Landing Page or Post?
- Where Does Astra Primary Color Setting Take Effect?
- How to Adjust the Width of Your Sidebar?
- How to Update the Plugin Manually from WordPress Backend?
- Recommended Settings for Elementor and the Astra Theme
- Recommended Settings for Beaver Builder and the Astra Theme
- How Do License Upgrades Work?
- How to Renew Yearly License?
- How to Apply For Brainstorm Force Affiliate Program? (Become Astra Affiliate)
- How to Manage License on Store?
- How To Update Your Payment Method?
- How do I check my Support Ticket History?
- Frequently Asked Questions – VIP Priority Support
- How to Process Refund Requests?
- Fix Swap Sections Not Working on Mobile (Old Astra Header)
- How to Remove Google Fonts Suggestions in Astra Theme?
- Remove default stretched block layout spacing
- How to Change the Logo on Specific Pages?
- How to remove horizontal & vertical gallery layouts from a single product page?
- Introducing New Filter to Enable/Disable Rank-Math Theme Support
- Enable/Disable YouTube videos from Astra admin dashboard
- How to Fix the Line Height Unit being converted to “EM”?
- How to Change WordPress Post labels to Projects
- Fix for – The PCLZIP_ERR_BAD_FORMAT (-10) Error
- Fix for – Parse error: syntax error, unexpected T_FUNCTION
- How to fix Fatal Error / White Screen of Death?
- Fix for- cURL error 51: SSL: no alternative certificate subject name matches target host name ‘websitedemos.net’
- Getting error – The package could not be installed. The theme is missing the style.css stylesheet?
- ‘The preview could not be loaded’ Pop Up with Astra and Elementor
- Troubleshooting Steps ( with Health Check & Troubleshooting plugin )
- How to Deal with Update Issues in Astra Theme and Astra Pro Addon?
- Blog Featured Image Size Not Working / Error in Image Processing Library
How To Hide Astra Settings for Specific User Roles?
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.
We don't respond to the article feedback, we use it to improve our support content.