Change WordPress user roles and capabilities Forums How to or FAQ using the ure_restrict_edit_post_type filter with custom taxonomy

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #4366

    I have a document post type with a department specific custom taxonomy associated with.
    How do I check whether the post has certain terms and change the $restrict_it value using the ure_restrict_edit_post_type hook?

    I want the finance role to only see posts that are under the finance resources category.
    I’m using this filter because i’m restricting to only see the Finance Resources page in the first place. My code below…

    add_filter('ure_restrict_edit_post_type',  __NAMESPACE__ . '\\exclude_posts_from_edit_restrictions');
    function exclude_posts_from_edit_restrictions($post_type) {
      $restrict_it = true;
      if (current_user_can('finance2')) {
          if ($post_type=='document' && has_term( 'finance-resources', 'department' ) )  {
              $restrict_it = false;
                // do something
      return $restrict_it;

    You can restrict access to the ‘document’ custom post type editing by input department taxonomy ID as a restrictions criteria for the role ‘finance’.

    A purpose of this filter is to exclude posts type from edit restrictions for all users or some role as edit restrictions are applied to all post types by default. It’s not planned to apply this filter to the selected post (item inside custom post type) by some criteria. Using this filter you can allow to edit all posts for the current user or just a subset of post according to the criteria for this user and his role(s).


    Hi Vladimir, I have multiple custom taxonomies under the same post type and rely heavily on them for other tasks. Therefore, the problem with this is that if I use one ID, then other terms in other custom taxonomies under the same post type won’t show up. Anyway to get around that?


    Thanks for the clarification. I will think about this.


    ‘ure_restrict_edit_post_type’ filter influences to the whole post type (restrict it or do not restrict), not on the current post only. So condition

    has_term( 'finance-resources', 'department' )

    is not applicable here.

    What if to use another blocking model, that is ‘Block’ instead of ‘Allow’. Then URE will hide blocked terms, but any other will still be available.
    For example you have categories: 1, 3, 8, 9, 15 and a lot of terms from other taxonomies. You wish to allow to edit just category 3 from the “Categories” taxonomy. Then select “Block” and input into categories ID list field: 1, 8, 9, 15. It should give you a need effect.

    I will add a custom filter for terms ID list into the next version. So it will be possible to set the list of prohibited posts by program not manually, which will provide a possibility of a more universal solution.

    Manage restrictions directly for the different taxonomies available for the same post type seems a complex task, due to data structure used by WordPress. I suppose also that this feature is not in a high-demand category.

    There is a ‘ure_edit_posts_access_id_list’ custom filter which allows to set posts ID list to allow or block for editing.
    So you can scan posts list for current user role and built a posts-list by your own checking any terms and taxonomies for the single post from a list of available posts.

    It’s possible to set a restriction type via custom filter too. For example:

    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) {
        $restriction_type = 2; // Block 
        return $restriction_type;
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.