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

Commit c71add1

Browse files
committed
Add current theme to preview link and enable save button when you switch back to the original theme.
1 parent a372282 commit c71add1

5 files changed

+28
-9
lines changed

js/compat/customize-snapshots.js

+2
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@
272272

273273
if ( api.state( 'activated' ).get() ) {
274274
snapshot.snapshotButton.prop( 'disabled', true );
275+
} else if ( ! api.state( 'activated' ).get() && snapshot.data.themeSaved ) {
276+
snapshot.snapshotButton.prop( 'disabled', true );
275277
}
276278

277279
snapshot.snapshotButton.on( 'click', function( event ) {

js/customize-snapshots.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
initialServerDate: '',
2020
initialServerTimestamp: 0,
2121
initialClientTimestamp: 0,
22+
theme: '',
2223
i18n: {},
2324
dirty: false
2425
},
@@ -106,16 +107,19 @@
106107
* @return {{}} Query vars for scroll, device, url, and autofocus.
107108
*/
108109
getStateQueryVars: function() {
109-
var queryVars = {
110+
var snapshot = this, currentTheme, queryVars;
111+
112+
queryVars = {
110113
'autofocus[control]': null,
111114
'autofocus[section]': null,
112115
'autofocus[panel]': null
113116
};
117+
currentTheme = api.settings.theme.stylesheet;
114118
queryVars.scroll = parseInt( api.previewer.scroll, 10 ) || 0;
115119
queryVars.device = api.previewedDevice.get();
116120
queryVars.url = api.previewer.previewUrl.get();
117121

118-
if ( ! api.state( 'activated' ).get() ) {
122+
if ( ! api.state( 'activated' ).get() || snapshot.data.theme !== currentTheme ) {
119123
queryVars.previewingTheme = true;
120124
}
121125

@@ -309,8 +313,10 @@
309313
* @return {void}
310314
*/
311315
addButtons: function addButtons() {
312-
var snapshot = this, setPreviewLinkHref, disableButton = true;
316+
var snapshot = this, disableButton = true,
317+
setPreviewLinkHref, currentTheme;
313318

319+
currentTheme = api.settings.theme.stylesheet;
314320
snapshot.spinner = $( '#customize-header-actions' ).find( '.spinner' );
315321
snapshot.publishButton = $( '#save' );
316322

@@ -325,7 +331,7 @@
325331
}
326332
}
327333

328-
if ( ! api.state( 'activated' ).get() ) {
334+
if ( ! api.state( 'activated' ).get() || snapshot.data.theme !== currentTheme ) {
329335
disableButton = false;
330336
}
331337

php/class-customize-snapshot-manager-back-compat.php

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public function enqueue_controls_scripts() {
9191
if ( $this->snapshot ) {
9292
$post = $this->snapshot->post();
9393
$this->override_post_date_default_data( $post );
94+
$preview_url_query_vars = $this->post_type->get_customizer_state_query_vars( $post->ID );
9495
}
9596

9697
// Script data array.
@@ -104,6 +105,8 @@ public function enqueue_controls_scripts() {
104105
'currentUserCanPublish' => current_user_can( 'customize_publish' ),
105106
'initialServerDate' => current_time( 'mysql', false ),
106107
'initialServerTimestamp' => floor( microtime( true ) * 1000 ),
108+
'theme' => $this->original_stylesheet,
109+
'themeSaved' => isset( $preview_url_query_vars['theme'] ),
107110
'i18n' => array(
108111
'saveButton' => __( 'Save', 'customize-snapshots' ),
109112
'updateButton' => __( 'Update', 'customize-snapshots' ),

php/class-customize-snapshot-manager.php

+2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ public function enqueue_controls_scripts() {
281281
$this->override_post_date_default_data( $post );
282282
$edit_link = $this->snapshot->get_edit_link( $post );
283283
}
284+
$preview_url_query_vars = $this->post_type->get_customizer_state_query_vars( $post_id );
284285
}
285286

286287
// Script data array.
@@ -292,6 +293,7 @@ public function enqueue_controls_scripts() {
292293
'currentUserCanPublish' => current_user_can( 'customize_publish' ),
293294
'initialServerDate' => current_time( 'mysql', false ),
294295
'initialServerTimestamp' => floor( microtime( true ) * 1000 ),
296+
'theme' => isset( $preview_url_query_vars['theme'] ) ? $preview_url_query_vars['theme'] : $this->original_stylesheet,
295297
'i18n' => array(
296298
'saveButton' => __( 'Save', 'customize-snapshots' ),
297299
'updateButton' => __( 'Update', 'customize-snapshots' ),

php/class-post-type.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -920,11 +920,17 @@ public function get_frontend_view_link( $post ) {
920920
$post = get_post( $post );
921921
$preview_url_query_vars = $this->get_customizer_state_query_vars( $post->ID );
922922
$base_url = isset( $preview_url_query_vars['url'] ) ? $preview_url_query_vars['url'] : home_url( '/' );
923-
return add_query_arg(
924-
array(
925-
static::FRONT_UUID_PARAM_NAME => $post->post_name,
926-
),
927-
$base_url
923+
$current_theme = get_stylesheet();
924+
$args = array(
925+
static::FRONT_UUID_PARAM_NAME => $post->post_name,
928926
);
927+
928+
if ( isset( $preview_url_query_vars['theme'] ) && $current_theme !== $preview_url_query_vars['theme'] ) {
929+
$args = array_merge( $args, array(
930+
'theme' => $preview_url_query_vars['theme'],
931+
) );
932+
}
933+
934+
return add_query_arg( $args, $base_url );
929935
}
930936
}

0 commit comments

Comments
 (0)