Cf7_Tokens::automator_save_cf7_form_func( WPCF7_ContactForm $contact_form,  $recipes,  $args )


Parameters Parameters

$contact_form

(WPCF7_ContactForm) (Required)

$recipes

(Required)

$args

(Required)


Source Source

File: src/integrations/contact-form7/tokens/cf7-tokens.php

	public function automator_save_cf7_form_func( WPCF7_ContactForm $contact_form, $recipes, $args ) {
		if ( is_array( $args ) ) {
			foreach ( $args as $trigger_result ) {
				//$trigger_result = array_pop( $args );
				if ( true === $trigger_result['result'] ) {

					if ( $recipes && $contact_form instanceof WPCF7_ContactForm ) {
						foreach ( $recipes as $recipe ) {
							$triggers = $recipe['triggers'];
							if ( $triggers ) {
								foreach ( $triggers as $trigger ) {
									$trigger_id = $trigger['ID'];
									if ( ! key_exists( 'CF7FORMS', $trigger['meta'] ) && ! key_exists( 'CF7FIELDS', $trigger['meta'] ) ) {
										continue;
									} else {
										if ( isset( $trigger['meta']['CF7FORMS'] ) ) {
											$form_id = (int) $trigger['meta']['CF7FORMS'];
										} elseif ( isset( $trigger['meta']['CF7FIELDS'] ) ) {
											$form_id = (int) $trigger['meta']['CF7FIELDS'];
										}
										$data    = $this->get_data_from_contact_form( $contact_form );
										$user_id = (int) $trigger_result['args']['user_id'];
										if ( $user_id ) {
											$recipe_log_id_raw = Automator()->maybe_create_recipe_log_entry( $recipe['ID'], $user_id );
											if ( is_array( $recipe_log_id_raw ) && key_exists( 'recipe_log_id', $recipe_log_id_raw ) ) {
												//$recipe_log_id  = absint( $recipe_log_id_raw['recipe_log_id'] );
												$trigger_log_id = (int) $trigger_result['args']['get_trigger_id'];
												$run_number     = (int) $trigger_result['args']['run_number'];

												$args = [
													'user_id'        => $user_id,
													'trigger_id'     => $trigger_id,
													'meta_key'       => 'CF7FORMS_' . $form_id,
													'meta_value'     => serialize( $data ),
													'run_number'     => $run_number, //get run number
													'trigger_log_id' => $trigger_log_id,
												];

												Automator()->insert_trigger_meta( $args );
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}