Skip to content

Instantly share code, notes, and snippets.

@jb510
Created June 1, 2018 12:05
Show Gist options
  • Select an option

  • Save jb510/acf5260a3d44ebdfda8e511e77b39ade to your computer and use it in GitHub Desktop.

Select an option

Save jb510/acf5260a3d44ebdfda8e511e77b39ade to your computer and use it in GitHub Desktop.
Hide metaboxes by user role
<?php
//* Hide Extra Metaboxes from certian user roles
add_action( 'init', ‘s9_remove_layouts_templates_init', 99 );
function s9_remove_layouts_templates_init() {
if ( ! is_admin() ) {
return;
}
$allowed_roles = array( 'administrator', 'super-editor', 'editor', 'author' );
$user = wp_get_current_user();
if( ! array_intersect($allowed_roles, $user->roles ) ) {
// Genesis Layouts, SEO
remove_action( 'admin_menu', 'genesis_add_inpost_seo_box' );
remove_theme_support( 'genesis-inpost-layouts' );
// Profile Builder Content Restriction
remove_action( 'add_meta_boxes', 'wppb_content_restriction_add_meta_box' );
// SearchwP
remove_meta_box( 'searchwp-related', 'post', 'normal' );
remove_meta_box( 'searchwp-related', 'article', 'normal' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment