Browse Source

Change how 'old custom theme colors' are cleaned out to be more specific (#5754)

Jason Crist 3 years ago
parent
commit
6ab7080e27
1 changed files with 12 additions and 1 deletions
  1. 12 1
      blockbase/inc/customizer/wp-customize-colors.php

+ 12 - 1
blockbase/inc/customizer/wp-customize-colors.php

@@ -152,7 +152,18 @@ class GlobalStylesColorCustomizer {
 		$new_settings['color']['palette']['theme'] = $this->user_color_palette;
 		$new_settings['color']['palette']['theme'] = $this->user_color_palette;
 		// We used to set the values in 'custom' but moved to 'theme' to mirror GS functionality.
 		// We used to set the values in 'custom' but moved to 'theme' to mirror GS functionality.
 		// This ensures that new saves don't store the customizations in both places.
 		// This ensures that new saves don't store the customizations in both places.
-		unset($new_settings['color']['palette']['custom']);
+		if($new_settings['color']['palette']['custom']) {
+			foreach ( $new_settings['color']['palette']['theme'] as $theme_color ) {
+				foreach ( $new_settings['color']['palette']['custom'] as $key => $custom_color ) {
+					if( $theme_color['slug'] === $custom_color['slug'] ) {
+						unset( $new_settings['color']['palette']['custom'][$key] );
+					}
+				}
+			}
+			if ( ! $new_settings['color']['palette']['custom'] ) {
+				unset ( $new_settings['color']['palette']['custom'] );
+			}
+		}
 
 
 		// Add the updated global styles to the update request
 		// Add the updated global styles to the update request
 		$update_request = new WP_REST_Request( 'PUT', '/wp/v2/global-styles/' );
 		$update_request = new WP_REST_Request( 'PUT', '/wp/v2/global-styles/' );