Action
uncanny-automator
automator_class_list_table_get_query_adapter_after
Fires after the query adapter is retrieved for the automator class list table, allowing modifications.
add_action( 'automator_class_list_table_get_query_adapter_after', $callback, 10, 1 );
Description
Fires after the query adapter for the Logs List Table is retrieved and potentially filtered. Developers can use this hook to further modify or inspect the query adapter before it's used to fetch log entries. This hook is called within the core Logs List Table class.
Usage
add_action( 'automator_class_list_table_get_query_adapter_after', 'your_function_name', 10, 1 );
Parameters
-
$this(mixed) - The `$this` parameter refers to the current instance of the `Logs_List_Table` class.
Examples
<?php
/**
* Example of using the automator_class_list_table_get_query_adapter_after action hook.
* This function modifies the query arguments for the logs list table after they have been composed.
* In this example, we'll add a condition to only show logs related to a specific automator action ID if that ID is provided.
*/
function my_automator_logs_modify_query_after( $list_table_instance ) {
// Ensure we have a valid instance of the Logs_List_Table
if ( ! $list_table_instance instanceof Uncanny_Automator_Logs_List_Table ) {
return;
}
// Access and potentially modify the query arguments.
// Note: The exact way to access/modify query arguments might depend on how
// the $this object is structured internally by the plugin.
// This is a hypothetical example assuming $this has a public property like 'query_args'.
// You would need to inspect the $list_table_instance object to confirm.
// For demonstration, let's assume we can get and modify $query_args.
// In a real scenario, you might check for a GET parameter, a user preference, etc.
// Hypothetical: Check if a specific automator action ID is present in the URL query
$specific_action_id = isset( $_GET['automator_action_id'] ) ? intval( $_GET['automator_action_id'] ) : null;
if ( $specific_action_id ) {
// Hypothetical: Accessing the query arguments stored within the instance.
// You'd need to know the internal structure of the $list_table_instance.
// Let's assume there's a protected or public property like $query_args
// that holds the WP_Query arguments.
// This is a placeholder and may not work directly without inspecting the class.
// A more robust approach might involve the plugin providing a method to get/set query args.
// For the sake of a realistic example, let's assume we are passed the query object itself
// or can access it. If not, this hook might be intended for side effects.
// If the hook only passes $this, we would need to rely on public methods or properties
// if the plugin exposes them for query manipulation after composition.
// A more realistic scenario if the hook doesn't expose query args directly:
// You might use this hook to trigger other actions based on the composed query's context.
// For example, to add specific column content or UI elements that are dependent on the query.
// If the hook intends for direct query manipulation and the plugin's internal structure allows:
// Let's simulate having access to the query parameters that would be used for the list table.
// This might involve inspecting the class properties or if there's a setter.
// Example: If the plugin allows accessing and modifying the 'meta_query' part of the query.
// This is highly speculative based on common WordPress query structures.
// **Realistic approach assuming the hook is for modifying the underlying WP_Query arguments:**
// The `$this` parameter in this context is the `Logs_List_Table` instance.
// We need to find out how this instance manages its query.
// Let's assume the `Logs_List_Table` has a method like `get_query_args()` and `set_query_args()`.
// Or, if query arguments are directly accessible, e.g., `$this->query_args`.
// Since we don't have the exact definition of `Logs_List_Table` properties,
// let's assume the intent is to slightly tweak the *intended* query.
// This often involves using `WP_Query`'s structure.
// If the `$this` object exposes the `WP_Query` object or its arguments, we can modify them.
// For example, if the list table builds a `$wp_query` object and makes it accessible.
// A common pattern for list tables is to have a `$this->query_args` property
// that is an array representing the arguments for `WP_Query`.
// Hypothetical scenario: You want to filter logs by a specific trigger type.
$trigger_type_filter = isset( $_GET['automator_trigger_type'] ) ? sanitize_text_field( $_GET['automator_trigger_type'] ) : null;
if ( $trigger_type_filter ) {
// If the list table's query arguments are accessible via a property like 'query_args'
if ( isset( $list_table_instance->query_args ) && is_array( $list_table_instance->query_args ) ) {
// Ensure meta_query is an array if it doesn't exist
if ( ! isset( $list_table_instance->query_args['meta_query'] ) || ! is_array( $list_table_instance->query_args['meta_query'] ) ) {
$list_table_instance->query_args['meta_query'] = array();
}
// Add a meta query condition to filter by trigger type
$list_table_instance->query_args['meta_query'][] = array(
'key' => 'trigger_type', // Assuming 'trigger_type' is a meta key used by the plugin
'value' => $trigger_type_filter,
'compare' => '=',
);
// Note: You might need to adjust the 'relation' if you're adding multiple meta queries.
}
}
}
}
// Hook the function to the action, specifying the priority and the number of arguments accepted.
// The 'automator_class_list_table_get_query_adapter_after' hook passes '$this' which is the list table instance.
// So, we accept one argument.
add_action( 'automator_class_list_table_get_query_adapter_after', 'my_automator_logs_modify_query_after', 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/admin-logs/wp-list-table/class-logs-list-table.php:108
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 ] : '';
}