Skip to content

Instantly share code, notes, and snippets.

@deckerweb
Last active June 10, 2021 06:07
Show Gist options
  • Save deckerweb/0086ebfc130633625ecbfb3093ac1a0c to your computer and use it in GitHub Desktop.
Save deckerweb/0086ebfc130633625ecbfb3093ac1a0c to your computer and use it in GitHub Desktop.
Remove Meta Boxes on Post & Page Edit Screens from "Astra" Theme and "Astra Pro" Plugin for users who are not Administrators, so Editors and below. Inspired by user question: https://www.facebook.com/groups/wpastra/permalink/367143130421624/ -- below Code Snippet should go into "Code Snippets" plugin at best (please avoid functions.php)!
<?php
/** Do NOT include the opening php tag */
add_action( 'do_meta_boxes', 'ddw_remove_astra_metaboxes_for_non_admins' );
/**
* Remove Astra settings meta box for users that are not administrators
* Inspired by: https://www.facebook.com/groups/wpastra/permalink/367143130421624/?comment_id=367167440419193&comment_tracking=%7B%22tn%22%3A%22R1%22%7D
*
* @author David Decker - DECKERWEB
* @link https://gist.github.com/deckerweb/0086ebfc130633625ecbfb3093ac1a0c
*/
function ddw_remove_astra_metaboxes_for_non_admins() {
/**
* If current user has capability 'edit_theme_options' (Administrators do!) then stop running code
*/
if ( current_user_can( 'edit_theme_options' ) ) {
return;
}
/** Remove meta boxes, if no 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
} // end function
@emfluenceindia
Copy link

Very useful :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment