Row actions are actions belonging to an item in a table. In the image above, the row actions are the three verbs underneath the item’s main line, or name.
Each action consists of a linked text, with an optional link title.
// Create the row actions object $row_actions = $this->row_actions(); // Set the base url, so that we don't have to set the ID for each action URL. $row_actions->url( add_query_arg( [ 'id' => $recording->id ] ) ); // Create a new action $row_actions->action( 'edit' ) // Set the URL, in this case using an array, like for add_query_arg ->url( [ 'tab' => 'edit_recording' ] ) // Translate the title ->title_( 'Edit the recording' ) // Set the translated action text ->text( 'Edit' ); // Retrieve an existing action $row_actions->action( 'edit' ) // Set another text. ->text( 'Edit this' ); // New action $row_actions->action( 'view' ) // Order from 10 to 99. 50 is the default. ->sort_order( 25 ) // Setting the URL directly ->url( '?tab=edit' ) // This title is not translated ->title( 'View the recording' ) // Set the text without translating it ->text( 'View' ); // The main row is optional, uses the same methods as the actions and can be set before or after the actions. $row_actions->main() ->url( [ 'tab' => 'edit_recording' ] ) ->title( 'Edit the recording' ) ->text( 'A taxonomy recording' ); echo $row_actions;
Ordering
When the actions are displayed, they are sorted first using the internal order number, then alphabetically.
The default order is 50, with 10 coming before 50 which comes before 90.
The order can be changed with ->sort_order( 25 )
.
Same as
Since the main action usually shares the same properties as the edit link, you can create it based off of an existing action.
$row_actions->main()
// Copy the properties from the edit action
->same_as( 'edit' )
// But use our own text, instead of "Edit"
->text( 'A taxonomy recording' );