Remove WordPress Quick Edit feature for certain post types and related action links
The Quick Edit feature is a small feature in the WordPress post list that allows us to quickly edit some of the post's attributes, such as title, alias, category, tags, etc. This is a very useful feature for CMS systems.Custom Article TypesThis feature is also inherited, for some article types, this feature is useless, and even bring some troubles for users. For example, we have created a new article type named “Message” to receive the inquiry information submitted by the user in the frontend, we want the customer service can only view, not edit the information, so we must remove the quick edit function. This requirement can be realized with the following code.
Remove quick edit for a certain post type
add_filter('post_row_actions', function ($actions = [], $post = null)
{
// If it's not the type of post we need, return it directly
if (!in_array(get_post_type($post), ['message'])) {
return $actions.
}
// Determine post type and remove quick edit links
if (isset($actions[ 'inline hide-if-no-js' ])) {
unset($actions[ 'inline hide-if-no-js' ]); }
}
// Return the array of links after removing the Quick Edit operation.
return $actions.
}, 10, 2).;WordPress Default Post List Operation Function
As we can see from the code above, this functionality is actually modified by the Filter post_row_actions $actions This array is realized then $actions What elements are in this array and what operations can we disable? By looking at the WordPress source code, we found the following several, according to the need to use the following data in the element to replace the name of the corresponding operation in the above code, you can disable the use of the function.
[
'view',
'inline hide-if-no-js',
'delete', 'trash', 'inline
'untrash', 'inline
]In addition to these, some plugins add custom actions to the post list, we can search for the post_row_actions Check out the custom action features added by the plugin and handle them as needed.