Disable “quick edit” only for non admin in functions.php

I have this in my functions.php

function remove_quick_edit( $actions ) {
    unset($actions['inline hide-if-no-js']);
    return $actions;
}
add_filter('post_row_actions','remove_quick_edit',10,1);

to remove the quick edit link in the backend when scrolling the list of published posts.

It works like a charm but it disable it even for the admin role.
Is it possible to keep it showing only for the admin while still diabling for the rest?
Thanks!

SOLVED thanks to jfacemyer!
This is the full code to add in functions.php

function remove_quick_edit( $actions ) {
    unset($actions['inline hide-if-no-js']);
    return $actions;
}
if ( ! current_user_can('manage_options') ) {
    add_filter('post_row_actions','remove_quick_edit',10,1);
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Use current_user_can to wrap the add_filter call:

if ( current_user_can('manage_options') ) {
} else {
    add_filter('post_row_actions','remove_quick_edit',10,1);
}

manage_options is an Admin capability. If the current user can do it, he’s an admin (on a vanilla WP installation).

See:

http://codex.wordpress.org/Roles_and_Capabilities

and

http://codex.wordpress.org/Function_Reference/current_user_can

Method 2

Here is the code if you wish to remove the Quick Edit option from Pages as well:

function remove_quick_edit( $actions ) {
    unset($actions['inline hide-if-no-js']);
    return $actions;
}
if ( !current_user_can('manage_options') ) {
    add_filter('page_row_actions','remove_quick_edit',10,1);
    add_filter('post_row_actions','remove_quick_edit',10,1);
}

Method 3

At least in WP 4.3.1 it is possible to use role name in current_user_can(). So the code may now look like this:

function remove_quick_edit( $actions ) {
  unset($actions['inline hide-if-no-js']);
  return $actions;
}
if ( !current_user_can('administrator') ) {
  add_filter('post_row_actions','remove_quick_edit',10,1);
}

Cleaner and more intuitive.

Method 4

Include this in your function.php

add_action('admin_head', 'wc_my_custom_css');
function wc_my_custom_css() {
     echo '<style>
               .hide-if-no-js {
                  display:none !important;
               }
          </style>';
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x