WP_Customize_Manager::_publish_changeset_values( int $changeset_post_id ): true|WP_Error
- Since
- 4.7.0
- Source
wp-includes/class-wp-customize-manager.php:3479
Description
This will publish the values contained in a changeset, even changesets that do not correspond to current manager instance. This is called by _wp_customize_publish_changeset() when a customize_changeset post is transitioned to the publish status. As such, this method should not be called directly and instead wp_publish_post() should be used.
Please note that if the settings in the changeset are for a non-activated theme, the theme must first be switched to (via switch_theme()) before invoking this method.
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
$changeset_post_idint- ID for customize_changeset post. Defaults to the changeset for the current manager instance.
Return value
true|WP_Error- True or error info.
Performance profile
How much work a call to WP_Customize_Manager::_publish_changeset_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
- 11–94
- Plugin surface
- 2 hooks
- Called by
- 0
Reaches the database via get_post().
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 205.
Third-party callbacks on 'customize_save', 'customize_save_after' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
do_action()called directly - cacheobject cache
wp_cache_delete()one call below WP_Customize_Manager::_publish_changeset_values()
Further down the call graph this can also reach option, serialize 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 · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Customize_Manager::_publish_changeset_values() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
is_wp_error() | 11 | ->get_changeset_post_data(), is_wp_error() |
!is_wp_error() && !did_action() | 82–87 | ->get_changeset_post_data(), is_wp_error(), get_post(), ->unsanitized_post_values(), array_keys(), ->add_dynamic_settings(), do_action(), get_current_user_id(), wp_set_current_user(), did_action(), do_action(), wp_get_post_revisions() |
!is_wp_error() && did_action() | 89–94 | ->get_changeset_post_data(), is_wp_error(), get_post(), ->unsanitized_post_values(), array_keys(), ->add_dynamic_settings(), do_action(), get_current_user_id(), wp_set_current_user(), did_action(), ->get_stylesheet(), ->update_stashed_theme_mod_settings(), do_action(), wp_get_post_revisions() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 205 | 11–94 | 26 | |
| 8.5 | 205 | 11–94 | 26 | |
| 8.4 | 205 | 11–94 | 26 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 208 | 11–94 | 26 | |
| 8.2 | 208 | 11–94 | 26 | |
| 8.1 | 208 | 11–94 | 26 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 209 | 11–94 | 26 |
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.
Hooks and filters fired · 2
2 hooks fire while WP_Customize_Manager::_publish_changeset_values() runs, in this order:
- do_action( customize_save )actionline 3553 (+74 into the body)
Fires once the theme has switched in the Customizer, but before settings have been saved.
- do_action( customize_save_after )actionline 3606 (+127 into the body)
Fires after Customize settings have been saved.
Uses · 16
- is_wp_error()Checks whether the given variable is a WordPress Error.
- get_post()Retrieves post data given a post ID or post object.
- do_action()Calls the callback functions that have been added to an action hook.
- get_current_user_id()Gets the current user's ID.
- wp_set_current_user()Changes the current user by ID or name.
- did_action()Retrieves the number of times an action has been fired during the current request.
- wp_get_post_revisions()Returns all revisions of specified post.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- wp_generate_uuid4()Generates a random UUID (version 4).
- clean_post_cache()Will clean the post in the cache.
- WP_Customize_Manager::get_changeset_post_data()Gets the data stored in a changeset post.
- WP_Customize_Manager::get_stylesheet()Retrieves the stylesheet name of the previewed theme.
Show all 16
- WP_Customize_Manager::unsanitized_post_values()Gets dirty pre-sanitized setting values in the current customized state.
- WP_Customize_Manager::add_dynamic_settings()Registers any dynamically-created settings, such as those from $_POST['customized'] that have no corresponding setting created.
- WP_Customize_Manager::get_setting()Retrieves a customize setting.
- WP_Customize_Manager::update_stashed_theme_mod_settings()Updates stashed theme mod settings.
Source code
public function _publish_changeset_values( $changeset_post_id ) { global $wpdb; $publishing_changeset_data = $this->get_changeset_post_data( $changeset_post_id ); if ( is_wp_error( $publishing_changeset_data ) ) { return $publishing_changeset_data; } $changeset_post = get_post( $changeset_post_id ); /* * Temporarily override the changeset context so that it will be read * in calls to unsanitized_post_values() and so that it will be available * on the $wp_customize object passed to hooks during the save logic. */ $previous_changeset_post_id = $this->_changeset_post_id; $this->_changeset_post_id = $changeset_post_id; $previous_changeset_uuid = $this->_changeset_uuid; $this->_changeset_uuid = $changeset_post->post_name; $previous_changeset_data = $this->_changeset_data; $this->_changeset_data = $publishing_changeset_data; // Parse changeset data to identify theme mod settings and user IDs associated with settings to be saved. $setting_user_ids = array(); $theme_mod_settings = array(); $namespace_pattern = '/^(?P<stylesheet>.+?)::(?P<setting_id>.+)$/'; $matches = array(); foreach ( $this->_changeset_data as $raw_setting_id => $setting_params ) { $actual_setting_id = null; $is_theme_mod_setting = ( isset( $setting_params['value'] ) && isset( $setting_params['type'] ) && 'theme_mod' === $setting_params['type'] && preg_match( $namespace_pattern, $raw_setting_id, $matches ) ); if ( $is_theme_mod_setting ) { if ( ! isset( $theme_mod_settings[ $matches['stylesheet'] ] ) ) { $theme_mod_settings[ $matches['stylesheet'] ] = array(); } $theme_mod_settings[ $matches['stylesheet'] ][ $matches['setting_id'] ] = $setting_params; if ( $this->get_stylesheet() === $matches['stylesheet'] ) { $actual_setting_id = $matches['setting_id']; } } else { $actual_setting_id = $raw_setting_id; } // Keep track of the user IDs for settings actually for this theme. if ( $actual_setting_id && isset( $setting_params['user_id'] ) ) { $setting_user_ids[ $actual_setting_id ] = $setting_params['user_id']; } } $changeset_setting_values = $this->unsanitized_post_values( array( 'exclude_post_data' => true, 'exclude_changeset' => false, ) ); $changeset_setting_ids = array_keys( $changeset_setting_values ); $this->add_dynamic_settings( $changeset_setting_ids ); /** * Fires once the theme has switched in the Customizer, but before settings * have been saved. * * @since 3.4.0 * * @param WP_Customize_Manager $manager WP_Customize_Manager instance. */ do_action( 'customize_save', $this ); /* * Ensure that all settings will allow themselves to be saved. Note that * this is safe because the setting would have checked the capability * when the setting value was written into the changeset. So this is whyChangelog
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.