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

Viewing 15 posts - 16 through 30 (of 30 total)
  • Author
    Posts
  • #5987
    edering
    Participant

    The problem I am having is when “Administrator” is not showing in the dropdown menu for “Select Role and Change its Capabilities” as shown here: https://www.screencast.com/t/nPZ9xVBq To me that would make sense because shouldn’t the default Administrator role have access to everything, regardless of what what settings are applied in URE, such “Force custom post types to use their own capabilities”? And whether I enabled “Force custom post types to use their own capabilities” or not, the list still does not show “administrator”

    #5989
    Vladimir
    Keymaster

    Turn ON special option “Show Administrator role at User Role Editor” at “Settings->User Role Editor->General” tab in order to see “Administrator” role in the URE’s roles drop-down list.

    #5992
    edering
    Participant

    Now we are showing the Custom Post Types, but no actual posts appear for these users. Only full Administrators. When I create a role with less access than admin, and I am giving them all access to that CPT (all capabilities). They can Add a New one, but none of the already existing Posts are appearing. In the Core capabilities, they have important items like read and edit_others_posts. Any idea?

    #5993
    edering
    Participant

    As a followup, I have a Role setup called Scholarships. Here are screenshots of what the Role can do: https://www.screencast.com/t/Cb4NEOLk and https://www.screencast.com/t/lrlZz8uL6Xf and https://www.screencast.com/t/13cjfAilwgE8 and “Force Custom Post Types to use their own capabilities” is still enabled.

    #5995
    Vladimir
    Keymaster

    Re-check if this role and/or user with this role has active edit restrictions. May be deactivate ‘Edit restrictions’ add-on temporally for quick test.

    #5996
    edering
    Participant

    That was it! The User had a restriction to a Page (one Page ID). I need that user to have this Scholarship Role, and another Role, but only access to one Page to edit. Is that possible? I set the Role to what I called “SDoL Page Editor” (which access to Pages only) and I did this (Additional Role) and set the Post ID of the Page the user needs to be able to edit. https://www.screencast.com/t/mSjZ1j4RiL

    #6000
    Vladimir
    Keymaster

    It should work, with little tuning.
    Try to exclude ‘scholarship’ CPT from edit restrictions using ‘ure_restrict_edit_post_type‘ filter.

    #6001
    edering
    Participant

    Thanks. in this screen shot – https://www.screencast.com/t/DSN6tOb63Ty – do I put the “scholarships”(our CPT) where I have the green arrow and also “scholarships” where I have the red arrow (that is the name of Role that is supposed to have access to the Custom Post Type)? I tried this and it did not work. I also tried “editor” like you have it. I also tried using “sdol-page-editor” for the current-user-can value (because that is the role we use to restrict pages/posts) but it did not work.

    #6002
    Vladimir
    Keymaster

    Check what exact ID your custom post type CPT really has. Pay attention that while we talk ‘posts’, post type ID is ‘post’. So I suppose that your CPT is ‘scholarship’, not ‘scholarships’.
    With this assumption in mind try this version of a code:

    
    if (current_user_can('scholarships')) {  // Role ID
          if ($post_type=='scholarship') {  // CPT ID
            $restrict_it = false;
          }
      }
    
    #6004
    edering
    Participant

    Thanks! That worked.

    #6018
    edering
    Participant

    I have to create multiple instances of this function and I have (changing the function name to be unique). I did exactly the same thing as before where I create a Role called News which is for the News CPT. https://www.screencast.com/t/90vxmv9z My test user is set to a SDoL Page Editor and gives editing access to one Post ID and also access to the News Role. https://www.screencast.com/t/sBK5LYeF But when I login to test the User, it shows all the News (which is good) and let’s me add News (which is good), but in Pages, it is ignore the restriction to only Allow one Page (based on Post ID) as seen here https://www.screencast.com/t/zetJ7sf5s Any idea why this exact same method works when I use the Scholarship Role with SDoL Page Editor (and Allow one Post ID), but I simply change the User’s Other Roles from Scholarship to News (and set the new Post ID and Category ID), it shows ALL Pages with Edit capabilities?

    #6020
    Vladimir
    Keymaster

    Is it possible to look at your site with admin privileges?
    If Yes, send credentials to support [at-sign] role-editor.com

    #6022
    edering
    Participant

    Yes, I just sent you the info. Thanks

    #6027
    Vladimir
    Keymaster

    Thank you.
    There is a possible bug at URE Pro code which I should investigate and fix. At some conditions URE sends TRUE to ure_restrict_edit_post_type instead of real post_type value. PHP evaluates ($post_type==’news’) expression as TRUE and switches off edit restrictions for pages too. This is a reason why user sees all pages instead of 1 allowed and its child page.

    Quick fix is to use exact type comparison operand ‘===’, like this:

    if ($post_type===’news’) { // CPT ID

    #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.

Viewing 15 posts - 16 through 30 (of 30 total)
  • You must be logged in to reply to this topic.