ACF_Data::switch_sitepublicACF 5.7.11

switch_site

Triggered when switching between sites on a multisite installation.

Method of the class: ACF_Data{}

No Hooks.

Returns

void. Nothing (null).

Usage

$ACF_Data = new ACF_Data();
$ACF_Data->switch_site( $site_id, $prev_site_id );
$site_id(int) (required)
New blog ID.
$prev_site_id(required)
.

Changelog

Since 5.7.11 Introduced.

ACF_Data::switch_site() code ACF 6.8.8

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 ] );
	}
}