Action
uncanny-automator
automator_admin_logs_list_table_extra_nav_before
Fires before the navigation in the Automator admin logs table.
add_action( 'automator_admin_logs_list_table_extra_nav_before', $callback, 10, 1 );
Description
Fires before the navigation controls are displayed in the Automator admin logs table. Developers can use this hook to add custom elements, such as search fields or additional filtering options, before the standard "top" or "bottom" table navigation appears.
Usage
add_action( 'automator_admin_logs_list_table_extra_nav_before', 'your_function_name', 10, 1 );
Examples
/**
* Example function to add a custom search field before the logs list table navigation.
*
* This function hooks into the 'automator_admin_logs_list_table_extra_nav_before' action
* to inject a custom search input field, allowing users to filter logs by a specific
* keyword before the default navigation elements appear.
*
* @param string $which The location of the navigation ('top' or 'bottom').
*/
function my_custom_automator_log_search_field( $which ) {
// Ensure this only runs on the 'top' navigation part.
if ( 'top' === $which ) {
// Get the current search term if it exists in the URL.
$current_search_term = isset( $_GET['log_search'] ) ? sanitize_text_field( $_GET['log_search'] ) : '';
?>
<div class="alignleft actions">
<label for="log_search" class="screen-reader-text"><?php esc_html_e( 'Search Logs', 'your-text-domain' ); ?></label>
<input type="text" id="log_search" name="log_search" value="<?php echo esc_attr( $current_search_term ); ?>" placeholder="<?php esc_attr_e( 'Enter keyword...', 'your-text-domain' ); ?>" />
<?php submit_button( __( 'Search', 'your-text-domain' ), '', 'search_logs_submit', false ); ?>
</div>
<?php
}
}
add_action( 'automator_admin_logs_list_table_extra_nav_before', 'my_custom_automator_log_search_field', 10, 1 );
/**
* Example function to modify the logs query based on custom search input.
*
* This function hooks into a hypothetical 'automator_admin_logs_query_args' filter
* (or a similar filter that exposes the WP_Query arguments for the logs table)
* to add a WHERE clause based on the 'log_search' GET parameter.
*
* NOTE: The actual hook to filter the query might vary. This is an illustrative example.
* You would need to identify the correct filter hook provided by Uncanny Automator
* for modifying the logs query. If no such filter exists, you might need to
* hook into 'pre_get_posts' and check if it's the logs list table query.
*
* @param array $query_args The current WP_Query arguments for the logs list table.
* @return array The modified WP_Query arguments.
*/
function my_filter_automator_logs_by_search( $query_args ) {
// Check if our custom search parameter is set in the URL.
if ( isset( $_GET['log_search'] ) && ! empty( $_GET['log_search'] ) ) {
$search_term = sanitize_text_field( $_GET['log_search'] );
// Assuming the logs table has a meta field or content field to search.
// This part is hypothetical and depends on how Uncanny Automator stores log data.
// For demonstration, let's assume there's a meta_query to search a 'log_message' meta key.
// You'll need to adapt this to the actual data structure.
if ( ! isset( $query_args['meta_query'] ) ) {
$query_args['meta_query'] = array();
}
// Add a 'LIKE' condition to search the 'log_message' meta key.
$query_args['meta_query'][] = array(
'key' => 'log_message', // Replace with the actual meta key or field to search.
'value' => $search_term,
'compare' => 'LIKE',
);
// If you need to search the post title or content directly if logs are post types,
// you might use 's' or 'title' arguments depending on the context.
// $query_args['s'] = $search_term;
}
return $query_args;
}
// This hook is hypothetical. Replace 'automator_admin_logs_query_args' with the actual hook
// if it exists, or use 'pre_get_posts' and add checks to target the logs table.
// add_filter( 'automator_admin_logs_query_args', 'my_filter_automator_logs_by_search', 10, 1 );
/**
* Example function to add a custom status filter to the logs list table.
*
* This function hooks into the 'automator_admin_logs_list_table_extra_nav_before' action
* to add a dropdown for filtering logs by a custom status.
*
* @param string $which The location of the navigation ('top' or 'bottom').
*/
function my_custom_automator_log_status_filter( $which ) {
if ( 'top' === $which ) {
// Get the current status filter if it exists in the URL.
$current_status = isset( $_GET['log_status'] ) ? sanitize_key( $_GET['log_status'] ) : '';
?>
<div class="alignleft actions">
<label for="log_status" class="screen-reader-text"><?php esc_html_e( 'Filter by Status', 'your-text-domain' ); ?></label>
<select name="log_status" id="log_status">
<option value=""><?php esc_html_e( 'All statuses', 'your-text-domain' ); ?></option>
<option value="success" <?php selected( $current_status, 'success' ); ?>><?php esc_html_e( 'Success', 'your-text-domain' ); ?></option>
<option value="error" <?php selected( $current_status, 'error' ); ?>><?php esc_html_e( 'Error', 'your-text-domain' ); ?></option>
<option value="pending" <?php selected( $current_status, 'pending' ); ?>><?php esc_html_e( 'Pending', 'your-text-domain' ); ?></option>
<?php // Add more custom statuses as needed ?>
</select>
<?php submit_button( __( 'Filter', 'your-text-domain' ), '', 'filter_logs_submit', false ); ?>
</div>
<?php
}
}
add_action( 'automator_admin_logs_list_table_extra_nav_before', 'my_custom_automator_log_status_filter', 15, 1 ); // Use a slightly higher priority
/**
* Example function to filter the logs query by custom status.
*
* This function hooks into a hypothetical 'automator_admin_logs_query_args' filter
* to add a meta query condition based on the selected status.
*
* @param array $query_args The current WP_Query arguments for the logs list table.
* @return array The modified WP_Query arguments.
*/
function my_filter_automator_logs_by_status( $query_args ) {
// Check if our custom status parameter is set in the URL.
if ( isset( $_GET['log_status'] ) && ! empty( $_GET['log_status'] ) ) {
$status = sanitize_key( $_GET['log_status'] );
// Assuming the logs table has a meta field 'log_status' to store the status.
if ( ! isset( $query_args['meta_query'] ) ) {
$query_args['meta_query'] = array();
}
$query_args['meta_query'][] = array(
'key' => 'log_status', // Replace with the actual meta key storing the status.
'value' => $status,
'compare' => '=',
);
}
return $query_args;
}
// This hook is hypothetical. Replace 'automator_admin_logs_query_args' with the actual hook
// if it exists, or use 'pre_get_posts' and add checks to target the logs table.
// add_filter( 'automator_admin_logs_query_args', 'my_filter_automator_logs_by_status', 20, 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:1022
protected function extra_tablenav( $which ) {
if ( 'top' === $which ) {
do_action( 'automator_admin_logs_list_table_extra_nav_before' );
// Use PRO filters if available.
if ( class_exists( 'uncanny_automator_proPro_Filters' ) ) {
echo Pro_Filters::activities_filters_html( $this->tab ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
do_action( 'automator_admin_logs_list_table_extra_nav_after' );
return;
}
// Otherwise, use placeholder.
include Utilities::automator_get_view( 'admin-logs/filters.php' );
do_action( 'automator_admin_logs_list_table_extra_nav_after' );
return;
}
}