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

Enable status button if current theme is not active. #132

Merged
merged 15 commits into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions php/class-customize-snapshot-manager-back-compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,14 @@ public function filter_customize_refresh_nonces( $nonces ) {
* @global \WP_Customize_Manager $wp_customize
*/
public function enqueue_controls_scripts() {

// Prevent loading the Snapshot interface if the theme is not active.
if ( ! $this->is_theme_active() ) {
return;
}
$this->ensure_customize_manager();

wp_enqueue_style( 'customize-snapshots' );
wp_enqueue_script( 'customize-snapshots-compat' );

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 @@ -106,7 +101,7 @@ public function enqueue_controls_scripts() {
'initialServerDate' => current_time( 'mysql', false ),
'initialServerTimestamp' => floor( microtime( true ) * 1000 ),
'theme' => $this->original_stylesheet,
'previewingTheme' => isset( $preview_url_query_vars['theme'] ) ? $preview_url_query_vars['theme']: '',
'previewingTheme' => ! $this->customize_manager->is_theme_active(),
Copy link
Contributor Author

@mohdsayed mohdsayed Mar 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter This is breaking my condition here

snapshot.isNotSavedPreviewingTheme = savedPreviewingTheme && savedPreviewingTheme !== currentTheme;

There are several use cases where the button has to be enabled or disabled.

  1. When they switch theme ( Has to enable ) ( Working )
  2. After saving the previewing theme, reload the page, ( Has to disable ) ( Not working now )
  3. After saving the previewing theme they switch to a third theme ( Has to enable ) ( Working )
  4. After travelling through the themes and saving the last one, they come back to the original theme ( Should be enable ) ( Not working now ).

I was not able to satisfy these conditions with only boolean value of previewingTheme . This is as good as api.state( 'activated' ).get()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. So this can be fixed by reverting back to:

'previewingTheme' => isset( $preview_url_query_vars['theme'] ) ? $preview_url_query_vars['theme'] : '',

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

'i18n' => array(
'saveButton' => __( 'Save', 'customize-snapshots' ),
'updateButton' => __( 'Update', 'customize-snapshots' ),
Expand Down
12 changes: 4 additions & 8 deletions php/class-customize-snapshot-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public function ensure_customize_manager() {
*
* @return bool Whether theme is active.
*
* @deprecated in favor of WP_Customize_Manager::is_theme_active()
* @todo move to back compat?
*/
public function is_theme_active() {
Expand All @@ -225,7 +226,7 @@ public function add_snapshot_uuid_to_return_url() {
&&
$this->current_snapshot_uuid
&&
$this->is_theme_active()
$this->customize_manager->is_theme_active()
&&
Copy link
Contributor Author

@mohdsayed mohdsayed Mar 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter Not sure why $this->customize_manager->is_theme_active() is returning false in 4.6.1 which is failing phpunit test. I mean inside phpunit test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because the setup_theme action wasn't triggered in the test case, and so \WP_Customize_Manager::$original_stylesheet didn't get set. In 4.7 this variable gets set in \WP_Customize_Manager::__construct() whereas in 4.6 it got set in \WP_Customize_Manager::setup_theme().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed in 52694b6.

false === strpos( $this->customize_manager->get_return_url(), '/wp-admin/' )
);
Expand Down Expand Up @@ -263,11 +264,7 @@ static public function encode_json( $value ) {
* @global \WP_Customize_Manager $wp_customize
*/
public function enqueue_controls_scripts() {

// Prevent loading the Snapshot interface if the theme is not active.
if ( ! $this->is_theme_active() ) {
return;
}
$this->ensure_customize_manager();

wp_enqueue_style( 'customize-snapshots' );
wp_enqueue_script( 'customize-snapshots' );
Expand All @@ -281,7 +278,6 @@ 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 @@ -293,7 +289,7 @@ public function enqueue_controls_scripts() {
'currentUserCanPublish' => current_user_can( 'customize_publish' ),
'initialServerDate' => current_time( 'mysql', false ),
'initialServerTimestamp' => floor( microtime( true ) * 1000 ),
'previewingTheme' => isset( $preview_url_query_vars['theme'] ) ? $preview_url_query_vars['theme']: '',
'previewingTheme' => ! $this->customize_manager->is_theme_active(),
'i18n' => array(
'saveButton' => __( 'Save', 'customize-snapshots' ),
'updateButton' => __( 'Update', 'customize-snapshots' ),
Expand Down