Filter uncanny-automator

automator_option_get_redirect_url

Filters the redirect URL after an Automator action, allowing modification before redirection occurs.

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

Description

Fires after the redirect URL option has been retrieved. Developers can use this filter to modify the redirect URL before it is returned. The `$option` parameter contains the current redirect URL.


Usage

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

Parameters

$option (mixed)
This parameter contains the array of options for the redirect URL field.

Return Value

The filtered value.


Examples

// Modify the redirect URL for a specific recipe action, perhaps to add query parameters based on user data.
add_filter( 'automator_option_get_redirect_url', function( $option ) {
	// Check if the current option is an array and contains the expected keys for a redirect URL.
	if ( is_array( $option ) && isset( $option['value'] ) && ! empty( $option['value'] ) ) {
		// Example: Append a user ID query parameter to the redirect URL if the user is logged in.
		if ( is_user_logged_in() ) {
			$user_id = get_current_user_id();
			$option['value'] = add_query_arg( 'user_id', $user_id, $option['value'] );
		}

		// Example: Always ensure the URL is absolute.
		$option['value'] = esc_url_raw( $option['value'] );
	}

	// Always return the modified (or original if no changes were made) $option array.
	return $option;
}, 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/lib/helpers/class-automator-recipe-helpers.php:787

public function get_redirect_url( $label = null, $option_code = 'REDIRECTURL' ) {

		if ( ! $label ) {
			$label = esc_attr__( 'Redirect URL', 'uncanny-automator' );
		}

		$option = array(
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'url',
			'supports_tokens' => true,
			'required'        => true,
			'placeholder'     => 'https://',
		);

		$option = apply_filters_deprecated( 'uap_option_get_redirect_url', array( $option ), '3.0', 'automator_option_get_redirect_url' );

		return apply_filters( 'automator_option_get_redirect_url', $option );
	}


Scroll to Top