Tribe__Events__Pro__Editor__Recurrence__Provider::to_classic_format( $event_id )

Format events from block into classic shape for recurrence structure


Parameters

$event_id

(Required)


Top ↑

Return

(bool)


Top ↑

Source

File: src/Tribe/Editor/Recurrence/Provider.php

	public function to_classic_format( $event_id ) {
		/** @var Tribe__Events__Pro__Editor__Meta $meta */
		$meta       = tribe( 'events-pro.editor.meta' );
		/** @var Tribe__Events__Pro__Editor__Recurrence__Blocks_Meta $blocks_meta */
		$blocks_meta = tribe( 'events-pro.editor.recurrence.blocks-meta' );
		$rules      = json_decode( $meta->get_value( $event_id, $blocks_meta->get_rules_key() ), true );
		$exclusions = json_decode( $meta->get_value( $event_id, $blocks_meta->get_exclusions_key() ), true );

		// Don't do anything if the block does not have any data.
		if ( is_null( $rules ) ) {
			return false;
		}

		/** @var Tribe__Events__Pro__Editor__Recurrence__Blocks_Meta $blocks_meta */
		$blocks_meta = tribe( 'events-pro.editor.recurrence.blocks-meta' );
		$data = array(
			'EventStartDate' => get_post_meta( $event_id, '_EventStartDate', true ),
			'EventEndDate'   => get_post_meta( $event_id, '_EventEndDate', true ),
			'recurrence'     => array(
				'rules'      => $this->parse_rules( $rules ),
				'exclusions' => $this->parse_rules( $exclusions ),
				'description'    => get_post_meta( $event_id, $blocks_meta->get_description_key(), true ),
			),
		);
		/**
		 * Use same mechanism as PRO to update the parsed data into the event
		 */
		$meta_builder    = new Tribe__Events__Pro__Recurrence__Meta_Builder( $event_id, $data );
		$recurrence_meta = $meta_builder->build_meta();

		/**
		 * Filters the recurring event save operation.
		 *
		 * Returning a non `null` value in this filter will prevent the normal save operation from going forward.
		 *
		 * @since 4.7
		 *
		 * @param mixed $saved           A boolean to indicate the recurring event save operation was handled, a non `null` value
		 *                               here will make the method bail and stop.
		 * @param array $recurrence_meta The recurrence information.
		 * @param int   $event_id        The post ID of the event recurring information that is being saved.
		 * @param array $data            The complete data, not just the recurrence meta, sent as part of the request.
		 */
		$saved = apply_filters(
			'tribe_events_pro_editor_save_recurrence_meta',
			null,
			$recurrence_meta,
			$event_id,
			$data
		);
		if ( null !== $saved ) {
			return $saved;
		}

		$updated = update_post_meta( $event_id, '_EventRecurrence', $recurrence_meta );

		$events_saver = new Tribe__Events__Pro__Recurrence__Events_Saver( $event_id, $updated );

		return $events_saver->save_events();
	}

Top ↑

Changelog

Changelog
Version Description
4.5 Introduced.