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

Commit c7b9124

Browse files
authored
Merge pull request #125 from xwp/return-url-fix
Fix return url in customizer.
2 parents 7f02238 + 87e7e74 commit c7b9124

4 files changed

+34
-1
lines changed

js/compat/customize-snapshots.js

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
snapshot.previewLink.attr( 'target', snapshot.data.uuid );
4949
}
5050

51+
snapshot.removeParamFromClose( 'customize_snapshot_uuid' );
52+
5153
api.state( 'snapshot-exists' ).set( false );
5254

5355
// Replace the history state with an updated Customizer URL that does not include the Snapshot UUID.

js/customize-snapshots.js

+29
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@
232232
snapshot.snapshotExpandButton.toggle( ! isPublishStatus );
233233
snapshot.previewLink.toggle( ! isPublishStatus );
234234

235+
if ( isPublishStatus ) {
236+
snapshot.removeParamFromClose( 'customize_changeset_uuid' );
237+
}
238+
235239
snapshot.statusButton.updateButtonText( 'alt-text' );
236240

237241
// Trigger an event for plugins to use.
@@ -1146,6 +1150,31 @@
11461150
snapshot.editBoxAutoSaveTriggered = false;
11471151
}
11481152
} );
1153+
},
1154+
1155+
/**
1156+
* Remove a param from close button link.
1157+
*
1158+
* @param {string} targetParam param.
1159+
* @return {void}.
1160+
*/
1161+
removeParamFromClose: function removeParamFromClose( targetParam ) {
1162+
var closeButton, queryString, updatedParams;
1163+
closeButton = $( '.customize-controls-close' );
1164+
queryString = closeButton.prop( 'search' ).substr( 1 );
1165+
1166+
if ( ! queryString.length ) {
1167+
return;
1168+
}
1169+
1170+
updatedParams = _.filter(
1171+
queryString.split( '&' ),
1172+
function( paramPair ) {
1173+
return 0 !== paramPair.indexOf( targetParam + '=' );
1174+
}
1175+
);
1176+
1177+
closeButton.prop( 'search', updatedParams.join( '&' ) );
11491178
}
11501179
} );
11511180

php/class-customize-snapshot-manager.php

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ public function is_theme_active() {
221221
*/
222222
public function add_snapshot_uuid_to_return_url() {
223223
$should_add_snapshot_uuid = (
224+
isset( $_GET[ $this->get_front_uuid_param() ] )
225+
&&
224226
$this->current_snapshot_uuid
225227
&&
226228
$this->is_theme_active()

tests/php/test-class-customize-snapshot-manager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public function test_is_theme_active() {
387387
public function test_add_snapshot_uuid_to_return_url() {
388388
global $wp_version;
389389
if ( version_compare( $wp_version, '4.4-beta', '>=' ) ) {
390-
$_REQUEST[ $this->front_param ] = self::UUID;
390+
$_GET[ $this->front_param ] = $_REQUEST[ $this->front_param ] = self::UUID;
391391
$manager = $this->get_snapshot_manager_instance( $this->plugin );
392392
$manager->init();
393393
$manager->ensure_customize_manager();

0 commit comments

Comments
 (0)