Change WordPress user roles and capabilities › Forums › Restrict or Permit access inside WordPress – how to › Restrict editing pages by user role? › Reply To: Restrict editing pages by user role?
11/09/2014 at 02:17
#958
Vladimir
Keymaster
Sorry, that was my fault. I did not pay attention on the word ‘specific’ at your 1st message.
Current version does not include the interface to restrict editing posts/pages by role. It is good feature request and I will add this functionality to Pro version with time.
Now you may use this piece of code to prohibit your users with ‘editor’ role access to the list of pages:
if (is_blog_admin() && current_user_can('editor')) {
add_action('pre_get_posts', 'restrict_posts_list');
function restrict_posts_list($query) {
$suppressing_filters = $query->get('suppress_filters'); // Filter suppression on?
if ($suppressing_filters) {
return query;
}
if ($query->query['post_type']=='page') {
$posts_restriction_type = 2; // Prohibit
$posts_list = array(442, 484); // comma separated list of pages IDs
if ($posts_restriction_type==1) { // Allow
$query->set('post__in', $posts_list);
} else { // Prohibit
$query->set('post__not_in', $posts_list);
}
}
return $query;
}
// restrict_posts_list()
}
Replace pages ID at $posts_list array and add this code to your active theme functions.php file.