Filter uncanny-automator

automator_rest_endpoint_loops_logs_resources_disable_run

Filters whether Automator REST endpoint loops logs resources can be run by default.

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

Description

Use this filter to disable the retrieval of specific loop run logs from the REST API. By returning an empty array, you can prevent these logs from being displayed, offering granular control over logged data visibility.


Usage

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

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to disable loop runs for specific conditions using the
 * automator_rest_endpoint_loops_logs_resources_disable_run filter.
 *
 * This function checks if the current action ID is '123' and if a specific
 * parameter 'disable_all_loops' is set to 'yes' in the request parameters.
 * If both conditions are met, it returns an empty array, effectively disabling
 * the loop runs for this specific scenario.
 *
 * @param bool  $default_value The default value for the filter, usually false.
 * @param array $loop          The loop data.
 * @param mixed $item          The current item in the loop.
 * @param array $params        The request parameters.
 * @param int   $action_id     The ID of the action.
 * @param array $log           The log data.
 *
 * @return array An empty array to disable runs, or the original value.
 */
add_filter(
	'automator_rest_endpoint_loops_logs_resources_disable_run',
	function ( $should_disable_runs, $loop, $item, $params, $action_id, $log ) {
		// Check if the action ID is '123' and if the 'disable_all_loops' parameter is 'yes'.
		if ( '123' === $action_id && isset( $params['disable_all_loops'] ) && 'yes' === $params['disable_all_loops'] ) {
			// Return an empty array to disable loop runs for this specific condition.
			return array();
		}

		// Otherwise, return the original value (which is likely false, meaning don't disable).
		return $should_disable_runs;
	},
	10, // Priority
	6  // Number of accepted arguments
);

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/services/rest/endpoint/log-endpoint/resources/loop-logs-resources.php:397

* @param mixed[] $log
	 *
	 * @return mixed[]
	 */
	public function get_runs( $loop, $item, $params, $action_id, $log ) {

		// Ability to disable loop runs.
		if ( true === apply_filters( 'automator_rest_endpoint_loops_logs_resources_disable_run', false ) ) {
			return array();
		}

		// Retrieve the distinct statuses collection for the current action.
		$distinct_statuses = $this->loop_logs_queries->get_distinct_statuses( $action_id, $params );

		$type = $loop['iterable_expression']['type'] ?? null;

Scroll to Top