WordPress at Your Fingertips
function is not described

WP_Customize_Manager::add_state_query_params() public WP 4.7.0

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

{} It's a method of the class: WP_Customize_Manager{}

No Hooks.

Return

String. URL.

Usage

$WP_Customize_Manager = new WP_Customize_Manager();
$WP_Customize_Manager->add_state_query_params( $url );
$url(string) (required)
URL.

Notes

  • See: wp_redirect()
  • See: WP_Customize_Manager::get_allowed_url()

Changelog

Since 4.7.0 Introduced.

Code of WP_Customize_Manager::add_state_query_params() WP 5.8.2

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