Filter uncanny-automator

automator_setup_trigger_logs_sortables

Filters the sortable columns for the Automator trigger logs table before they are displayed.

add_filter( 'automator_setup_trigger_logs_sortables', $callback, 10, 1 );

Description

This filter allows developers to customize the sortable columns displayed in the WordPress Automator recipe logs. Modify the `$sortables` array to add, remove, or alter the behavior of available sorting options, providing greater control over how log data is presented and filtered.


Usage

add_filter( 'automator_setup_trigger_logs_sortables', 'your_function_name', 10, 1 );

Parameters

$sortables (mixed)
This parameter contains an array of column headings that are sortable in the logs view.

Return Value

The filtered value.


Examples

/**
 * Add a new sortable column to the Automator logs table for 'trigger_name'.
 *
 * This example demonstrates how to add a new sortable column to the
 * Automator logs table, allowing users to sort logs by the name of the trigger.
 *
 * @param array $sortables An associative array of sortable columns.
 * @return array Modified array of sortable columns.
 */
add_filter( 'automator_setup_trigger_logs_sortables', function( $sortables ) {
	// Add a new sortable column for 'trigger_name'.
	// The key 'trigger_name' is the column ID.
	// The value is an array where the first element is the actual column ID
	// for sorting purposes (usually the same as the key), and the second
	// element is a boolean indicating if it's sortable (true) or not (false).
	$sortables['trigger_name'] = array( 'trigger_name', true );

	return $sortables;
}, 10, 1 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/core/views/admin-logs/component/logs.php:104
src/core/includes/recipe-logs-view.php:112

function automator_setup_trigger_logs( $current_tab, $args = array() ) {

	$headings = array(
		/* translators: Log column. */
		'trigger_title'     => esc_attr__( 'Trigger', 'uncanny-automator' ),
		/* translators: Log column. The trigger completion date */
		'trigger_date'      => esc_attr__( 'Completion date', 'uncanny-automator' ),
		/* translators: Log column. */
		'recipe_title'      => esc_attr__( 'Recipe', 'uncanny-automator' ),
		/* translators: Log column. */
		'recipe_completed'  => esc_attr__( 'Recipe status', 'uncanny-automator' ),
		/* translators: Log column. */
		/* (Disabled @since 4.5) 'recipe_date_time'   => esc_attr__( 'Recipe completion date', 'uncanny-automator' ),
		/* translators: Log column. Noun. The recipe iteration */
		'recipe_run_number' => esc_attr__( 'Run #', 'uncanny-automator' ),
		/* translators: Log column. Noun. The trigger iteration */
		/* Moved below the title 'trigger_run_number' => esc_attr__( 'Trigger run #', 'uncanny-automator' ),
		/* translators: Log column. */
		'display_name'      => esc_attr__( 'User', 'uncanny-automator' ),
		'actions'           => ' ', // Need to pass something so column become available.
	);

	$headings = wp_parse_args( $args, $headings );

	$sortables = array(
		'trigger_title'      => array( 'trigger_title', true ),
		'trigger_date'       => array( 'trigger_date', true ),
		'recipe_title'       => array( 'recipe_title', true ),
		'recipe_completed'   => array( 'recipe_completed', true ), // linked
		'recipe_date_time'   => array( 'recipe_date_time', true ),
		'recipe_run_number'  => array( 'recipe_run_number', true ),
		'trigger_run_number' => array( 'trigger_run_number', false ),
		'display_name'       => array( 'display_name', true ),
	);

	$sortables = apply_filters( 'automator_setup_trigger_logs_sortables', $sortables );

	//Prepare Table of elements
	$wp_list_table = new Logs_List_Table();
	$wp_list_table->set_columns( $headings );
	$wp_list_table->set_sortable_columns( $sortables );
	$wp_list_table->set_tab( $current_tab );
	$wp_list_table->prepare_items();
	$wp_list_table->display();
}

Internal Usage

Found in src/core/views/recipe-logs-details.php:55:

add_filter( 'automator_setup_trigger_logs_sortables', '__return_empty_array' );
Scroll to Top