wppaste
WordPress

WP_Customize_Manager::unsanitized_post_values( array $args = array() ): array

Since
4.1.1, 4.7.0
Source
wp-includes/class-wp-customize-manager.php:1759
Gets dirty pre-sanitized setting values in the current customized state.

Description

The returned array consists of a merge of three sources:

  1. If the theme is not currently active, then the base array is any stashed theme mods that were modified previously but never published.
  2. The values from the current changeset, if it exists.
  3. If the user can customize, the values parsed from the incoming $_POST['customized'] JSON data.
  4. Any programmatically-set post values via WP_Customize_Manager::set_post_value().

The name "unsanitized_post_values" is a carry-over from when the customized state was exclusively sourced from $_POST['customized']. Nevertheless, the value returned will come from the current changeset post and from the incoming post data.

Compatibility

WordPress
since 4.7.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$argsarrayoptional
Args.Default: array()
  • $exclude_changesetbool

    Whether the changeset values should also be excluded. Defaults to false.
  • $exclude_post_databool

    Whether the post input values should also be excluded. Defaults to false when lacking the customize capability.

Return value

array

Performance profile

How much work a call to WP_Customize_Manager::unsanitized_post_values() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
21–74

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 105.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
7

7 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionoption read or writeget_option()called directly
  • serializeserialisationjson_decode()called directly
  • hookthird-party callbacksapply_filters()one call below WP_Customize_Manager::unsanitized_post_values()
  • cacheobject cachewp_cache_get()one call below WP_Customize_Manager::unsanitized_post_values()

Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 18 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Customize_Manager::unsanitized_post_values() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
->is_theme_active() && $args21current_user_can(), exclude_changeset(), ->is_theme_active()
->is_theme_active()25–26current_user_can(), exclude_changeset(), ->is_theme_active(), ->changeset_data()
->is_theme_active()29–38current_user_can(), exclude_changeset(), ->is_theme_active(), array_merge()
!->is_theme_active() && !isset($stashed_theme_mods[$stylesheet]) && $args30current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet()
->is_theme_active() && !$args33–43current_user_can(), exclude_changeset(), ->is_theme_active(), ->changeset_data(), array_merge()
!->is_theme_active() && !isset($stashed_theme_mods[$stylesheet])34–35current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), ->changeset_data()
!->is_theme_active() && !isset($stashed_theme_mods[$stylesheet])38–47current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), array_merge()
!->is_theme_active() && isset($stashed_theme_mods[$stylesheet]) && $args41current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), wp_list_pluck(), array_merge()
!->is_theme_active() && !isset($stashed_theme_mods[$stylesheet]) && !$args42–52current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), ->changeset_data(), array_merge()
!->is_theme_active() && isset($stashed_theme_mods[$stylesheet])45–46current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), wp_list_pluck(), array_merge(), ->changeset_data()
->is_theme_active()48–49current_user_can(), exclude_changeset(), ->is_theme_active(), wp_unslash(), json_decode(), array_merge()
!->is_theme_active() && isset($stashed_theme_mods[$stylesheet])49–58current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), wp_list_pluck(), array_merge(), array_merge()
6 further outcomes, up to 74 instructions
->is_theme_active() && !$args52–54current_user_can(), exclude_changeset(), ->is_theme_active(), ->changeset_data(), wp_unslash(), json_decode(), array_merge()
!->is_theme_active() && isset($stashed_theme_mods[$stylesheet]) && !$args53–63current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), wp_list_pluck(), array_merge(), ->changeset_data(), array_merge()
!->is_theme_active() && !isset($stashed_theme_mods[$stylesheet])57–58current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), wp_unslash(), json_decode(), array_merge()
!->is_theme_active() && !isset($stashed_theme_mods[$stylesheet]) && !$args61–63current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), ->changeset_data(), wp_unslash(), json_decode(), array_merge()
!->is_theme_active() && isset($stashed_theme_mods[$stylesheet])68–69current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), wp_list_pluck(), array_merge(), wp_unslash(), json_decode(), array_merge()
!->is_theme_active() && isset($stashed_theme_mods[$stylesheet]) && !$args72–74current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), wp_list_pluck(), array_merge(), ->changeset_data(), wp_unslash(), json_decode(), array_merge()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 105 instructions, 21–74 executed per call, 14 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 7

Used by · 7

Source code

	public function unsanitized_post_values( $args = array() ) {		$args = array_merge(			array(				'exclude_changeset' => false,				'exclude_post_data' => ! current_user_can( 'customize' ),			),			$args		); 		$values = array(); 		// Let default values be from the stashed theme mods if doing a theme switch and if no changeset is present.		if ( ! $this->is_theme_active() ) {			$stashed_theme_mods = get_option( 'customize_stashed_theme_mods' );			$stylesheet         = $this->get_stylesheet();			if ( isset( $stashed_theme_mods[ $stylesheet ] ) ) {				$values = array_merge( $values, wp_list_pluck( $stashed_theme_mods[ $stylesheet ], 'value' ) );			}		} 		if ( ! $args['exclude_changeset'] ) {			foreach ( $this->changeset_data() as $setting_id => $setting_params ) {				if ( ! array_key_exists( 'value', $setting_params ) ) {					continue;				}				if ( isset( $setting_params['type'] ) && 'theme_mod' === $setting_params['type'] ) { 					// Ensure that theme mods values are only used if they were saved under the active theme.					$namespace_pattern = '/^(?P<stylesheet>.+?)::(?P<setting_id>.+)$/';					if ( preg_match( $namespace_pattern, $setting_id, $matches ) && $this->get_stylesheet() === $matches['stylesheet'] ) {						$values[ $matches['setting_id'] ] = $setting_params['value'];					}				} else {					$values[ $setting_id ] = $setting_params['value'];				}			}		} 		if ( ! $args['exclude_post_data'] ) {			if ( ! isset( $this->_post_values ) ) {				if ( isset( $_POST['customized'] ) ) {					$post_values = json_decode( wp_unslash( $_POST['customized'] ), true );				} else {					$post_values = array();				}				if ( is_array( $post_values ) ) {					$this->_post_values = $post_values;				} else {					$this->_post_values = array();				}			}			$values = array_merge( $values, $this->_post_values );		}		return $values;	}

Changelog

Introduced in 4.1.1. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

4.7.0
Added $args parameter and merging with changeset values and stashed theme mods.from the docblock
4.1.1
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 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.