Filter uncanny-automator-pro

automator_db_query_operators

Filters database query operators, allowing customization of available operators for queries.

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

Description

Allows developers to modify the operators available for the DB Query action. This filter fires after Uncanny Automator Pro retrieves its default operators. Developers can add, remove, or alter operator options for custom database queries within automations.


Usage

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

Parameters

$operators (mixed)
This parameter is an array of operators used in the Uncanny Automator DB Query action, where each operator is represented as an associative array with 'text' and 'value' keys.

Return Value

The filtered value.


Examples

<?php

/**
 * Example of modifying the database query operators for Uncanny Automator.
 * This function will add a new custom operator to the list of available operators
 * for the 'Select Query' action in Uncanny Automator.
 *
 * @param array $operators The array of existing operators. Each element is an array
 *                         with 'text' and 'value' keys.
 * @return array The modified array of operators, including the new custom one.
 */
function my_custom_automator_db_query_operators( $operators ) {
    // Define our new custom operator.
    $new_operator = array(
        'text'  => __( 'Is Not Empty', 'your-text-domain' ), // User-friendly text
        'value' => 'not_empty', // Unique machine-readable value
    );

    // Add our new operator to the end of the existing operators array.
    $operators[] = $new_operator;

    // Return the modified array of operators.
    return $operators;
}

// Add the filter with a priority of 10 (default) and 1 accepted argument.
add_filter( 'automator_db_query_operators', 'my_custom_automator_db_query_operators', 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

uncanny-automator-pro/src/integrations/db-query/actions/select-query-run.php:250

protected function get_operators() {

		$operators = array();

		foreach ( $this->operators as $id => $operator ) {
			$operators[] = array(
				'text'  => $operator,
				'value' => $id,
			);
		}

		return apply_filters( 'automator_db_query_operators', $operators );
	}

Scroll to Top