Skip to content

Instantly share code, notes, and snippets.

@barbietunnie
Forked from danielpataki/new-role.php
Last active September 13, 2015 17:35
Show Gist options
  • Save barbietunnie/19d75239001dadf347d2 to your computer and use it in GitHub Desktop.
Save barbietunnie/19d75239001dadf347d2 to your computer and use it in GitHub Desktop.
Hide Pages
register_activation_hook( __FILE__, 'my_initial_setup' );
function my_initial_setup() {
$admin = get_role( 'administrator' );
$overlord_caps = $admin->capabilities;
$overlord_caps[] = 'be_overlord';
$role = add_role( 'overlord', 'Overlord', $overlord_caps );
}
add_action( 'init', 'ny_page_category' );
function ny_page_category() {
$show_ui = ( current_user_can( 'be_overlord' ) ) ? true : false;
$labels = array(
'name' => 'Page Categories',
'singular_name' => 'Page Category',
'search_items' => 'Search Page Categories',
'all_items' => 'All Page Categories',
'parent_item' => 'Parent Page Category',
'parent_item_colon' => 'Parent Page Category:',
'edit_item' => 'Edit Page Category',
'update_item' => 'Update Page Category',
'add_new_item' => 'Add New Page Category',
'new_item_name' => 'New Page Category Name',
'menu_name' => 'Page Categories',
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => $show_ui,
'query_var' => true,
'rewrite' => array( 'slug' => 'page_category' ),
);
register_taxonomy( 'page_category', array( 'page' ), $args );
}
add_action( 'pre_get_posts', 'my_hide_system_pages' );
function my_hide_system_pages( $query ) {
if( is_admin() && !empty( $_GET['post_type'] ) && $_GET['post_type'] == 'page' && $query->query['post_type'] == 'page' && !current_user_can( 'be_overlord' ) ) {
$query->set( 'tax_query', array(array(
'taxonomy' => 'page_category',
'field' => 'slug',
'terms' => array( 'system-page' ),
'operator' => 'NOT IN'
)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment