0

I seem to be missing something fundamental somehow ('ll try and keep it short but can provide more code if needs be of course )

I have registered a CPT with following arguments

'capability_type' => array(CPT_SLUG, CPT_SLUG.'s'),
'map_meta_cap' => true,
 'capabilities' => array(
 'edit_post' => 'edit_'.CPT_SLUG.'',
 'edit_posts' => 'edit_'.CPT_SLUG.'s',
 'edit_others_posts' => 'edit_others_'.CPT_SLUG.'s',
 'publish_posts' => 'publish_'.CPT_SLUG.'s',
 'read_post' => 'read_'.CPT_SLUG.'',
 'read_private_posts' => 'read_private_'.CPT_SLUG.'s',
 'delete_post' => 'delete_'.CPT_SLUG.'',
 'delete_posts' => 'delete_'.CPT_SLUG.'s'
 )  

so far so good. to bring things in line somewhat with the way user roles work in normal wp posts I am removing the capability for "author" roles by doing

 $authorRole->remove_cap( 'edit_others_'.CPT_SLUG.'s' );

so authors cannot edit the post of other roles. though this works, I am still left with the quick edit link in the list of CPT posts even for posts created by another role.

although I cannot save anything using the quick edit for posts created by other roles (which is the idea of course), I don't think that quick edit link should be there, to begin with (for example "normal" WP posts don't show this either in above scenario)

am I missing a filter/action perhaps I need to add too? or is there another capability that needs removing for the "author"?

had a look around for quite some time now but cannot find any answer really other than what seems workarounds...

hints much appreciated

2

You can try post_row_actions hook:

/**
 * Hide quick edit
 *
 * @internal  Used as a callback.
 *
 * @see  https://developer.wordpress.org/reference/hooks/post_row_actions/
 */
function wpse288663_hide_quick_edit($actions, $post)
{
    // Replace `{$cap}` with your specific capability.
    if (CPT_SLUG === $post->post_type && current_user_can({$cap})) {
        unset($actions['inline hide-if-no-js']);
    }

    return $actions;
}

// Hook up.
add_filter('post_row_actions', 'wpse288663_hide_quick_edit', 10, 2);
  • hmm, that only works in so far as that it removes all links (quickedit as well as view and probably all others ) for all posts (i.e also for the posts that belong to the author role) maybe i need to clarify: I only want the quickedit links to disappear for posts that where NOT created by the "author" role. the posts that belong to the "author" role should be "quickeditable" – Olly Dec 15 '17 at 2:28
  • actually - sorry about that - i think i might have made an error here (way too late - again ) i'll mess around for a bit after some sleep. I think my comment above is not strictly accurate thanks for taking the time to reply . – Olly Dec 15 '17 at 2:46
  • I corrected the hook by changing add_action ==> add_filter. Hope it work for you! – MinhTri Dec 15 '17 at 4:28
  • 1
    It turns out that my problem was that I actually already used the post_row_actions hook to add a customised quick edit link previously without accounting for the user role, so instead of trying to remove something I should not have added it in the first place like I did . Doh ! a simple conditional in my original function hooked like so $can_edit_post = current_user_can( 'edit_post', $post->ID ); if ( !$can_edit_post || 'trash' == $post->post_status ) {return $actions;} solved my problem. I'll accept the answer provided (and it also brought me onto the trail of the issue) – Olly Dec 19 '17 at 18:19

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.