Tribe__Tickets__Editor::flush_blocks()

Function called by load-post.php action when the editor screen is loaded, insert a new meta field value as a flag into the post / event if the classic editor is displayed and has blocks in case it has blocks to trigger a new action tribe_tickets_update_blocks_from_classic_editor


Return

(bool)


Top ↑

Source

File: src/Tribe/Editor.php

	public function flush_blocks() {
		// Bail because we dont have access to any of the classes we need for Blocks Editor
		if ( ! tribe( 'editor' )->should_load_blocks() ) {
			return false;
		}

		$post_id = absint( tribe_get_request_var( 'post' ) );

		if (
			empty( $post_id )
			|| ! is_numeric( $post_id )
			|| ! tribe_events_has_tickets( $post_id )
		) {
			return false;
		}

		/** @var Tribe__Tickets__Editor__Template__Overwrite $template_overwrite */
		$template_overwrite = tribe( 'tickets.editor.template.overwrite' );

		$is_event                 = function_exists( 'tribe_is_event' ) && tribe_is_event( $post_id );
		$has_event_classic_editor = $is_event && ! $template_overwrite->has_early_access_to_blocks();

		/** @var Tribe__Editor $editor */
		$editor = tribe( 'editor' );

		// Set meta key only if is classic editor and bail
		if ( $editor->is_classic_editor() || $has_event_classic_editor ) {
			update_post_meta( $post_id, $this->meta_key_flush_flag, 1 );

			return false;
		}

		/**
		 * Don't process the first time a post is converted into blocks which means has_blocks, will
		 * return false the first time this is called in the post as the conversion from classic into
		 * blocks has not done yet, as this is process by 'tribe_blocks_editor_flag_post_classic_editor'
		 * so we only care if we already have blocks so we can search and remove old tickets blocks to
		 * replace with the new schema of tickets.
		 */
		if ( ! has_blocks( $post_id ) ) {
			return false;
		}

		$has_meta_flush = metadata_exists( 'post', $post_id, $this->meta_key_flush_flag );
		if ( $has_meta_flush ) {
			/**
			 * Fire an action to update the blocks associated with a post
			 *
			 * @since 4.9.2
			 */
			do_action( 'tribe_tickets_update_blocks_from_classic_editor', $post_id );

			return delete_post_meta( $post_id, $this->meta_key_flush_flag );
		}

		return false;
	}

Top ↑

Changelog

Changelog
Version Description
4.9.2 Introduced.