Mec_Event_Tokens::replace_values( $value,  $pieces,  $recipe_id,  $trigger_data,  $user_id,  $replace_args )

Replaces the token values.


Return Return

(mixed) The value.


Source Source

File: src/integrations/modern-events-calendar/tokens/mec-event-tokens.php

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



		$trigger_meta = $pieces[1];
		$parse        = $pieces[2];

		$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 ) {
			return $value;
		}

		foreach ( $trigger_data as $trigger ) {

			if ( ! isset( $trigger['meta'] ) ) {
				continue;
			}

			if ( ! key_exists( $trigger_meta, $trigger['meta'] ) && ( ! isset( $trigger['meta']['code'] ) && $trigger_meta !== $trigger['meta']['code'] ) ) {
				continue;
			}

			$trigger_id     = $trigger['ID'];
			$trigger_log_id = $replace_args['trigger_log_id'];

			$event_id = $this->get_event_id_from_trigger_log_meta(
				$user_id,
				'MEC_EVENT_ID',
				$replace_args['trigger_id'],
				$replace_args['trigger_log_id']
			);

			if ( empty( $event_id ) ) {
				return;
			}

			$the_event = new MEC_EVENT_HELPERS();
			$the_event->setup( $event_id );

			$value = '';

			switch ( $parse ) {

				case $this->token . 'EVENT_DATE':
					$value = $the_event->get_event_date();
					break;
				case $this->token . 'EVENT_TIME':
					$value = $the_event->get_event_time();
					break;
				case $this->token . 'EVENT_LOCATION':
					$value = $the_event->get_event_location();
					break;
				case $this->token . 'EVENT_ORGANIZER':
					$value = $the_event->get_event_organizer();
					break;
				case $this->token . 'EVENT_COST':
					$value = $the_event->get_event_cost();
					break;
			}
		}

		return $value;

	}