10

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);
}
  • I believe the User Role Editor plugin will let you do this. Feel free to punch me in the head if I'm wrong. – Jared Steffen Mar 19 '13 at 18:24
  • The user role plugin has made my site instable so I needed to disable it and I've added all the small pieces of code I needed in my functions.php making them available in case I want to replicate this project in the future. Unfortunately I'm missing the quick edit removal only for non admins... – user27309 Mar 20 '13 at 11:13
  • Please be careful: the solution you outlined doesn't remove "edit" from bulk actions select. In order to do it, you have to add this snippet of code add_filter( 'bulk_actions-edit-post', 'remove_from_bulk_actions' ); function remove_from_bulk_actions( $actions ){ unset( $actions[ 'edit' ] ); return $actions; } – Marco Panichi Jul 5 '17 at 4:50
9

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

6

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);
}
0

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.

0

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>';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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