summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/sync/class.jetpack-sync-module-themes.php')
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-themes.php82
1 files changed, 66 insertions, 16 deletions
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-themes.php b/plugins/jetpack/sync/class.jetpack-sync-module-themes.php
index e36743fd..2fbb810f 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-themes.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-themes.php
@@ -12,7 +12,7 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
add_action( 'jetpack_installed_theme', $callable, 10, 2 );
add_action( 'jetpack_updated_theme', $callable, 10, 2 );
add_action( 'delete_site_transient_update_themes', array( $this, 'detect_theme_deletion') );
- add_action( 'jetpack_deleted_theme', $callable );
+ add_action( 'jetpack_deleted_theme', $callable, 10, 2 );
add_filter( 'wp_redirect', array( $this, 'detect_theme_edit' ) );
add_action( 'jetpack_edited_theme', $callable, 10, 2 );
add_action( 'update_site_option_allowedthemes', array( $this, 'sync_network_allowed_themes_change' ), 10, 4 );
@@ -32,6 +32,10 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
}
public function sync_widget_edit( $instance, $new_instance, $old_instance, $widget_object ) {
+ if ( empty( $old_instance ) ) {
+ return $instance;
+ }
+
$widget = array(
'name' => $widget_object->name,
'id' => $widget_object->id,
@@ -41,7 +45,7 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
*
* @since 5.0.0
*
- * @param string $widget_name, Name of edited widget
+ * @param string $widget_name , Name of edited widget
*/
do_action( 'jetpack_widget_edited', $widget );
@@ -52,6 +56,13 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
$all_enabled_theme_slugs = array_keys( $value );
if ( count( $old_value ) > count( $value ) ) {
+
+ //Suppress jetpack_network_disabled_themes sync action when theme is deleted
+ $delete_theme_call = $this->get_delete_theme_call();
+ if ( ! empty( $delete_theme_call ) ) {
+ return;
+ }
+
$newly_disabled_theme_names = array_keys( array_diff_key( $old_value, $value ) );
$newly_disabled_themes = $this->get_theme_details_for_slugs( $newly_disabled_theme_names );
/**
@@ -132,19 +143,19 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
}
public function detect_theme_deletion() {
- $backtrace = debug_backtrace();
- $delete_theme_call = null;
- foreach ( $backtrace as $call ) {
- if ( isset( $call['function'] ) && 'delete_theme' === $call['function'] ) {
- $delete_theme_call = $call;
- break;
- }
- }
+ $delete_theme_call = $this->get_delete_theme_call();
if ( empty( $delete_theme_call ) ) {
return;
}
$slug = $delete_theme_call['args'][0];
+ $theme = wp_get_theme( $slug );
+ $theme_data = array(
+ 'name' => $theme->get('Name'),
+ 'version' => $theme->get('Version'),
+ 'uri' => $theme->get( 'ThemeURI' ),
+ 'slug' => $slug,
+ );
/**
* Signals to the sync listener that a theme was deleted and a sync action
@@ -153,8 +164,9 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
* @since 5.0.0
*
* @param string $slug Theme slug
+ * @param array $theme_data Theme info Since 5.3
*/
- do_action( 'jetpack_deleted_theme', $slug );
+ do_action( 'jetpack_deleted_theme', $slug, $theme_data );
}
public function check_upgrader( $upgrader, $details) {
@@ -264,6 +276,11 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
$moved_to_sidebar = array();
$sidebar_name = $this->get_sidebar_name( $sidebar );
+ //Don't sync jetpack_widget_added if theme was switched
+ if ( $this->is_theme_switch() ) {
+ return array();
+ }
+
foreach ( $added_widgets as $added_widget ) {
$moved_to_sidebar[] = $added_widget;
$added_widget_name = $this->get_widget_name( $added_widget );
@@ -342,13 +359,12 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
}
function sync_sidebar_widgets_actions( $old_value, $new_value ) {
-
// Don't really know how to deal with different array_values yet.
if ( $old_value['array_version'] !== 3 || $new_value['array_version'] !== 3 ) {
return;
}
- $moved_to_inactive = array();
+ $moved_to_inactive_ids = array();
$moved_to_sidebar = array();
foreach ( $new_value as $sidebar => $new_widgets ) {
@@ -359,8 +375,12 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
? $old_value[ $sidebar ]
: array();
+ if ( ! is_array( $new_widgets ) ) {
+ $new_widgets = array();
+ }
+
$moved_to_inactive_recently = $this->sync_remove_widgets_from_sidebar( $new_widgets, $old_widgets, $sidebar, $new_value['wp_inactive_widgets'] );
- $moved_to_inactive_ids = array_merge( $moved_to_inactive, $moved_to_inactive_recently );
+ $moved_to_inactive_ids = array_merge( $moved_to_inactive_ids, $moved_to_inactive_recently );
$moved_to_sidebar_recently = $this->sync_add_widgets_to_sidebar( $new_widgets, $old_widgets, $sidebar );
$moved_to_sidebar = array_merge( $moved_to_sidebar, $moved_to_sidebar_recently );
@@ -369,6 +389,11 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
}
+ //Don't sync either jetpack_widget_moved_to_inactive or jetpack_cleared_inactive_widgets if theme was switched
+ if ( $this->is_theme_switch() ) {
+ return;
+ }
+
// Treat inactive sidebar a bit differently
if ( ! empty( $moved_to_inactive_ids ) ) {
$moved_to_inactive_name = array_map( array( $this, 'get_widget_name' ), $moved_to_inactive_ids );
@@ -406,9 +431,34 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
}
$theme = wp_get_theme();
- $theme_support['name'] = $theme->name;
- $theme_support['version'] = $theme->version;
+ $theme_support['name'] = $theme->get('Name');
+ $theme_support['version'] = $theme->get('Version');
+ $theme_support['slug'] = $theme->get_stylesheet();
+ $theme_support['uri'] = $theme->get('ThemeURI');
+
return $theme_support;
}
+
+ private function get_delete_theme_call() {
+ $backtrace = debug_backtrace();
+ $delete_theme_call = null;
+ foreach ( $backtrace as $call ) {
+ if ( isset( $call['function'] ) && 'delete_theme' === $call['function'] ) {
+ $delete_theme_call = $call;
+ break;
+ }
+ }
+ return $delete_theme_call;
+ }
+
+ private function is_theme_switch() {
+ $backtrace = debug_backtrace();
+ foreach ( $backtrace as $call ) {
+ if ( isset( $call['args'][0] ) && 'after_switch_theme' === $call['args'][0] ) {
+ return true;
+ }
+ }
+ return false;
+ }
}