Restrict page editor access for a single page
-
I’m using a multisite installation and only want Super Admins to be able to edit or delete certain pages. This would be one or two pages in each site. I want the administrators for each site to still have Administrator-level access. Making them all Authors and restricting their access to their own pages would not be an option, since there are multiple administrators per site.
So that’s the problem: how do I restrict Administrators (or Editors) from editing specific pages on their sites?
I found a possible solution here. It didn’t quite work for me, but I used it as a basis for my own solution: use a custom field to mark a page as “Protected” and restrict administrator access to those pages to Super Admins only by using
!current_user_can('manage_network')
.Here is the code:
function superadmin_restrict_pages() { global $post; $protected_value_status = get_post_meta( $post->ID, 'protected_value', true ); if (!current_user_can('manage_network') && $protected_value_status == 'Protected' ) { wp_die( sprintf( __( 'You do not have permission to access this area.' ) ) . sprintf( '<br /><a href="javascript:history.go(-1);">Go back</a>' )); } } add_action('load-post.php' , 'superadmin_restrict_pages'); add_action('edit_post','superadmin_restrict_pages'); add_action('wp_trash_post', 'superadmin_restrict_pages'); add_action('before_delete_post', 'superadmin_restrict_pages');
This is in my theme’s functions.php file. I also tried removing it from functions.php and instead putting it within a custom plugin I created. That didn’t work either. The function is simply having no effect. Administrators can still access and edit the restricted pages with no problem.
Is there something wrong with this function? Is there a better way to go about this?
- The topic ‘Restrict page editor access for a single page’ is closed to new replies.