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

Commit

Permalink
Add current theme to preview link and enable save button when you swi…
Browse files Browse the repository at this point in the history
…tch back to the original theme.
  • Loading branch information
mohdsayed committed Mar 13, 2017
1 parent a372282 commit c71add1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
2 changes: 2 additions & 0 deletions js/compat/customize-snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@

if ( api.state( 'activated' ).get() ) {
snapshot.snapshotButton.prop( 'disabled', true );
} else if ( ! api.state( 'activated' ).get() && snapshot.data.themeSaved ) {
snapshot.snapshotButton.prop( 'disabled', true );
}

snapshot.snapshotButton.on( 'click', function( event ) {
Expand Down
14 changes: 10 additions & 4 deletions js/customize-snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
initialServerDate: '',
initialServerTimestamp: 0,
initialClientTimestamp: 0,
theme: '',
i18n: {},
dirty: false
},
Expand Down Expand Up @@ -106,16 +107,19 @@
* @return {{}} Query vars for scroll, device, url, and autofocus.
*/
getStateQueryVars: function() {
var queryVars = {
var snapshot = this, currentTheme, queryVars;

queryVars = {
'autofocus[control]': null,
'autofocus[section]': null,
'autofocus[panel]': null
};
currentTheme = api.settings.theme.stylesheet;
queryVars.scroll = parseInt( api.previewer.scroll, 10 ) || 0;
queryVars.device = api.previewedDevice.get();
queryVars.url = api.previewer.previewUrl.get();

if ( ! api.state( 'activated' ).get() ) {
if ( ! api.state( 'activated' ).get() || snapshot.data.theme !== currentTheme ) {
queryVars.previewingTheme = true;
}

Expand Down Expand Up @@ -309,8 +313,10 @@
* @return {void}
*/
addButtons: function addButtons() {
var snapshot = this, setPreviewLinkHref, disableButton = true;
var snapshot = this, disableButton = true,
setPreviewLinkHref, currentTheme;

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

Expand All @@ -325,7 +331,7 @@
}
}

if ( ! api.state( 'activated' ).get() ) {
if ( ! api.state( 'activated' ).get() || snapshot.data.theme !== currentTheme ) {
disableButton = false;
}

Expand Down
3 changes: 3 additions & 0 deletions php/class-customize-snapshot-manager-back-compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function enqueue_controls_scripts() {
if ( $this->snapshot ) {
$post = $this->snapshot->post();
$this->override_post_date_default_data( $post );
$preview_url_query_vars = $this->post_type->get_customizer_state_query_vars( $post->ID );
}

// Script data array.
Expand All @@ -104,6 +105,8 @@ public function enqueue_controls_scripts() {
'currentUserCanPublish' => current_user_can( 'customize_publish' ),
'initialServerDate' => current_time( 'mysql', false ),
'initialServerTimestamp' => floor( microtime( true ) * 1000 ),
'theme' => $this->original_stylesheet,
'themeSaved' => isset( $preview_url_query_vars['theme'] ),
'i18n' => array(
'saveButton' => __( 'Save', 'customize-snapshots' ),
'updateButton' => __( 'Update', 'customize-snapshots' ),
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 @@ -281,6 +281,7 @@ public function enqueue_controls_scripts() {
$this->override_post_date_default_data( $post );
$edit_link = $this->snapshot->get_edit_link( $post );
}
$preview_url_query_vars = $this->post_type->get_customizer_state_query_vars( $post_id );
}

// Script data array.
Expand All @@ -292,6 +293,7 @@ public function enqueue_controls_scripts() {
'currentUserCanPublish' => current_user_can( 'customize_publish' ),
'initialServerDate' => current_time( 'mysql', false ),
'initialServerTimestamp' => floor( microtime( true ) * 1000 ),
'theme' => isset( $preview_url_query_vars['theme'] ) ? $preview_url_query_vars['theme'] : $this->original_stylesheet,
'i18n' => array(
'saveButton' => __( 'Save', 'customize-snapshots' ),
'updateButton' => __( 'Update', 'customize-snapshots' ),
Expand Down
16 changes: 11 additions & 5 deletions php/class-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,11 +920,17 @@ public function get_frontend_view_link( $post ) {
$post = get_post( $post );
$preview_url_query_vars = $this->get_customizer_state_query_vars( $post->ID );
$base_url = isset( $preview_url_query_vars['url'] ) ? $preview_url_query_vars['url'] : home_url( '/' );
return add_query_arg(
array(
static::FRONT_UUID_PARAM_NAME => $post->post_name,
),
$base_url
$current_theme = get_stylesheet();
$args = array(
static::FRONT_UUID_PARAM_NAME => $post->post_name,
);

if ( isset( $preview_url_query_vars['theme'] ) && $current_theme !== $preview_url_query_vars['theme'] ) {
$args = array_merge( $args, array(
'theme' => $preview_url_query_vars['theme'],
) );
}

return add_query_arg( $args, $base_url );
}
}

0 comments on commit c71add1

Please sign in to comment.