浏览代码

Alves: Improve color-annotation support.

- Add conditional fallbacks for foreground-light/dark colors
- Hide duplicate palette colors when using custom colors
Allan Cole 5 年之前
父节点
当前提交
49bbb275d0
共有 1 个文件被更改,包括 30 次插入8 次删除
  1. 30 8
      alves/functions.php

+ 30 - 8
alves/functions.php

@@ -58,11 +58,13 @@ if ( ! function_exists( 'alves_setup' ) ) :
 		 *
 		 *
 		 * - if the customizer color is empty, use the default
 		 * - if the customizer color is empty, use the default
 		 */
 		 */
-		$colors_array = get_theme_mod('colors_manager'); // color annotations array()
-		$primary      = ! empty( $colors_array ) ? $colors_array['colors']['link'] : '#3E7D98'; // $config-global--color-primary-default;
-		$secondary    = ! empty( $colors_array ) ? $colors_array['colors']['fg1'] : '#9B6A36';  // $config-global--color-secondary-default;
-		$foreground   = ! empty( $colors_array ) ? $colors_array['colors']['txt'] : '#394d55';  // $config-global--color-foreground-default;
-		$background   = ! empty( $colors_array ) ? $colors_array['colors']['bg'] : '#FFFFFF';   // $config-global--color-background-default;
+		$colors_array = get_theme_mod('colors_manager', array( 'colors' => true )); // color annotations array()
+		$primary          = ! empty( $colors_array ) ? $colors_array['colors']['link'] : '#3E7D98'; // $config-global--color-primary-default;
+		$secondary        = ! empty( $colors_array ) ? $colors_array['colors']['fg1'] : '#9B6A36';  // $config-global--color-secondary-default;
+		$background       = ! empty( $colors_array ) ? $colors_array['colors']['bg'] : '#FFFFFF';   // $config-global--color-background-default;
+		$foreground       = ! empty( $colors_array ) ? $colors_array['colors']['txt'] : '#394d55';  // $config-global--color-foreground-default;
+		$foreground_light = ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#394d55' ? $colors_array['colors']['txt'] : '#4d6974';  // $config-global--color-foreground-light-default;
+		$foreground_dark  = ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#394d55' ? $colors_array['colors']['txt'] : '#253136';  // $config-global--color-foreground-dark-default;
 
 
 		// Editor color palette.
 		// Editor color palette.
 		add_theme_support(
 		add_theme_support(
@@ -78,15 +80,25 @@ if ( ! function_exists( 'alves_setup' ) ) :
 					'slug'  => 'secondary',
 					'slug'  => 'secondary',
 					'color' => $secondary,
 					'color' => $secondary,
 				),
 				),
+				array(
+					'name'  => __( 'Background', 'alves' ),
+					'slug'  => 'background',
+					'color' => $background,
+				),
 				array(
 				array(
 					'name'  => __( 'Foreground', 'alves' ),
 					'name'  => __( 'Foreground', 'alves' ),
 					'slug'  => 'foreground',
 					'slug'  => 'foreground',
 					'color' => $foreground,
 					'color' => $foreground,
 				),
 				),
 				array(
 				array(
-					'name'  => __( 'Background', 'alves' ),
-					'slug'  => 'background',
-					'color' => $background,
+					'name'  => __( 'Foreground Light', 'alves' ),
+					'slug'  => 'foreground-light',
+					'color' => $foreground_light,
+				),
+				array(
+					'name'  => __( 'Foreground Dark', 'alves' ),
+					'slug'  => 'foreground-dark',
+					'color' => $foreground_dark,
 				),
 				),
 			)
 			)
 		);
 		);
@@ -207,5 +219,15 @@ function alves_editor_styles() {
 
 
 	// Enqueue Google fonts in the editor, if necessary
 	// Enqueue Google fonts in the editor, if necessary
 	wp_enqueue_style( 'alves-editor-fonts', alves_fonts_url(), array(), null );
 	wp_enqueue_style( 'alves-editor-fonts', alves_fonts_url(), array(), null );
+
+	// Hide duplicate palette colors
+	$colors_array = get_theme_mod('colors_manager', array( 'colors' => true )); // color annotations array()
+	if ( ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#394d55' ) { // $config-global--color-foreground-light-default;
+		$inline_palette_css = '.block-editor-color-gradient-control .components-circular-option-picker__option-wrapper:nth-child(5),
+			.block-editor-color-gradient-control .components-circular-option-picker__option-wrapper:nth-child(6) {
+				display: none;
+			}';
+		wp_add_inline_style( 'wp-edit-blocks', $inline_palette_css );
+	}
 }
 }
 add_action( 'enqueue_block_editor_assets', 'alves_editor_styles' );
 add_action( 'enqueue_block_editor_assets', 'alves_editor_styles' );