ACF_Data::switch_site()publicACF 5.7.11

switch_site

Triggered when switching between sites on a multisite installation.

{} Это метод класса: ACF_Data{}

Хуков нет.

Возвращает

null. Ничего.

Использование

$ACF_Data = new ACF_Data();
$ACF_Data->switch_site( $site_id, $prev_site_id );
$site_id(int) (обязательный)
New blog ID.
$prev_site_id (обязательный)
-

Список изменений

С версии 5.7.11 Введена.

Код ACF_Data::switch_site() ACF 5.10.2

function switch_site( $site_id, $prev_site_id ) {

	// Bail early if not multisite compatible.
	if ( ! $this->multisite ) {
		return;
	}

	// Bail early if no change in blog ID.
	if ( $site_id === $prev_site_id ) {
		return;
	}

	// Create storage.
	if ( ! isset( $this->site_data ) ) {
		$this->site_data    = array();
		$this->site_aliases = array();
	}

	// Save state.
	$this->site_data[ $prev_site_id ]    = $this->data;
	$this->site_aliases[ $prev_site_id ] = $this->aliases;

	// Reset state.
	$this->data    = array();
	$this->aliases = array();

	// Load state.
	if ( isset( $this->site_data[ $site_id ] ) ) {
		$this->data    = $this->site_data[ $site_id ];
		$this->aliases = $this->site_aliases[ $site_id ];
		unset( $this->site_data[ $site_id ] );
		unset( $this->site_aliases[ $site_id ] );
	}
}