Elem_Tokens::elem_token( $value,  $pieces,  $recipe_id,  $trigger_data,  $user_id,  $replace_args )

Parse the token.


Parameters Parameters

$value

(Required)

$pieces

(Required)

$recipe_id

(Required)

$trigger_data

(Required)

$user_id

(Required)

$replace_args

(Required)


Top ↑

Return Return

(null|string)


Source Source

File: src/integrations/elementor/tokens/elem-tokens.php

	public function elem_token( $value, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args ) {

		$piece = 'ELEMFORM';
		if ( $pieces ) {
			if ( in_array( $piece, $pieces ) ) {

				$recipe_log_id = isset( $replace_args['recipe_log_id'] ) ? (int) $replace_args['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'] ) ) {
							$trigger_id     = $trigger['ID'];
							$trigger_log_id = $replace_args['trigger_log_id'];
							$token_info     = explode( '|', $pieces[2] );
							$form_id        = $token_info[0];
							$meta_key       = isset( $token_info[1] ) ? $token_info[1] : '';
							$meta_field     = $piece . '_' . $form_id;
							$entry          = Automator()->helpers->recipe->get_form_data_from_trigger_meta( $meta_field, $trigger_id, $trigger_log_id, $user_id );
							if ( ! empty( $entry ) ) {
								if ( is_array( $entry ) && ! empty( $meta_key ) ) {
									$value = isset( $entry[ $meta_key ] ) ? $entry[ $meta_key ] : '';
									if ( is_array( $value ) ) {
										$value = implode( ', ', $value );
									}
								} else {
									$value = $entry;
								}
							}
						}
					}
				}
			}
		}

		return $value;
	}