Projects Engine - Word

post_row_actions

The post_row_actions filter hook in WordPress allows you to modify the row action links displayed for each post in the admin panel's post listing screen.

Home / Dictionary / post_row_actions

The post_row_actions filter hook in WordPress allows you to modify the row action links displayed for each post in the admin panel’s post listing screen. These action links typically include options like “Edit,” “Quick Edit,” “Trash,” etc.

Description: This filter hook enables developers to customize the action links displayed for each post row in the WordPress admin panel. By hooking into post_row_actions, you can add, remove, or modify the action links to tailor them to your specific needs.

Parameters:

  1. $actions (array): An associative array containing the action links for the post row. Each key-value pair represents a single action link, where the key is the action name and the value is the HTML markup for the link.
  2. $post (WP_Post object): The WP_Post object representing the current post row being displayed in the admin panel.

Return: The function hooked to post_row_actions must return an array containing the modified action links. This array should include any changes you want to apply to the action links for the current post row. Ensure that the modifications made are consistent with the format expected for the action links.

Here’s an example illustrating how you can use this filter hook:

if( !function_exists('zing_modify_post_row_actions')) {
	/**
	 * Filters the array of row action links on the Posts list table.
	 *
	 * @param string[] $actions
	 * @param WP_Post $post
	 * @return array
	 */
	function zing_modify_post_row_actions( $actions, $post ) {

		if( 'word' === $post->post_type ) {
			// Add a custom action link at the beginning of the array
			$actions['ID'] = 'ID: ' . $post->ID;
		}

		return $actions;
	}

	add_filter( 'post_row_actions', 'zing_modify_post_row_actions', 10, 2 );
}

If the condition is true (i.e., the post type is ‘word’), it adds a custom action link to the $actions array. This custom action link has a key of ‘ID’ and a value of ‘ID: ‘ followed by the post ID.