Change WordPress user roles and capabilities › Forums › How to or FAQ › Edit Page – but a specific page only
- This topic has 29 replies, 2 voices, and was last updated 5 years, 1 month ago by Vladimir.
-
AuthorPosts
-
09/10/2019 at 12:04 #5987ederingParticipant
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”
10/10/2019 at 02:36 #5989VladimirKeymasterTurn 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.
10/10/2019 at 12:33 #5992ederingParticipantNow 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?
10/10/2019 at 12:45 #5993ederingParticipantAs 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.
10/10/2019 at 13:14 #5995VladimirKeymasterRe-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.
10/10/2019 at 13:20 #5996ederingParticipantThat 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
10/10/2019 at 16:50 #6000VladimirKeymasterIt should work, with little tuning.
Try to exclude ‘scholarship’ CPT from edit restrictions using ‘ure_restrict_edit_post_type‘ filter.10/10/2019 at 17:18 #6001ederingParticipantThanks. 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.
11/10/2019 at 03:04 #6002VladimirKeymasterCheck 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; } }
11/10/2019 at 13:21 #6004ederingParticipantThanks! That worked.
14/10/2019 at 15:26 #6018ederingParticipantI 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?
15/10/2019 at 15:33 #6020VladimirKeymasterIs it possible to look at your site with admin privileges?
If Yes, send credentials to support [at-sign] role-editor.com15/10/2019 at 15:38 #6022ederingParticipantYes, I just sent you the info. Thanks
16/10/2019 at 03:26 #6027VladimirKeymasterThank you.
There is a possible bug at URE Pro code which I should investigate and fix. At some conditions URE sends TRUE toure_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
‘16/10/2019 at 03:57 #6028VladimirKeymasterI 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. -
AuthorPosts
- You must be logged in to reply to this topic.