Last active
December 17, 2015 01:09
-
-
Save dominic-p/5526528 to your computer and use it in GitHub Desktop.
Filter to hide protected pages in the admin list table from users who aren't qualified to edit them.
This file contains hidden or 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
/* | |
List some protected pages and then prevent unqualified | |
users from seeing them. | |
*/ | |
function admin_hide_protect_pages( $q ) { | |
global $pagenow, $wpdb; | |
// Bail out if we have the proper permissions or we aren't on the right page | |
if ( !is_admin() | |
|| 'edit.php' != $pagenow | |
|| 'page' != get_query_var( 'post_type' ) | |
|| current_user_can( 'manage_options' ) ) return $q; | |
// List of reserved page | |
$hidden_pages = array( | |
'cart', | |
'checkout', | |
'pay', | |
'order-received', | |
'my-account', | |
'change-password', | |
'edit-address', | |
'view-order', | |
'order-tracking' | |
); | |
// Get the IDs of all the reserved pages | |
$hidden_page_ids = $wpdb->get_col( | |
" | |
SELECT ID | |
FROM {$wpdb->posts} | |
WHERE post_name IN( '" . implode( "','", $hidden_pages ) . "' ); | |
" | |
); | |
if ( !$hidden_page_ids ) return $q; | |
$q->set( 'post__not_in', $hidden_page_ids ); | |
} | |
add_filter( 'pre_get_posts', 'admin_hide_protect_pages' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment