AMELIABOOKING_TOKENS::parse_tokens( mixed $value, mixed $pieces, mixed $recipe_id, mixed $trigger_data, mixed $user_id, mixed $replace_args )

Parsing the tokens.


Parameters Parameters

$value

(Required)

$pieces

(Required)

$recipe_id

(Required)

$trigger_data

(Required)

$user_id

(Required)

$replace_args

(Required)


Top ↑

Return Return

(void)


Source Source

File: src/integrations/ameliabooking/tokens/ameliabooking-tokens.php

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

		$trigger_code = '';

		if ( isset( $trigger_data[0]['meta']['code'] ) ) {
			$trigger_code = $trigger_data[0]['meta']['code'];
		}

		if ( empty( $trigger_code ) || ! in_array( $trigger_code, self::APPOINTMENT_BOOKING_TOKENS_TRIGGERS, true ) ) {
			return $value;
		}

		if ( ! is_array( $pieces ) || ! isset( $pieces[1] ) || ! isset( $pieces[2] ) ) {
			return $value;
		}

		// The $pieces[2] is the token id.
		$token_id_parts = explode( '_', $pieces[2] );

		// Get the meta from database record.
		$booking_data = json_decode( Automator()->db->token->get( 'AMELIA_BOOKING_DATA', $replace_args ), true );

		// Add a check to prevent notice.
		if ( isset( $token_id_parts[0] ) && isset( $token_id_parts[1] ) ) {
			// Example: $booking_data['appointment']['id].
			if ( isset( $booking_data[ $token_id_parts[0] ][ $token_id_parts[1] ] ) ) {
				$value = $booking_data[ $token_id_parts[0] ][ $token_id_parts[1] ];
			}
		}

		return $value;

	}