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
Description
The returned array consists of a merge of three sources:
- If the theme is not currently active, then the base array is any stashed theme mods that were modified previously but never published.
- The values from the current changeset, if it exists.
- If the user can customize, the values parsed from the incoming
$_POST['customized']JSON data. - 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_changesetboolWhether the changeset values should also be excluded. Defaults to false.$exclude_post_databoolWhether 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
- Scaling
- Scales with input
- Instructions
- 21–74
- Plugin surface
- None
- Called by
- 7
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 105.
Nothing here hands control to plugin code.
7 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()called directly - serializeserialisation
json_decode()called directly - hookthird-party callbacks
apply_filters()one call below WP_Customize_Manager::unsanitized_post_values() - cacheobject cache
wp_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.
| When | Instructions | Calls it makes |
|---|---|---|
->is_theme_active() && $args | 21 | current_user_can(), exclude_changeset(), ->is_theme_active() |
->is_theme_active() | 25–26 | current_user_can(), exclude_changeset(), ->is_theme_active(), ->changeset_data() |
->is_theme_active() | 29–38 | current_user_can(), exclude_changeset(), ->is_theme_active(), array_merge() |
!->is_theme_active() && !isset($stashed_theme_mods[$stylesheet]) && $args | 30 | current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet() |
->is_theme_active() && !$args | 33–43 | current_user_can(), exclude_changeset(), ->is_theme_active(), ->changeset_data(), array_merge() |
!->is_theme_active() && !isset($stashed_theme_mods[$stylesheet]) | 34–35 | current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), ->changeset_data() |
!->is_theme_active() && !isset($stashed_theme_mods[$stylesheet]) | 38–47 | current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), array_merge() |
!->is_theme_active() && isset($stashed_theme_mods[$stylesheet]) && $args | 41 | current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), wp_list_pluck(), array_merge() |
!->is_theme_active() && !isset($stashed_theme_mods[$stylesheet]) && !$args | 42–52 | current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), ->changeset_data(), array_merge() |
!->is_theme_active() && isset($stashed_theme_mods[$stylesheet]) | 45–46 | current_user_can(), exclude_changeset(), ->is_theme_active(), get_option(), ->get_stylesheet(), wp_list_pluck(), array_merge(), ->changeset_data() |
->is_theme_active() | 48–49 | current_user_can(), exclude_changeset(), ->is_theme_active(), wp_unslash(), json_decode(), array_merge() |
!->is_theme_active() && isset($stashed_theme_mods[$stylesheet]) | 49–58 | current_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() && !$args | 52–54 | current_user_can(), exclude_changeset(), ->is_theme_active(), ->changeset_data(), wp_unslash(), json_decode(), array_merge() |
!->is_theme_active() && isset($stashed_theme_mods[$stylesheet]) && !$args | 53–63 | current_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–58 | current_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]) && !$args | 61–63 | current_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–69 | current_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]) && !$args | 72–74 | current_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
- current_user_can()Returns whether the current user has the specified capability.
- get_option()Retrieves an option value based on an option name.
- wp_list_pluck()Plucks a certain field out of each object or array in an array.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- 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.
- WP_Customize_Manager::changeset_data()Gets changeset data.
Used by · 7
- WP_Customize_Manager::_publish_changeset_values()Publishes the values of a changeset.
- WP_Customize_Manager::customize_pane_settings()Prints JavaScript settings for parent window.
- WP_Customize_Manager::customize_preview_settings()Prints JavaScript settings for preview frame.
- WP_Customize_Manager::post_value()Returns the sanitized value for a given setting from the current customized state.
- WP_Customize_Manager::register_dynamic_settings()Adds settings from the POST data that were not added with code, e.g. dynamically-created settings for Widgets
- WP_Customize_Manager::save_changeset_post()Saves the post for the loaded changeset.
- WP_Customize_Manager::set_post_value()Overrides a setting's value in the current customized state.
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.
Signature, return type and hooks compared across 5 parsed releases.
$args parameter and merging with changeset values and stashed theme mods.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.9.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.