I have a multi author blog. I want to use the 'Quick edit' option only for Admin and Editor on Dashboard not for Author or other Users. Thank You.
1 Answer
Use a conditional depending on capability. Admin's and Editors can both moderate comments so we can use the moderate_comments
capability. If a user cannot moderate comments, then remove the quick edit link.
Then we can filter post_row_actions
to remove the quick edit link.
function remove_quick_edit(){
function unset_quick_edit( $actions ) {
unset( $actions['inline hide-if-no-js'] );
return $actions;
}
if ( ! current_user_can( 'moderate_comments' ) ) {
add_filter( 'post_row_actions', 'unset_quick_edit', 10, 1 );
}
}
add_action('admin_init', 'remove_quick_edit');
-
I would use
admin_init
action hook to checkcurrent_user_can()
(or user roles if needed) and add thepost_row_actions
filter to remove the quick edit.– cybmetaCommented Sep 22, 2015 at 17:04 -
That makes sense. What is the benefit of using
admin_init
here? Would it forgo extra an extra query on the front end? Would you like to add an answer or should I edit mine? Commented Sep 22, 2015 at 17:28 -
1Quick edit doesn't exist on frontend, so an admin action hook is a good event to include this code. Not sure what you mean when talking about the query in the frontend. The benefit of using
admin_init
(or other proper action hook) is that we can be sure thatcurrent_user_can()
function has been defined and we won't get "undefined function" errors, for example like this one or this one. Edit your answer if you like– cybmetaCommented Sep 22, 2015 at 18:20