disable quickedit for specific custom post type user role
-
07-03-2021 - |
Вопрос
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
Решение
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);