Cf7_Tokens::parse_cf7_token( $value,  $pieces,  $recipe_id,  $trigger_data,  $user_id,  $replace_args )


Parameters Parameters

$value

(Required)

$pieces

(Required)

$recipe_id

(Required)

$trigger_data

(Required)

$user_id

(Required)

$replace_args

(Required)


Top ↑

Return Return

(mixed)


Source Source

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

	public function parse_cf7_token( $value, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args ) {
		$piece        = 'CF7FORMS';
		$piece_fields = 'CF7FIELDS';
		if ( $pieces ) {
			if ( in_array( $piece, $pieces ) || in_array( $piece_fields, $pieces ) ) {

				$recipe_log_id = Automator()->maybe_create_recipe_log_entry( $recipe_id, $user_id )['recipe_log_id'];
				if ( $trigger_data && $recipe_log_id ) {
					foreach ( $trigger_data as $trigger ) {
						if ( key_exists( $piece, $trigger['meta'] ) || key_exists( $piece_fields, $trigger['meta'] ) ) {
							$trigger_id     = $trigger['ID'];
							$trigger_log_id = $replace_args['trigger_log_id'];
							$token_info     = explode( '|', $pieces[2] );
							$form_id        = $token_info[0];
							$meta_key       = $token_info[1];
							$meta_field     = $piece . '_' . $form_id;
							$user_meta      = Automator()->helpers->recipe->get_form_data_from_trigger_meta( $meta_field, $trigger_id, $trigger_log_id, $user_id );
							if ( is_array( $user_meta ) && key_exists( trim( $meta_key ), $user_meta ) ) {
								if ( is_array( $user_meta[ $meta_key ] ) ) {
									$value = join( ', ', $user_meta[ $meta_key ] );
								} else {
									$value = $user_meta[ $meta_key ];
								}
							}
						}
					}
				}
			} elseif ( in_array( 'CF7SUBFIELD', $pieces ) ) {
				if ( $trigger_data ) {
					foreach ( $trigger_data as $trigger ) {
						if ( key_exists( 'CF7SUBFIELD', $trigger['meta'] ) && isset( $trigger['meta'][ $pieces[2] ] ) ) {
							$value = $trigger['meta'][ $pieces[2] ];
						}
					}
				}
			}
		}

		return $value;
	}