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 #125 from xwp/return-url-fix
Browse files Browse the repository at this point in the history
Fix return url in customizer.
  • Loading branch information
westonruter authored Mar 10, 2017
2 parents 7f02238 + 87e7e74 commit c7b9124
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions js/compat/customize-snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
snapshot.previewLink.attr( 'target', snapshot.data.uuid );
}

snapshot.removeParamFromClose( 'customize_snapshot_uuid' );

api.state( 'snapshot-exists' ).set( false );

// Replace the history state with an updated Customizer URL that does not include the Snapshot UUID.
Expand Down
29 changes: 29 additions & 0 deletions js/customize-snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@
snapshot.snapshotExpandButton.toggle( ! isPublishStatus );
snapshot.previewLink.toggle( ! isPublishStatus );

if ( isPublishStatus ) {
snapshot.removeParamFromClose( 'customize_changeset_uuid' );
}

snapshot.statusButton.updateButtonText( 'alt-text' );

// Trigger an event for plugins to use.
Expand Down Expand Up @@ -1146,6 +1150,31 @@
snapshot.editBoxAutoSaveTriggered = false;
}
} );
},

/**
* Remove a param from close button link.
*
* @param {string} targetParam param.
* @return {void}.
*/
removeParamFromClose: function removeParamFromClose( targetParam ) {
var closeButton, queryString, updatedParams;
closeButton = $( '.customize-controls-close' );
queryString = closeButton.prop( 'search' ).substr( 1 );

if ( ! queryString.length ) {
return;
}

updatedParams = _.filter(
queryString.split( '&' ),
function( paramPair ) {
return 0 !== paramPair.indexOf( targetParam + '=' );
}
);

closeButton.prop( 'search', updatedParams.join( '&' ) );
}
} );

Expand Down
2 changes: 2 additions & 0 deletions php/class-customize-snapshot-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ public function is_theme_active() {
*/
public function add_snapshot_uuid_to_return_url() {
$should_add_snapshot_uuid = (
isset( $_GET[ $this->get_front_uuid_param() ] )
&&
$this->current_snapshot_uuid
&&
$this->is_theme_active()
Expand Down
2 changes: 1 addition & 1 deletion tests/php/test-class-customize-snapshot-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public function test_is_theme_active() {
public function test_add_snapshot_uuid_to_return_url() {
global $wp_version;
if ( version_compare( $wp_version, '4.4-beta', '>=' ) ) {
$_REQUEST[ $this->front_param ] = self::UUID;
$_GET[ $this->front_param ] = $_REQUEST[ $this->front_param ] = self::UUID;
$manager = $this->get_snapshot_manager_instance( $this->plugin );
$manager->init();
$manager->ensure_customize_manager();
Expand Down

0 comments on commit c7b9124

Please sign in to comment.