apply_filters( 'post_row_actions', array $actions, WP_Post $post )

Filters the array of row action links on the Posts list table.


Description Description

The filter is evaluated only for non-hierarchical post types.


Parameters Parameters

$actions

(array) An array of row action links. Defaults are 'Edit', 'Quick Edit', 'Restore', 'Trash', 'Delete Permanently', 'Preview', and 'View'.

$post

(WP_Post) The post object.


Top ↑

Source Source

File: wp-admin/includes/class-wp-posts-list-table.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
2.8.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by Aurovrata Venet

    Here is an example of how to modify the quick links in your custom post type admin table list,

    add_filter( 'post_row_actions', 'modify_list_row_actions', 10, 2 );
    
    function modify_list_row_actions( $actions, $post ) {
    	// Check for your post type.
    	if ( $post->post_type == "my_custom_post_type" ) {
    
    		// Build your links URL.
    		$url = admin_url( 'admin.php?page=mycpt_page&post=' . $post->ID );
    
    		// Maybe put in some extra arguments based on the post status.
    		$edit_link = add_query_arg( array( 'action' => 'edit' ), $url );
    
    		// The default $actions passed has the Edit, Quick-edit and Trash links.
    		$trash = $actions['trash'];
    
    		/*
    		 * You can reset the default $actions with your own array, or simply merge them
    		 * here I want to rewrite my Edit link, remove the Quick-link, and introduce a
    		 * new link 'Copy'
    		 */
    		$actions = array(
    			'edit' => sprintf( '<a href="%1$s">%2$s</a>',
    			esc_url( $edit_link ),
    			esc_html( __( 'Edit', 'contact-form-7' ) ) )
    		);
    
    		// You can check if the current user has some custom rights.
    		if ( current_user_can( 'edit_my_cpt', $post->ID ) ) {
    
    		  // Include a nonce in this link
    		  $copy_link = wp_nonce_url( add_query_arg( array( 'action' => 'copy' ), $url ), 'edit_my_cpt_nonce' );
    
    		  // Add the new Copy quick link.
    		  $actions = array_merge( $actions, array(
    		  	'copy' => sprintf( '<a href="%1$s">%2$s</a>',
    				esc_url( $copy_link ), 
    				'Duplicate'
    			) 
    		 ) );
    
    			// Re-insert thrash link preserved from the default $actions.
    			$actions['trash']=$trash;
    		}
    	}
    
    	return $actions;
    }
    

You must log in before being able to contribute a note or feedback.