Tribe__Events__Pro__Service_Providers__RBE::set_in_use( string|null $in_use = null )

Sets the engine currently in use.

The method will update the value of the rbe_engine Tribe option.


Parameters

$in_use

(string|null) (Optional) Either the string representing an engine or null if no engine is in use.

Default value: null


Top ↑

Return

(string) The slug of the engine in use.


Top ↑

Source

File: src/Tribe/Service_Providers/RBE.php

	public function set_in_use( $in_use = null ) {
		$engines_map      = $this->get_engines_map();
		$currently_in_use = $this->get_in_use();

		if ( ! array_key_exists( $in_use, $engines_map ) || $currently_in_use === $in_use ) {
			// Let's not change to an engine that does not exist.
			return $currently_in_use;
		}

		$current = $engines_map[ $this->get_in_use() ];
		$current = $current instanceof Tribe__Events__Pro__Recurrence__Engines__Engine_Interface
			? $current
			: $this->container->make( $current );

		$unhooked = $current->unhook();

		if ( false === $unhooked ) {
			// For some reasons the current engine cannot be unhooked, return its slug.
			return $current->get_slug();
		}

		try {
			$engine = $engines_map[ $in_use ];
			$engine = $engine instanceof Tribe__Events__Pro__Recurrence__Engines__Engine_Interface
				? $engine
				: $this->container->make( $engine );
			$hooked = $engine->hook();
		} catch ( Exception $e ) {
			// Something went wrong; let's hook none.
			tribe_update_option( self::OPTION_NAME, self::NONE );

			return self::NONE;
		}

		$now_in_use = empty( $hooked ) ? self::NONE : $engine->get_slug();
		tribe_update_option( self::OPTION_NAME, $now_in_use );

		return $now_in_use;
	}

Top ↑

Changelog

Changelog
Version Description
4.7 Introduced.