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

Commit ee51770

Browse files
committed
Fix snapshot publish issue after settings save
1 parent 7e7e048 commit ee51770

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

php/class-customize-snapshot-manager.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -794,13 +794,13 @@ function( $value ) {
794794
},
795795
$this->customize_manager->unsanitized_post_values()
796796
);
797-
$result = $this->snapshot->set( $settings_data );
797+
$result = $this->snapshot->set( $settings_data, array( 'skip_validation' => true ) );
798798
if ( ! empty( $result['errors'] ) ) {
799799
add_filter( 'customize_save_response', function( $response ) use ( $result, $that ) {
800800
$response['snapshot_errors'] = $that->prepare_errors_for_response( $result['errors'] );
801801
return $response;
802802
} );
803-
return false;
803+
return false; // Todo should remove?
804804
}
805805

806806
if ( ! $this->snapshot->post() || 'publish' !== $this->snapshot->post()->post_status ) {

php/class-customize-snapshot.php

+24-20
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public function status() {
141141
* @throws Exception When $settings_data is not an array of arrays.
142142
*
143143
* @param array $settings_data Settings data, mapping setting IDs to arrays containing `value` and optionally additional params.
144+
* @param array $args extra optional param to tweak.
144145
* @return array {
145146
* Result.
146147
*
@@ -149,7 +150,7 @@ public function status() {
149150
* @type array $validities Setting validities.
150151
* }
151152
*/
152-
public function set( array $settings_data ) {
153+
public function set( array $settings_data, array $args = array() ) {
153154
$error = new \WP_Error();
154155
$result = array(
155156
'errors' => null,
@@ -188,26 +189,29 @@ public function set( array $settings_data ) {
188189
)
189190
);
190191

191-
// Validate.
192-
if ( method_exists( $customize_manager, 'validate_setting_values' ) ) {
193-
$result['validities'] = $customize_manager->validate_setting_values( $unsanitized_values );
194-
} else {
195-
// @codeCoverageIgnoreStart
196-
$result['validities'] = array_map(
197-
function( $sanitized ) {
198-
if ( is_null( $sanitized ) ) {
199-
return new \WP_Error( 'invalid_value', __( 'Invalid value', 'customize-snapshots' ) );
200-
} else {
201-
return true;
202-
}
203-
},
204-
$unsanitized_values
205-
);
206-
// @codeCoverageIgnoreEnd
192+
$invalid_setting_ids = array();
193+
if ( empty( $args['skip_validation'] ) ) {
194+
// Validate.
195+
if ( method_exists( $customize_manager, 'validate_setting_values' ) ) {
196+
$result['validities'] = $customize_manager->validate_setting_values( $unsanitized_values );
197+
} else {
198+
// @codeCoverageIgnoreStart
199+
$result['validities'] = array_map(
200+
function( $sanitized ) {
201+
if ( is_null( $sanitized ) ) {
202+
return new \WP_Error( 'invalid_value', __( 'Invalid value', 'customize-snapshots' ) );
203+
} else {
204+
return true;
205+
}
206+
},
207+
$unsanitized_values
208+
);
209+
// @codeCoverageIgnoreEnd
210+
}
211+
$invalid_setting_ids = array_keys( array_filter( $result['validities'], function( $validity ) {
212+
return is_wp_error( $validity );
213+
} ) );
207214
}
208-
$invalid_setting_ids = array_keys( array_filter( $result['validities'], function( $validity ) {
209-
return is_wp_error( $validity );
210-
} ) );
211215

212216
// Sanitize.
213217
foreach ( $unsanitized_values as $setting_id => $unsanitized_value ) {

0 commit comments

Comments
 (0)