-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Navigation: Remove duplicate css color building functions #48700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,77 +5,6 @@ | |||||
| * @package WordPress | ||||||
| */ | ||||||
|
|
||||||
| /** | ||||||
| * Build an array with CSS classes and inline styles defining the colors | ||||||
| * which will be applied to the navigation markup in the front-end. | ||||||
| * | ||||||
| * @param array $context Navigation block context. | ||||||
| * @param array $attributes Block attributes. | ||||||
| * @return array Colors CSS classes and inline styles. | ||||||
| */ | ||||||
| function block_core_navigation_link_build_css_colors( $context, $attributes ) { | ||||||
| $colors = array( | ||||||
| 'css_classes' => array(), | ||||||
| 'inline_styles' => '', | ||||||
| ); | ||||||
|
|
||||||
| $is_sub_menu = isset( $attributes['isTopLevelLink'] ) ? ( ! $attributes['isTopLevelLink'] ) : false; | ||||||
|
|
||||||
| // 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; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Build an array with CSS classes and inline styles defining the font sizes | ||||||
| * which will be applied to the navigation markup in the front-end. | ||||||
|
|
@@ -174,7 +103,7 @@ function render_block_core_navigation_link( $attributes, $content, $block ) { | |||||
| return ''; | ||||||
| } | ||||||
|
|
||||||
| $colors = block_core_navigation_link_build_css_colors( $block->context, $attributes ); | ||||||
| $colors = function_exists( 'block_core_navigation_submenu_build_css_colors' ) ? block_core_navigation_submenu_build_css_colors( $block->context, $attributes ) : array(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| $font_sizes = block_core_navigation_link_build_css_font_sizes( $block->context ); | ||||||
| $classes = array_merge( | ||||||
| $colors['css_classes'], | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,78 +5,7 @@ | |||||
| * @package WordPress | ||||||
| */ | ||||||
|
|
||||||
| /** | ||||||
| * Build an array with CSS classes and inline styles defining the colors | ||||||
| * which will be applied to the navigation markup in the front-end. | ||||||
| * | ||||||
| * @param array $context Navigation block context. | ||||||
| * @param array $attributes Block attributes. | ||||||
| * @return array Colors CSS classes and inline styles. | ||||||
| */ | ||||||
| function block_core_navigation_submenu_build_css_colors( $context, $attributes ) { | ||||||
| $colors = array( | ||||||
| 'css_classes' => array(), | ||||||
| 'inline_styles' => '', | ||||||
| ); | ||||||
|
|
||||||
| $is_sub_menu = isset( $attributes['isTopLevelItem'] ) ? ( ! $attributes['isTopLevelItem'] ) : false; | ||||||
|
|
||||||
| // 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; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| /** | ||||||
| * Build an array with CSS classes and inline styles defining the font sizes | ||||||
| * which will be applied to the navigation markup in the front-end. | ||||||
| * | ||||||
|
|
@@ -145,7 +74,7 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) { | |||||
| return ''; | ||||||
| } | ||||||
|
|
||||||
| $colors = block_core_navigation_submenu_build_css_colors( $block->context, $attributes ); | ||||||
| $colors = function_exists( 'block_core_navigation_submenu_build_css_colors' ) ? block_core_navigation_submenu_build_css_colors( $block->context, $attributes ) : array(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| $font_sizes = block_core_navigation_submenu_build_css_font_sizes( $block->context ); | ||||||
| $classes = array_merge( | ||||||
| $colors['css_classes'], | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -898,4 +898,75 @@ function block_core_navigation_typographic_presets_backcompatibility( $parsed_bl | |||||
| return $parsed_block; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Build an array with CSS classes and inline styles defining the colors | ||||||
| * which will be applied to the navigation markup in the front-end. | ||||||
| * | ||||||
| * @param array $context Navigation block context. | ||||||
| * @param array $attributes Block attributes. | ||||||
| * @return array Colors CSS classes and inline styles. | ||||||
| */ | ||||||
| function block_core_navigation_submenu_build_css_colors( $context, $attributes ) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we change the name to not reference
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| $colors = array( | ||||||
| 'css_classes' => array(), | ||||||
| 'inline_styles' => '', | ||||||
| ); | ||||||
|
|
||||||
| $is_sub_menu = isset( $attributes['isTopLevelItem'] ) ? ( ! $attributes['isTopLevelItem'] ) : false; | ||||||
|
|
||||||
| // 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; | ||||||
| } | ||||||
|
|
||||||
| add_filter( 'render_block_data', 'block_core_navigation_typographic_presets_backcompatibility' ); | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since all functions in PHP are public, should we probably add
_deprecated_function( __FUNCTION__, '6.2' );to this one and just call the other function from it, right?