WP_Customize_Manager::add_state_query_params( string $url ): string
- Since
- 4.7.0
- Source
wp-includes/class-wp-customize-manager.php:1988
Adds customize state query params to a given URL if preview is allowed.
Parameters
$urlstring- URL.
Return
string- URL.
Uses · 7
- wp_parse_url()A wrapper for PHP's parse_url() function that handles consistency in the return values across PHP versions.
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- add_query_arg()Retrieves a modified URL query string.
- WP_Customize_Manager::get_allowed_urls()Gets URLs allowed to be previewed.
- WP_Customize_Manager::changeset_uuid()Gets the changeset UUID.
- WP_Customize_Manager::is_theme_active()Checks if the current theme is active.
- WP_Customize_Manager::get_stylesheet()Retrieves the stylesheet name of the previewed theme.
Source
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'] && str_starts_with( $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; }History
Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/class-wp-customize-manager.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.