post_row_actions
Allows you to remove/add links displayed below the post title in the admin Posts table (for example: Edit, Quick Edit, Trash, View).
The filter works only for non-hierarchical post types, such as posts. It does not work for pages. Hierarchical post types such as page have the similar page_row_actions filter.
Usage
add_filter( 'post_row_actions', 'wp_kama_post_row_actions_filter', 10, 2 );
/**
* Function for `post_row_actions` filter-hook.
*
* @param string[] $actions An array of row action links.
* @param WP_Post $post The post object.
*
* @return string[]
*/
function wp_kama_post_row_actions_filter( $actions, $post ){
// filter...
return $actions;
}
- $actions(array)
An array of links. By default these are 'Edit', 'Quick Edit', 'Trash', and 'View'.
By default, the
$actionsarray looks like this:Array ( [edit] => <a href="http://wp-test.ru/wp-admin/post.php?post=173&action=edit" aria-label="Edit «My Post»">Edit</a> [inline hide-if-no-js] => <a href="#" class="editinline" aria-label="Quick edit “My Post”">Quick Edit</a> [trash] => <a href="http://wp-test.ru/wp-admin/post.php?post=173&action=trash&_wpnonce=79bbce2a2f" class="submitdelete" aria-label="Move “My Post” to the Trash">Trash</a> [view] => <a href="http://wp-test.ru/%d0%bc%d0%be%d1%8f-%d0%b7%d0%b0%d0%bf%d0%b8%d1%81%d1%8c/" rel="bookmark" aria-label="View «My Post»">View</a> )
- $post(WP_Post)
- The current post object.
Examples
#1 Add a link to the post's comments page
add_filter( 'post_row_actions', 'post_actions_add_comments_link', 10, 2 );
function post_actions_add_comments_link( $actions, $post ) {
if ( $post->comment_count ) {
$url = esc_url( add_query_arg( array( 'p' => $post->ID, 'comment_status' => 'approved' ), admin_url( 'edit-comments.php' ) ) );
$actions['comments'] = sprintf( '<a href="%s">Comments</a>', $url );
}
return $actions;
}Changelog
| Since 2.8.0 | Introduced. |
Where the hook is called
wp-admin/includes/class-wp-posts-list-table.php 1705
$actions = apply_filters( 'post_row_actions', $actions, $post );