WP_Customize_Manager::add_state_query_params() WordPress Method

The add_state_query_params() method of the WP_Customize_Manager class is used to add query parameters to the current URL when the customizer state changes. The customizer state is a set of values that define the current settings in the customizer. The query parameters that are added to the URL are used to preserve the state of the customizer when the page is reloaded.

WP_Customize_Manager::add_state_query_params( string $url ) #

Adds customize state query params to a given URL if preview is allowed.


Description

Top ↑

See also


Top ↑

Parameters

$url

(string)(Required)URL.


Top ↑

Return

(string) URL.


Top ↑

Source

File: wp-includes/class-wp-customize-manager.php

	public function add_state_query_params( $url ) {
		$parsed_original_url = wp_parse_url( $url );
		$is_allowed          = false;
		foreach ( $this->get_allowed_urls() as $allowed_url ) {
			$parsed_allowed_url = wp_parse_url( $allowed_url );
			$is_allowed         = (
				$parsed_allowed_url['scheme'] === $parsed_original_url['scheme']
				&&
				$parsed_allowed_url['host'] === $parsed_original_url['host']
				&&
				0 === strpos( $parsed_original_url['path'], $parsed_allowed_url['path'] )
			);
			if ( $is_allowed ) {
				break;
			}
		}

		if ( $is_allowed ) {
			$query_params = array(
				'customize_changeset_uuid' => $this->changeset_uuid(),
			);
			if ( ! $this->is_theme_active() ) {
				$query_params['customize_theme'] = $this->get_stylesheet();
			}
			if ( $this->messenger_channel ) {
				$query_params['customize_messenger_channel'] = $this->messenger_channel;
			}
			$url = add_query_arg( $query_params, $url );
		}

		return $url;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More