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

Commit 010daf7

Browse files
authored
Merge pull request #89 from xwp/bugfix/snapshot-publish-issue
Fix snapshot publish issue after settings save
2 parents 7e7e048 + c0b4539 commit 010daf7

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

php/class-customize-snapshot-manager.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ 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'] );
@@ -1299,7 +1299,7 @@ public function replace_customize_link( $wp_admin_bar ) {
12991299
return;
13001300
}
13011301

1302-
// Remove customize_snapshot_uuuid query param from url param to be previewed in Customizer.
1302+
// Remove customize_snapshot_uuid query param from url param to be previewed in Customizer.
13031303
$preview_url_query_params = array();
13041304
$preview_url_parsed = wp_parse_url( $customize_node->href );
13051305
parse_str( $preview_url_parsed['query'], $preview_url_query_params );

php/class-customize-snapshot.php

+28-20
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ 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 $options {
145+
* Additional options.
146+
*
147+
* @type bool $skip_validation Whether to skip validation. Optional, defaults to false.
148+
* }
144149
* @return array {
145150
* Result.
146151
*
@@ -149,7 +154,7 @@ public function status() {
149154
* @type array $validities Setting validities.
150155
* }
151156
*/
152-
public function set( array $settings_data ) {
157+
public function set( array $settings_data, array $options = array() ) {
153158
$error = new \WP_Error();
154159
$result = array(
155160
'errors' => null,
@@ -188,26 +193,29 @@ public function set( array $settings_data ) {
188193
)
189194
);
190195

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
196+
$invalid_setting_ids = array();
197+
if ( empty( $options['skip_validation'] ) ) {
198+
// Validate.
199+
if ( method_exists( $customize_manager, 'validate_setting_values' ) ) {
200+
$result['validities'] = $customize_manager->validate_setting_values( $unsanitized_values );
201+
} else {
202+
// @codeCoverageIgnoreStart
203+
$result['validities'] = array_map(
204+
function( $sanitized ) {
205+
if ( is_null( $sanitized ) ) {
206+
return new \WP_Error( 'invalid_value', __( 'Invalid value', 'customize-snapshots' ) );
207+
} else {
208+
return true;
209+
}
210+
},
211+
$unsanitized_values
212+
);
213+
// @codeCoverageIgnoreEnd
214+
}
215+
$invalid_setting_ids = array_keys( array_filter( $result['validities'], function( $validity ) {
216+
return is_wp_error( $validity );
217+
} ) );
207218
}
208-
$invalid_setting_ids = array_keys( array_filter( $result['validities'], function( $validity ) {
209-
return is_wp_error( $validity );
210-
} ) );
211219

212220
// Sanitize.
213221
foreach ( $unsanitized_values as $setting_id => $unsanitized_value ) {

0 commit comments

Comments
 (0)