Filter
uncanny-automator
automator_setup_api_logs_sortables
Filters the sortable columns available for the Automator API logs table.
add_filter( 'automator_setup_api_logs_sortables', $callback, 10, 1 );
Description
This filter hook allows developers to modify the sortable columns for the API logs table. It fires after the default sortable columns are defined. Developers can add, remove, or change the sortable properties of existing columns to customize the API log table's sorting capabilities.
Usage
add_filter( 'automator_setup_api_logs_sortables', 'your_function_name', 10, 1 );
Parameters
-
$sortables(mixed) - This parameter contains an array of columns that can be sorted in the API logs table.
Return Value
The filtered value.
Examples
/**
* Example: Add a new sortable column to the API logs table for 'request_method'.
*
* This filter hook allows developers to modify the array of sortable columns
* for the API logs table in the Automator plugin.
*
* @param array $sortables An array of sortable columns. Each key is the column ID,
* and the value is an array containing the column ID and a boolean
* indicating if it's sortable by default.
*
* @return array The modified array of sortable columns.
*/
add_filter( 'automator_setup_api_logs_sortables', function( $sortables ) {
// Add 'request_method' as a new sortable column.
// The format is 'column_id' => array( 'column_id', is_sortable_by_default ).
$sortables['request_method'] = array( 'request_method', true );
// You could also remove existing sortable columns if needed:
// unset( $sortables['endpoint'] );
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/admin/api-log/class-api-log.php:98
public function log_body( $current_tab, $args = array() ) {
$headings = array(
'type' => esc_attr__( 'Type', 'uncanny-automator' ),
'date' => esc_attr__( 'Date', 'uncanny-automator' ),
'title' => esc_attr__( 'Title', 'uncanny-automator' ),
'endpoint' => esc_attr__( 'Endpoint', 'uncanny-automator' ),
'status' => esc_attr__( 'Response code', 'uncanny-automator' ),
'completed' => esc_attr__( 'Status', 'uncanny-automator' ),
'error_message' => esc_attr__( 'Notes', 'uncanny-automator' ),
'time_spent' => esc_attr__( 'Response time (ms)', 'uncanny-automator' ),
);
if ( ! defined( 'AUTOMATOR_PRO_FILE' ) ) {
$headings['price'] = esc_attr__( 'App credits charged', 'uncanny-automator' );
$headings['balance'] = esc_attr__( 'App credits left', 'uncanny-automator' );
}
$headings['actions'] = esc_attr__( 'Actions', 'uncanny-automator' );
$headings = wp_parse_args( $args, $headings );
$sortables = array(
'type' => array( 'type', true ),
'date' => array( 'date', true ),
'title' => array( 'title', true ),
'completed' => array( 'completed', true ),
'error_message' => array( 'error_message', true ),
'recipe_title' => array( 'recipe_title', true ),
'status' => array( 'status', true ),
'time_spent' => array( 'time_spent', true ),
'endpoint' => array( 'endpoint', true ),
);
$sortables = apply_filters( 'automator_setup_api_logs_sortables', $sortables );
//Prepare Table of elements
$wp_list_table = new Api_Log_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();
}