Filter uncanny-automator

automator_class_list_table_get_query_adapter

Filters the query adapter for the automator class list table, allowing customization of how data is retrieved.

add_filter( 'automator_class_list_table_get_query_adapter', $callback, 10, 2 );

Description

Filters the query adapters used for the Automator logs list table. Developers can modify this array to customize or add new query adapters for different log types, enabling advanced filtering and data retrieval options. The hook provides access to the current query adapter configuration and the list table instance.


Usage

add_filter( 'automator_class_list_table_get_query_adapter', 'your_function_name', 10, 2 );

Parameters

$tabs_query (mixed)
This parameter holds an array of query arguments, where keys represent different log tabs and values are the corresponding database query definitions.
$this (mixed)
This parameter contains an array of query arguments, with keys representing different log tabs and values being the corresponding database queries.

Return Value

The filtered value.


Examples

<?php
/**
 * Example function to modify the query adapters for the Automator logs list table.
 * This function adds a new tab 'user-meta-log' and its corresponding query adapter.
 *
 * @param array $tabs_query The existing array of query adapters keyed by tab slugs.
 * @param AutomatorCoreAdminAdminLogsLogs_List_Table $this The instance of the Logs_List_Table class.
 * @return array The modified array of query adapters.
 */
function my_automator_custom_query_adapter( $tabs_query, $list_table_instance ) {

    // Check if the current user has the capability to view user meta logs.
    if ( current_user_can( 'manage_options' ) ) {
        // Define a custom query adapter for a new 'user-meta-log' tab.
        // In a real scenario, Pro_Filters::get_user_meta_query() would contain
        // the logic to build the WP_Query arguments for user meta logs.
        $tabs_query['user-meta-log'] = array(
            'callback' => array( $list_table_instance, 'get_user_meta_query_callback' ),
            'query_args' => array(
                // Example arguments for the WP_Query.
                'post_type' => 'user_meta_log_entry', // Assuming a custom post type for user meta logs.
                'posts_per_page' => 20,
                'meta_query' => array(
                    // Add specific meta queries if needed.
                ),
            ),
        );
    }

    // Return the modified query adapters array.
    return $tabs_query;
}

// Add the filter to the 'automator_class_list_table_get_query_adapter' hook.
// The '3' indicates the priority, and '2' indicates that the callback
// function accepts two arguments ($tabs_query, $this).
add_filter( 'automator_class_list_table_get_query_adapter', 'my_automator_custom_query_adapter', 3, 2 );
?>

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/admin-logs/wp-list-table/class-logs-list-table.php:105

private function get_query_provider( $provider = '', $tab = 'recipe-log' ) {

		$tabs_query = array(
			'recipe-log'      => $this->get_recipe_query(),
			'recipe-activity' => $this->get_recipe_query(),
			'trigger-log'     => $this->get_trigger_query(),
			'action-log'      => $this->get_action_query(),
		);

		if ( 'pro' === $provider ) {
			$tabs_query = array(
				'recipe-log'      => Pro_Filters::get_recipe_query(),
				'recipe-activity' => Pro_Filters::get_recipe_query(),
				'trigger-log'     => Pro_Filters::get_trigger_query(),
				'action-log'      => Pro_Filters::get_action_query(),
			);
		}

		// Allow others to hook and extend.
		$tabs_query = apply_filters( 'automator_class_list_table_get_query_adapter', $tabs_query, $this );

		// Allow others to run code after query composition.
		do_action( 'automator_class_list_table_get_query_adapter_after', $this );

		return isset( $tabs_query[ $tab ] ) ? $tabs_query[ $tab ] : '';
	}


Scroll to Top