Uc_Tokens::parse_uncanny_codes_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|string)


Source Source

File: src/integrations/uncanny-codes/tokens/uc-tokens.php

	public function parse_uncanny_codes_token( $value, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args ) {
		$tokens = array(
			'UNCANNYCODESPREFIX',
			'UNCANNYCODESSUFFIX',
			'UNCANNYCODESBATCH',
			'UNCANNYCODESBATCHEXPIRY',
		);

		if ( $pieces && isset( $pieces[2] ) ) {
			$meta_field = $pieces[2];
			if ( ! empty( $meta_field ) && in_array( $meta_field, $tokens ) ) {
				if ( $trigger_data ) {
					foreach ( $trigger_data as $trigger ) {
						switch ( $meta_field ) {
							case 'UNCANNYCODESBATCHEXPIRY':
								global $wpdb;
								$batch_id         = $trigger['meta']['UNCANNYCODESBATCH'];
								$expiry_date      = $wpdb->get_var( $wpdb->prepare( "SELECT expire_date FROM `{$wpdb->prefix}uncanny_codes_groups` WHERE ID = %d", $batch_id ) );
								$expiry_timestamp = strtotime( $expiry_date );

								// Check if the date is in future to filter out empty dates
								if ( $expiry_timestamp > time() ) {

									// Get the format selected in general WP settings
									$date_format = get_option( 'date_format' );

									// Get the formattted time according to the selected time zone
									$value = date_i18n( $date_format, strtotime( $expiry_date ) );
								}
								break;
							case 'UNCANNYCODESBATCH':
								$value = $trigger['meta']['UNCANNYCODESBATCH_readable'];
								break;
							default:
								$value = isset( $trigger['meta'][ $meta_field ] ) ? $trigger['meta'][ $meta_field ] : '';
								break;
						}
						break;
					}
				}
			}
		}

		return $value;
	}