Tribe__Process__Queue::dispatch()

Overrides the base dispatch method to allow for constants and/or environment vars to run async requests in sync mode.


Return

(mixed)


Top ↑

Source

File: src/Tribe/Process/Queue.php

	public function dispatch() {
		if (
			( defined( 'TRIBE_NO_ASYNC' ) && true === TRIBE_NO_ASYNC )
			|| true == getenv( 'TRIBE_NO_ASYNC' )
			|| (bool) tribe_get_request_var( 'tribe_queue_sync', false )
			|| tribe_is_truthy( tribe_get_option( 'tribe_queue_sync', false ) )
		) {
			$result = $this->sync_process( $this->data );
			$this->complete();

			return $result;
		}

		if ( $this->feature_detection->supports_async_process() ) {
			return parent::dispatch();
		}

		/*
		 * If async AJAX-based processing is not available then we "dispatch"
		 * by scheduling a single cron event immediately (as soon as possible)
		 * for this handler cron identifier.
		 */
		if ( ! wp_next_scheduled( $this->identifier ) ) {
			// Schedule the event to happen as soon as possible.
			$scheduled = wp_schedule_single_event( time() - 1, $this->identifier );

			if ( false === $scheduled ) {
				/** @var Tribe__Log__Logger $logger */
				$logger = tribe( 'logger' );
				$class  = get_class( $this );
				$src    = call_user_func( array( $class, 'action' ) );
				$logger->log( 'Could not schedule event for cron-based processing', Tribe__Log::ERROR, $src );
			}
		}

		return true;
	}

Top ↑

Changelog

Changelog
Version Description
4.9.5 Pulled method code from the WP_Background_Process class.
4.7.12 Introduced.