title: Restrict author to post in category and create subcategory
body: <p>I want to restrict my authors to publish in a specific parent category (Restricted and created by me) and allow them to create and publish in a <strong>subcategory</strong> (Created by each author) of the parent category.</p>
  
  <p>So basically, 
  Author 1 restricted to publish in CATEGORY A. He will create and publish in Category A -> Subcategory1 etc.<br>
  Author 2 restricted to publish in CATEGORY B. He will create and publish in Category B -> Subcategory1 etc.  </p>
  
  <p>I found a code working well but doesn't do exactly what I want. Actually, the plugin restrict the author to publish only in the category he created. This is what I want but for the subcategories and what to assign a specific parent category to a specific author.</p>
  
  <pre><code>class SW_Category_Restriction{
      private $user_cats = NULL;
  
      public function __construct(){
          //Save author ID for category
          add_action( 'create_category', array( &amp;$this, 'save_category_author' ) );
          //Set manage_categories cap for 'Author'
          add_action( 'admin_init', array( &amp;$this, 'add_author_cap_categories' ) );
          //Remove manage_categories  capfor 'Author'
          register_deactivation_hook( __FILE__, array( &amp;$this, 'remove_author_cap_categories' ) );
          //Filter categorys in new-post, edit-post, edit-categories
          add_action( 'admin_print_scripts-post-new.php', array( &amp;$this, 'filter_post_page' ) );
          add_action( 'admin_print_scripts-post.php', array( &amp;$this, 'filter_post_page' ) );
          add_action( 'admin_print_scripts-edit-tags.php', array( &amp;$this, 'filter_post_page' ) );
          //just show own posts
          global $pagenow;
          if ( $pagenow == 'edit.php' )
              add_filter( 'pre_get_posts', array( &amp;$this, 'filter_edit_page' ) );
      }
  
      public function save_category_author( $term_id ) {
          $user_id = get_current_user_id();
          add_term_meta( $term_id, 'author', $user_id );
      }
  
      public function get_user_cats( $user_id ) {
          $args = [
              'hide_empty' =&gt; false,
              'meta_query' =&gt; [
                  [
                      'key' =&gt; 'author',
                      'value' =&gt; $user_id,
                  ]
              ]
          ];
          $terms = get_terms( 'category', $args );
          $ids = '-1,';
          foreach ($terms as $term ) {
              $ids .= $term-&gt;term_id . ',';
          }
          $ids = substr($ids, 0, -1);
          $this-&gt;user_cats = $ids;
      }
  
      public function add_author_cap_categories() {
          $role = get_role( 'author' );
          $role-&gt;add_cap( 'manage_categories' );
      }
  
      public function remove_author_cap_categories() {
          $role = get_role( 'author' );
          $role-&gt;remove_cap( 'manage_categories' );
      }
  
      public function exclusions( $exclusions ){
          $exclusions .= " AND ( t.term_id IN ( $this-&gt;user_cats ) OR tt.taxonomy NOT IN ( 'category' ) )";
          return $exclusions;
      }
  
      public function filter_post_page() {
          //check post-type 
          $screen = get_current_screen();
          if ( $screen-&gt;post_type != 'post' )
              return;
  
          //just Author and lower
          if ( current_user_can('delete_others_posts') )
              return;
  
          $user_id = get_current_user_id();
          $this-&gt;get_user_cats( $user_id );
  
          if ( empty( $this-&gt;user_cats ) )
              return;
  
          add_filter( 'list_terms_exclusions', array( &amp;$this, 'exclusions' ) );
      }
  
      public function filter_edit_page( $query ) {
          if ( current_user_can('delete_others_posts') )
              return;     
          $query-&gt;set( 'author', get_current_user_id() );
  
          return $query;
      }
  
  }
  
  new SW_Category_Restriction();
  </code></pre>