Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #127 from xwp/bugfix/populate-customized-state-early
Browse files Browse the repository at this point in the history
Populate back-compat customized state up front for parity with changesets
  • Loading branch information
westonruter committed Mar 3, 2017
2 parents d0b5767 + efd1bdf commit 5e15e85
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions php/class-customize-snapshot-manager-back-compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,14 @@ public function save_settings_with_publish_snapshot( $new_status, $old_status, $
return false;
}

// Populate customized state with values from snapshot.
$snapshot_content = $this->post_type->get_post_content( $post );
foreach ( $snapshot_content as $setting_id => $setting_params ) {
if ( array_key_exists( 'value', $setting_params ) ) {
$this->customize_manager->set_post_value( $setting_id, $setting_params['value'] );
}
}

if ( ! did_action( 'customize_register' ) ) {
/*
* When running from CLI or Cron, we have to remove the action because
Expand Down Expand Up @@ -676,7 +684,6 @@ public function save_settings_with_publish_snapshot( $new_status, $old_status, $
// undefine( 'DOING_AJAX' )... just kidding. This is the end of the unfortunate hack and it should be fixed in Core.
unset( $_REQUEST['action'] );
}
$snapshot_content = $this->post_type->get_post_content( $post );

if ( method_exists( $this->customize_manager, 'validate_setting_values' ) ) {
/** This action is documented in wp-includes/class-wp-customize-manager.php */
Expand All @@ -703,7 +710,9 @@ public function save_settings_with_publish_snapshot( $new_status, $old_status, $
if ( ! isset( $setting_params['value'] ) || is_null( $setting_params['value'] ) ) {
if ( ! is_array( $setting_params ) ) {
if ( ! empty( $setting_params ) ) {
$setting_params = array( 'value' => $setting_params );
$setting_params = array(
'value' => $setting_params,
);
} else {
$setting_params = array();
}
Expand All @@ -714,7 +723,6 @@ public function save_settings_with_publish_snapshot( $new_status, $old_status, $
}

// Unrecognized setting error.
$this->customize_manager->set_post_value( $setting_id, $setting_params['value'] );
$setting = $this->customize_manager->get_setting( $setting_id );
if ( ! ( $setting instanceof \WP_Customize_Setting ) ) {
$setting_params['publish_error'] = 'unrecognized_setting';
Expand Down

0 comments on commit 5e15e85

Please sign in to comment.