-
-
Save barbietunnie/19d75239001dadf347d2 to your computer and use it in GitHub Desktop.
Hide Pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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