0

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 1

1

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');
3
  • I would use admin_init action hook to check current_user_can() (or user roles if needed) and add the post_row_actions filter to remove the quick edit.
    – cybmeta
    Commented 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
  • 1
    Quick 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 that current_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
    – cybmeta
    Commented Sep 22, 2015 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.