Filter uncanny-automator-pro

automator_pro_generate_random_email_domain

Filters the randomly generated email domain before it's used by the generator integration.

add_filter( 'automator_pro_generate_random_email_domain', $callback, 10, 6 );

Description

Filters the generated random email domain. Developers can use this hook to override the default domain with their own or modify the generated domain dynamically based on user, action, or recipe data. The `$parsed` argument contains the original domain setting from the action configuration.


Usage

add_filter( 'automator_pro_generate_random_email_domain', 'your_function_name', 10, 6 );

Parameters

$user_id (mixed)
This parameter represents the default domain to be used if no other domain is specified.
$action_data (mixed)
This parameter contains the ID of the user for whom the random email is being generated.
$recipe_id (mixed)
This parameter contains an array of data associated with the specific action being processed, which might include settings for generating a random email.
$args (mixed)
This parameter contains the ID of the Uncanny Automator recipe that triggered the action.
$parsed (mixed)
This parameter is an array containing all the arguments passed to the function, allowing for flexible data handling.
$this (mixed)
This parameter refers to the instance of the `UOA_Generate_Random_Email` class itself.

Return Value

The filtered value.


Examples

/**
 * Filter the default domain for generated random emails.
 *
 * This function provides a custom domain for generating random email addresses
 * when the default 'example.com' is not suitable or when a specific domain
 * is required for a particular user or recipe.
 *
 * @param string $domain      The default domain.
 * @param int    $user_id     The ID of the user associated with the recipe.
 * @param array  $action_data The data associated with the action.
 * @param int    $recipe_id   The ID of the recipe.
 * @param array  $args        Additional arguments passed to the action.
 * @param array  $parsed      The parsed data from the action's settings.
 * @param object $this        The instance of the UOA_Generate_Random_Email action class.
 *
 * @return string The custom domain to use for generating random emails.
 */
add_filter(
	'automator_pro_generate_random_email_domain',
	function ( $domain, $user_id, $action_data, $recipe_id, $args, $parsed, $this_instance ) {
		// Example: If the recipe ID is 123, use a specific domain.
		if ( absint( $recipe_id ) === 123 ) {
			return 'mycustomdomain.org';
		}

		// Example: If the user is a premium subscriber, use a premium domain.
		if ( class_exists( 'Uncanny_Automator_ProUtilitiesPremium' ) ) {
			$premium_utilities = new Uncanny_Automator_ProUtilitiesPremium();
			if ( $premium_utilities->is_user_premium( $user_id ) ) {
				return 'premiumuser.net';
			}
		}

		// Fallback to the original domain if no custom logic applies.
		return $domain;
	},
	10, // Priority
	7  // 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

uncanny-automator-pro/src/integrations/generator/actions/uoa-generate-random-email.php:109

protected function process_action( $user_id, $action_data, $recipe_id, $args, $parsed ) {

		$domain          = sanitize_text_field( $parsed['RAND_EMAIL_DOMAIN'] );
		$include_numbers = sanitize_text_field( $parsed['RAND_EMAIL_NUMS'] ) === 'true';
		$prefix          = sanitize_text_field( $parsed['RAND_EMAIL_PREFIX'] );

		if ( empty( $domain ) ) {
			$domain = apply_filters( 'automator_pro_generate_random_email_domain', 'example.com', $user_id, $action_data, $recipe_id, $args, $parsed, $this );
		}

		$random_email = $this->generate_random_email( $domain, $include_numbers, $prefix );

		$this->hydrate_tokens(
			array(
				'RANDOM_EMAIL' => $random_email,
			)
		);

		// Set log properties.
		$this->set_log_properties(
			array(
				'type'  => 'email',
				'label' => __( 'Generated email', 'uncanny-automator-pro' ),
				'value' => $random_email,
			)
		);
		Automator()->complete->action( $user_id, $action_data, $recipe_id );
	}

Scroll to Top