wppaste
WordPress

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:3480
Publishes the values of a changeset.

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

Reaches the database via get_post().

Scaling
Scales with input

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

Instructions
11–94

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

Plugin surface
2 hooks

Third-party callbacks on 'customize_save', 'customize_save_after' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksdo_action()called directly
  • cacheobject cachewp_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.

WhenInstructionsCalls 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

PHPCompiledExecutedBranchesNotes
8.6-dev20511–9426
8.520511–9426
8.420511–94263 fewer instructions than PHP 8.3
8.320811–9426
8.220811–9426
8.120811–94261 fewer instruction than PHP 7.4
7.420911–9426

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:

  1. do_action( customize_save )actionline 3554 (+74 into the body)

    Fires once the theme has switched in the Customizer, but before settings have been saved.

  2. do_action( customize_save_after )actionline 3607 (+127 into the body)

    Fires after Customize settings have been saved.

Uses · 16

Show all 16

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 why

Changelog

Introduced in 4.7.0. 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.

About this page

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