Change WordPress user roles and capabilities Forums How to or FAQ Edit Page – but a specific page only Reply To: Edit Page – but a specific page only

#6028
Vladimir
Keymaster

I found a reason of the problem, when edit restriction was not applied to the ‘page’ post type. It’s my own code I recommended to you to insert into functions.php. As you used it 2 time as filter. 2nd time it was executed with not ‘page’ post type as an input parameter, but with value replace by TRUE after the 1st execution. Replace your code in functions.php with this updated version:


// URE to allow Scholarship Role access to Scholarship plugin while restricting Pages for user
add_filter('ure_restrict_edit_post_type', 'exclude_posts_from_edit_restrictions', 10, 1);
function exclude_posts_from_edit_restrictions($post_type) {
  $restrict_it =  $post_type;
  $user = wp_get_current_user();
  if ( empty( $user) || !is_array( $user->roles ) ) {
      return $restrict_it;
  }
  if ( in_array( 'scholarships', $user->roles ) ) {  // Role ID
      if ($post_type=='scholarship') {  // CPT ID
        $restrict_it = false;
      }
  }
  return $restrict_it;
}
// end URE to allow Scholarship Role access
 
// URE to allow News Role access to News plugin while restricting Pages for user
add_filter('ure_restrict_edit_post_type', 'exclude_posts_from_edit_news_restrictions', 10, 1);
function exclude_posts_from_edit_news_restrictions($post_type) {
  $restrict_it = $post_type;
  $user = wp_get_current_user();
  if ( empty( $user) || !is_array( $user->roles ) ) {
      return $restrict_it;
  }
  if ( in_array( 'news', $user->roles ) ) {  // Role ID
      if ($post_type==='news') {  // CPT ID
        $restrict_it = false;
      }
  }
  
  return $restrict_it;
}

1) It does not changes post type argument for the next calls of this filter;
2) It does not user heavy weight current_user_can() function, which is not recommended to use when you need check role, not capability.