Change WordPress user roles and capabilities › Forums › Restrict or Permit access inside WordPress – how to › Protecting specific page from being edited › Reply To: Protecting specific page from being edited
15/10/2017 at 03:46
#4285
Vladimir
Keymaster
Look how it works at my test site – demo video.
Slightly enhanced code version. Update your copy:
add_filter('ure_edit_posts_access_id_list', 'ure_edit_posts_access_set_id_list');
function ure_edit_posts_access_set_id_list($list) {
if (!current_user_can('edit_others_pages')) {
return $list;
}
$slugs = array('shop', 'busket'); // input blocked pages slug here
$id_list = array();
foreach($slugs as $slug) {
$page = get_page_by_path($slug);
if (!empty($page)) {
$id_list[] = $page->ID;
}
}
if (count($id_list)>0) {
$id_list_str = implode(',', $id_list);
$list .= $id_list_str;
}
return $list;
}
add_filter('ure_edit_posts_access_restriction_type', 'ure_edit_posts_access_set_restriction_type');
function ure_edit_posts_access_set_restriction_type($restriction_type) {
if (current_user_can('edit_others_pages')) {
$restriction_type = 2; // Block
}
return $restriction_type;
}