From 4c596f06d9ca5d3b44c5c4aa426ee50bcd7ff2f9 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 30 Jun 2023 15:10:54 +1000 Subject: [PATCH 1/2] block_core_navigation_submenu_build_css_colors was deprecated in https://github.com/WordPress/gutenberg/pull/48936 in favour of wp_apply_colors_support this commit adds a deprecation to core --- src/wp-includes/deprecated.php | 75 ++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/wp-includes/deprecated.php b/src/wp-includes/deprecated.php index 8f4396711ca3c..97d9ec9352dac 100644 --- a/src/wp-includes/deprecated.php +++ b/src/wp-includes/deprecated.php @@ -5290,3 +5290,78 @@ function wp_global_styles_render_svg_filters() { echo $filters; } } + +/** + * Build an array with CSS classes and inline styles defining the colors + * which will be applied to the navigation markup in the front-end. + * + * @deprecated 6.3.0 This was removed from the Navigation Submenu block in favour of `wp_apply_colors_support()`. + * `wp_apply_colors_support()` returns an array with similar class and style values, + * but with different keys: `class` and `style`. + * + * @param array $context Navigation block context. + * @param array $attributes Block attributes. + * @param bool $is_sub_menu Whether the block is a sub-menu. + * @return array Colors CSS classes and inline styles. + */ +function block_core_navigation_submenu_build_css_colors( $context, $attributes, $is_sub_menu = false ) { + _deprecated_function( __FUNCTION__, '6.3.0' ); + $colors = array( + 'css_classes' => array(), + 'inline_styles' => '', + ); + + // Text color. + $named_text_color = null; + $custom_text_color = null; + + if ( $is_sub_menu && array_key_exists( 'customOverlayTextColor', $context ) ) { + $custom_text_color = $context['customOverlayTextColor']; + } elseif ( $is_sub_menu && array_key_exists( 'overlayTextColor', $context ) ) { + $named_text_color = $context['overlayTextColor']; + } elseif ( array_key_exists( 'customTextColor', $context ) ) { + $custom_text_color = $context['customTextColor']; + } elseif ( array_key_exists( 'textColor', $context ) ) { + $named_text_color = $context['textColor']; + } elseif ( isset( $context['style']['color']['text'] ) ) { + $custom_text_color = $context['style']['color']['text']; + } + + // If has text color. + if ( ! is_null( $named_text_color ) ) { + // Add the color class. + array_push( $colors['css_classes'], 'has-text-color', sprintf( 'has-%s-color', $named_text_color ) ); + } elseif ( ! is_null( $custom_text_color ) ) { + // Add the custom color inline style. + $colors['css_classes'][] = 'has-text-color'; + $colors['inline_styles'] .= sprintf( 'color: %s;', $custom_text_color ); + } + + // Background color. + $named_background_color = null; + $custom_background_color = null; + + if ( $is_sub_menu && array_key_exists( 'customOverlayBackgroundColor', $context ) ) { + $custom_background_color = $context['customOverlayBackgroundColor']; + } elseif ( $is_sub_menu && array_key_exists( 'overlayBackgroundColor', $context ) ) { + $named_background_color = $context['overlayBackgroundColor']; + } elseif ( array_key_exists( 'customBackgroundColor', $context ) ) { + $custom_background_color = $context['customBackgroundColor']; + } elseif ( array_key_exists( 'backgroundColor', $context ) ) { + $named_background_color = $context['backgroundColor']; + } elseif ( isset( $context['style']['color']['background'] ) ) { + $custom_background_color = $context['style']['color']['background']; + } + + // If has background color. + if ( ! is_null( $named_background_color ) ) { + // Add the background-color class. + array_push( $colors['css_classes'], 'has-background', sprintf( 'has-%s-background-color', $named_background_color ) ); + } elseif ( ! is_null( $custom_background_color ) ) { + // Add the custom background-color inline style. + $colors['css_classes'][] = 'has-background'; + $colors['inline_styles'] .= sprintf( 'background-color: %s;', $custom_background_color ); + } + + return $colors; +} From 4dc0e607b6b8a7bed460285087ff977ab7f488ed Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Mon, 3 Jul 2023 15:09:22 +1000 Subject: [PATCH 2/2] Add since to deprecated function. --- src/wp-includes/deprecated.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-includes/deprecated.php b/src/wp-includes/deprecated.php index 97d9ec9352dac..74fdfb7887099 100644 --- a/src/wp-includes/deprecated.php +++ b/src/wp-includes/deprecated.php @@ -5295,6 +5295,7 @@ function wp_global_styles_render_svg_filters() { * Build an array with CSS classes and inline styles defining the colors * which will be applied to the navigation markup in the front-end. * + * @since 5.9.0 * @deprecated 6.3.0 This was removed from the Navigation Submenu block in favour of `wp_apply_colors_support()`. * `wp_apply_colors_support()` returns an array with similar class and style values, * but with different keys: `class` and `style`.