Change WordPress user roles and capabilities › Forums › How to or FAQ › quick edit and permalink disable for role
Tagged: fatal error
- This topic has 10 replies, 3 voices, and was last updated 6 years, 7 months ago by Vladimir.
-
AuthorPosts
-
13/12/2016 at 17:31 #3076digitaliwayParticipant
I have a role for people to edit pages, but I do not want them to edit the slug/permalink or do a quick edit. how can I prevent this?
14/12/2016 at 02:24 #3079VladimirKeymasterAnswers on your questions are available here:
Restrict access by role to Quick Edit functionality on post listing screens?
28/12/2016 at 21:40 #3122digitaliwayParticipantThis did not work. can you please provide specific code or update plugin to have capability?
I have a role called: page-editor
I added this exact code to the functions file and QUICKEDIT and PERMALINK EDIT still remain.
if (current_user_can(‘page-editor’)) {
add_filter(‘post_row_actions’,’remove_quick_edit’,10,1);
}
function remove_quick_edit( $actions ) {unset($actions[‘inline hide-if-no-js’]);
return $actions;
}29/12/2016 at 01:45 #3123VladimirKeymasterThis code is still actual to remove ‘Quick Edit’ link under a post line at the posts list. I re-tested it with theme 2017 functions.php, I just used the ‘editor’ role instead yours:
if (current_user_can('editor')) { add_filter('post_row_actions','remove_quick_edit',10,1); } function remove_quick_edit( $actions ) { unset($actions['inline hide-if-no-js']); return $actions; }
Check if you inserted code to the active theme’s functions.php, if your test user really has ‘page-editor’ role.
I’m ready to look at your site on-line if you send URL and admin login credentials to support [at-sign] role-editor.com
29/12/2016 at 12:14 #3132digitaliwayParticipantI was able to get this working with the below code. The code you posted does not contain “page_row_actions” and the code on https://www.role-editor.com/block-permalink-edit-button/ does not seem to work so I changed it to the filter “get_sample_permalink_html” below which seems more efficient unless you see a better solution?
//remove quick edit functions for page and post function remove_quick_edit( $actions ) { unset($actions['inline hide-if-no-js']); return $actions; } if ( current_user_can('page-editor') ) { add_filter('page_row_actions','remove_quick_edit',10,1); add_filter('post_row_actions','remove_quick_edit',10,1); } //hide permalink edit buton on page for role function hide_permalink() { return ''; } if ( current_user_can('page-editor') ) { add_filter( 'get_sample_permalink_html', 'hide_permalink' ); }
29/12/2016 at 12:43 #3133VladimirKeymasterYes, I did not tested with pages somehow :), just with posts. Thank You for the update.
16/05/2018 at 13:59 #4859jbgayetParticipantHi, when applying this in a mu-plugins I got a nice Fata error :
`Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in /wp-includes/capabilities.php:590
any idea on how to fix ?
Thank’s
JB16/05/2018 at 14:07 #4860VladimirKeymasterHi,
You should not call current_user_can() directly from mu-plugin code. You have to enclose it into some function hooked to the action when WordPress will load it’s core code already, like this:
add_action('admin_init', 'load_mu_plugin'); function load_mu_plugin() { if ( current_user_can('page-editor') ) { add_filter('page_row_actions','remove_quick_edit',10,1); add_filter('post_row_actions','remove_quick_edit',10,1); } }
16/05/2018 at 14:09 #4861VladimirKeymasterIt’s better to use current_user_can() for checking if capability was granted to a user or it was not. To check if user has role it’s more correct to use this code:
$user = wp_get_current_user(); if (in_array('some_role_id', $user->roles)) { // do something }
16/05/2018 at 14:23 #4862jbgayetParticipantwell great, and what about hiding the Move to trash for the Publish Metabox on the edit post page ?
16/05/2018 at 14:27 #4863VladimirKeymasterRevoke ‘delete_posts’, ‘delete_publish_posts’ capabilities from this role.
-
AuthorPosts
- You must be logged in to reply to this topic.