2

I want to limit the access rights of a user in the Wordpress backend in a way that this user only has (read, write) access to the posts from one category. The user should not even be able to read posts from another category in the backend.

How can I achieve this (ideally by adding some code to the functions.php) - and without any performance impacts (e.g. page load)?

I basically try to achieve what this plugin did, before it got outdated: https://wordpress.org/plugins/restrict-categories/

"Restrict Categories is a plugin that allows you to select which categories users can view, add, and edit in the Posts edit screen. This plugin allows you to restrict access based on the user role AND username."

Alex
  • 621
  • 1
  • 8
  • 26

2 Answers2

1

If you don't mind using a plugin that's up to date then this one will do everything you've asked for and has been regularly updated and has over 40,000 active installs.

User Access Manager

https://wordpress.org/plugins/user-access-manager/

  • Thanks, Jamie. Already found this one - however, this adds much more complexity as needed and overlaps with other plugins I already use. Hence a simple code snippet for my functions.php would be ideal. – Alex May 10 '16 at 10:14
  • Hi Alex, take a look at this guide http://3.7designs.co/blog/2014/08/restricting-access-to-custom-post-types-using-roles-in-wordpress/ it's a basic guide on creating a custom user type and restricting access to a specific post type and can all be done from your functions.php file. – Jamie Livingstone May 10 '16 at 10:34
0

Update in 2020, Working answer, I went to different answers none of them works now in new WordPress.

function hide_categories_for_specific_user( $exclusions, $args ){

if ( ((defined( 'REST_REQUEST' ) && REST_REQUEST) or $GLOBALS['pagenow'] === 'edit.php' ) && !current_user_can( 'manage_options' ) ) {

   // IDs of terms to be excluded
   $exclude_array = array("12","16","17"); // CHANGE THIS TO IDs OF YOUR TERMS


   // Generation of exclusion SQL code
   $exterms = wp_parse_id_list( $exclude_array );
   foreach ( $exterms as $exterm ) {
           if ( empty($exclusions) )
               $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' ';
       else
               $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' ';
   }

   // Closing bracket
   if ( !empty($exclusions) )
   $exclusions .= ')';

   // Return our SQL statement

  }
   return $exclusions;
}

 // Finally hook up our filter
 add_filter( 'list_terms_exclusions', 'hide_categories_for_specific_user', 10, 2 );

answer final help from Hide Some Categories in Post Editor