Action uncanny-automator

automator_save_anon_wp_form

Fires when an anonymous WPForms entry is saved, providing access to form fields, data, and associated recipes.

add_action( 'automator_save_anon_wp_form', $callback, 10, 4 );

Description

Fires after an anonymous WPForms submission is saved. This hook provides access to form fields, form data, associated recipes, and additional arguments. Developers can use it to perform custom actions, log data, or modify the saved entry before finalization.


Usage

add_action( 'automator_save_anon_wp_form', 'your_function_name', 10, 4 );

Parameters

$fields (mixed)
This parameter contains the submitted form fields.
$form_data (mixed)
This parameter contains the submitted form fields and their values.
$recipes (mixed)
This parameter contains the raw data submitted for the WPForms form, including field IDs and their corresponding values.
$args (mixed)
This parameter contains an array of recipes that are triggered by the form submission.

Examples

<?php

/**
 * Example callback function for the automator_save_anon_wp_form action hook.
 * This function demonstrates how to access and potentially process the data
 * passed to the hook, such as form fields, form data, and associated recipes.
 *
 * @param mixed $fields      The fields submitted in the form.
 * @param mixed $form_data   The raw form data.
 * @param mixed $recipes     The recipes associated with this form submission.
 * @param mixed $args        Additional arguments, often including user ID and trigger entry data.
 */
function my_custom_automator_save_anon_wp_form_handler( $fields, $form_data, $recipes, $args ) {
    // Log or process the form submission data.
    // In a real-world scenario, you might:
    // 1. Log the submitted fields for debugging or auditing.
    // 2. Update custom user meta based on specific form fields.
    // 3. Trigger other custom processes based on the form content and associated recipes.

    // Example: Log the submitted fields and the user ID from the args.
    if ( isset( $args['user_id'] ) && ! empty( $args['user_id'] ) ) {
        $user_id = $args['user_id'];
        error_log( "Automator: Received anonymous WPForms submission for User ID: " . $user_id );
    } else {
        error_log( "Automator: Received anonymous WPForms submission with no associated User ID." );
    }

    if ( ! empty( $fields ) ) {
        error_log( "Automator: Submitted Fields: " . print_r( $fields, true ) );
    }

    if ( ! empty( $form_data ) ) {
        error_log( "Automator: Form Data: " . print_r( $form_data, true ) );
    }

    if ( ! empty( $recipes ) && is_array( $recipes ) ) {
        $recipe_ids = array_keys( $recipes );
        error_log( "Automator: Associated Recipe IDs: " . implode( ', ', $recipe_ids ) );
    }

    // You could also perform actions based on specific form field values.
    // For example, if 'your_specific_field_name' exists and has a certain value:
    if ( isset( $fields['your_specific_field_name'] ) && 'desired_value' === $fields['your_specific_field_name'] ) {
        error_log( "Automator: Specific field condition met!" );
        // Perform custom action here.
    }
}

// Hook into the action with a priority and specify the number of arguments expected.
add_action( 'automator_save_anon_wp_form', 'my_custom_automator_save_anon_wp_form_handler', 30, 4 );

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/integrations/wpforms/triggers/anon-wpf-subform.php:112
uncanny-automator-pro/src/integrations/wpforms/triggers/anon-wpf-submitfield.php:135
uncanny-automator-pro/src/integrations/wpforms/triggers/anon-wpf-subform-with-conditions-paypalpayment.php:148
uncanny-automator-pro/src/integrations/wpforms/triggers/wpf-subform-with-conditions-paypal-payment.php:158

public function wpform_submit( $fields, $entry, $form_data, $entry_id ) {

		if ( empty( $form_data ) ) {
			return;
		}

		$user_id = get_current_user_id();
		$args    = array(
			'code'    => $this->trigger_code,
			'meta'    => $this->trigger_meta,
			'post_id' => intval( $form_data['id'] ),
			'user_id' => $user_id,
		);

		$args = Automator()->process->user->maybe_add_trigger_entry( $args, false );

		// Adding an action to save form submission in trigger meta
		$recipes = Automator()->get->recipes_from_trigger_code( $this->trigger_code );
		do_action( 'automator_save_anon_wp_form', $fields, $form_data, $recipes, $args );

		if ( $args ) {
			foreach ( $args as $result ) {
				if ( true === $result['result'] ) {
					if ( isset( $result['args'] ) && isset( $result['args']['get_trigger_id'] ) ) {
						$user_ip    = Automator()->helpers->recipe->wpforms->options->get_entry_user_ip_address( $entry_id );
						$entry_date = Automator()->helpers->recipe->wpforms->options->get_entry_entry_date( $entry_id );
						$entry_id   = Automator()->helpers->recipe->wpforms->options->get_entry_entry_id( $entry_id );
						// Saving form values in trigger log meta for token parsing!
						$wpf_args               = array(
							'trigger_id'     => (int) $result['args']['trigger_id'],
							'user_id'        => $user_id,
							'trigger_log_id' => $result['args']['get_trigger_id'],
							'run_number'     => $result['args']['run_number'],
						);
						$wpf_args['meta_key']   = 'WPFENTRYID';
						$wpf_args['meta_value'] = $entry_id;
						Automator()->insert_trigger_meta( $wpf_args );

						$wpf_args['meta_key']   = 'WPFENTRYIP';
						$wpf_args['meta_value'] = $user_ip;
						Automator()->insert_trigger_meta( $wpf_args );

						$wpf_args['meta_key']   = 'WPFENTRYDATE';
						$wpf_args['meta_value'] = maybe_serialize( Automator()->helpers->recipe->wpforms->options->get_entry_date( $entry_date ) );
						Automator()->insert_trigger_meta( $wpf_args );
					}
					Automator()->process->user->maybe_trigger_complete( $result['args'] );
				}
			}
		}
	}

Internal Usage

Found in src/integrations/wpforms/tokens/wpf-tokens.php:26:

add_action( 'automator_save_anon_wp_form', array( $this, 'wpf_form_save_entry' ), 40, 4 );
Scroll to Top