Filter uncanny-automator

automator_recipe_log_view_query

Filter the recipe log view query. Filters the SQL query used to retrieve recipe log entries for the log view.

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

Description

This filter allows modification of the SQL query used to retrieve recipe logs before they are displayed. Developers can alter the query string to customize which log entries are fetched, for example, by adding specific WHERE clauses or joining additional tables. The hook fires just before the query is executed by the `Automator_DB` class.


Usage

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

Parameters

$query (string)
SQL query string.

Return Value

The filtered value.


Examples

<?php
/**
 * Example: Filter the automator recipe log query to include only recipes that are currently active.
 *
 * This example demonstrates how to modify the SQL query to add a WHERE clause,
 * ensuring that only logs for active recipes are retrieved.
 */
add_filter( 'automator_recipe_log_view_query', 'my_automator_filter_active_recipe_logs', 10, 1 );

function my_automator_filter_active_recipe_logs( $query ) {
    global $wpdb;

    // Assuming there's a way to identify active recipes, for example, through a meta key.
    // This is a hypothetical example, and the actual method to check for active recipes
    // might differ based on the Automator plugin's structure.
    // We'll assume recipes have a meta key like 'is_active' set to 1.
    $query .= "
        AND r.automator_recipe_id IN (
            SELECT post_id
            FROM {$wpdb->postmeta}
            WHERE meta_key = 'is_active' AND meta_value = '1'
        )
    ";

    return $query;
}
?>

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/class-automator-db.php:465

public static function recipe_log_view_query() {

		global $wpdb;

		// Base query to fetch recipe log data.
		$query = "SELECT 
					r.ID AS recipe_log_id,
					r.user_id,
					r.date_time AS recipe_date_time,
					r.completed AS recipe_completed,
					r.run_number,
					r.log_number,
					r.completed,
					r.automator_recipe_id,
					u.user_email,
					u.display_name,
					p.post_title AS recipe_title
				FROM {$wpdb->prefix}uap_recipe_log r
				LEFT JOIN {$wpdb->users} u
					ON u.ID = r.user_id
				JOIN {$wpdb->posts} p
					ON p.ID = r.automator_recipe_id";

		/**
		 * Filter the recipe log view query.
		 *
		 * @param string $query SQL query string.
		 */
		return apply_filters( 'automator_recipe_log_view_query', $query );
	}

Scroll to Top