From 0de941c281a965b13916e3b3ab6d9c8aac5f70ca Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Fri, 17 Apr 2026 12:01:58 +0530 Subject: [PATCH 1/2] fix: vertical alignment in flex layouts --- includes/front.php | 35 ++++++++++++++++++++++++++++++++--- includes/meta.php | 8 ++++++++ includes/settings.php | 16 ---------------- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/includes/front.php b/includes/front.php index cb42e40..bce3e5f 100644 --- a/includes/front.php +++ b/includes/front.php @@ -339,6 +339,18 @@ public static function get_icon_style( $meta, $keys, $as_attribute = true ) { $rule = self::$default_style[ $key ]; + // Special handling for vertical-align because it affects the layout of flex containers. + if ( 'vertical_align' === $key ) { + $stored = isset( $meta[ $key ] ) ? $meta[ $key ] : $rule['value']; + + if ( $stored !== $rule['value'] ) { + $style_a[ $rule['property'] ] = $stored; + } + + $style_a['align-self'] = self::calculate_align_self( $stored ); + continue; + } + if ( ! isset( $meta[ $key ] ) || $meta[ $key ] === $rule['value'] ) { continue; } @@ -355,13 +367,13 @@ public static function get_icon_style( $meta, $keys, $as_attribute = true ) { return $style_s; } - foreach ( $style_a as $key => $value ) { - $style_s .= "{$key}:{$value};"; + foreach ( $style_a as $prop => $value ) { + $style_s .= "{$prop}:{$value};"; } $style_s = esc_attr( $style_s ); - if ( $as_attribute ) { + if ( $as_attribute ) { $style_s = sprintf( ' style="%s"', $style_s ); } @@ -513,4 +525,21 @@ public static function _add_menu_item_class( $classes, $item, $args ) { // phpcs $classes[] = 'menu-item'; return $classes; } + + /** + * Calculate align-self value. + * + * @param string $value vertical-align value. + * @return string + */ + private static function calculate_align_self( $value ) { + $align_self_map = array( + 'top' => 'flex-start', + 'middle' => 'center', + 'bottom' => 'flex-end', + 'baseline' => 'baseline', + ); + + return isset( $align_self_map[ $value ] ) ? $align_self_map[ $value ] : 'center'; + } } diff --git a/includes/meta.php b/includes/meta.php index fd8563d..51c8d0f 100644 --- a/includes/meta.php +++ b/includes/meta.php @@ -103,6 +103,14 @@ public static function get( $id, $defaults = array() ) { $value['position'] = $defaults['position']; } + // Backward-compatibility: values removed in favour of align-self support. + $supported_vertical_align = array( 'top', 'middle', 'bottom', 'baseline' ); + if ( isset( $value['vertical_align'] ) && + ! in_array( $value['vertical_align'], $supported_vertical_align, true ) + ) { + $value['vertical_align'] = 'middle'; + } + if ( isset( $value['size'] ) && ! isset( $value['font_size'] ) ) { $value['font_size'] = $value['size']; unset( $value['size'] ); diff --git a/includes/settings.php b/includes/settings.php index 666eb57..c7f88f4 100644 --- a/includes/settings.php +++ b/includes/settings.php @@ -535,18 +535,10 @@ public static function get_settings_fields( array $values = array() ) { 'label' => __( 'Vertical Align', 'menu-icons' ), 'default' => 'middle', 'choices' => array( - array( - 'value' => 'super', - 'label' => __( 'Super', 'menu-icons' ), - ), array( 'value' => 'top', 'label' => __( 'Top', 'menu-icons' ), ), - array( - 'value' => 'text-top', - 'label' => __( 'Text Top', 'menu-icons' ), - ), array( 'value' => 'middle', 'label' => __( 'Middle', 'menu-icons' ), @@ -555,18 +547,10 @@ public static function get_settings_fields( array $values = array() ) { 'value' => 'baseline', 'label' => __( 'Baseline', 'menu-icons' ), ), - array( - 'value' => 'text-bottom', - 'label' => __( 'Text Bottom', 'menu-icons' ), - ), array( 'value' => 'bottom', 'label' => __( 'Bottom', 'menu-icons' ), ), - array( - 'value' => 'sub', - 'label' => __( 'Sub', 'menu-icons' ), - ), ), ), 'font_size' => array( From f80a5e52e570e578fde1bd230ecce90c32a882ec Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Fri, 17 Apr 2026 12:20:58 +0530 Subject: [PATCH 2/2] fix: improve vertical alignment handling --- includes/front.php | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/includes/front.php b/includes/front.php index bce3e5f..5e1d89b 100644 --- a/includes/front.php +++ b/includes/front.php @@ -51,6 +51,19 @@ final class Menu_Icons_Front_End { */ protected static $hidden_label_class = 'visuallyhidden'; + /** + * Align-self map for vertical-align values. + * + * @access private + * @var array + */ + private static $align_self_map = array( + 'top' => 'flex-start', + 'middle' => 'center', + 'bottom' => 'flex-end', + 'baseline' => 'baseline', + ); + /** * Add hooks for front-end functionalities @@ -341,13 +354,13 @@ public static function get_icon_style( $meta, $keys, $as_attribute = true ) { // Special handling for vertical-align because it affects the layout of flex containers. if ( 'vertical_align' === $key ) { - $stored = isset( $meta[ $key ] ) ? $meta[ $key ] : $rule['value']; - - if ( $stored !== $rule['value'] ) { - $style_a[ $rule['property'] ] = $stored; + if ( ! isset( $meta[ $key ] ) || $meta[ $key ] === $rule['value'] ) { + continue; } - $style_a['align-self'] = self::calculate_align_self( $stored ); + $stored = $meta[ $key ]; + $style_a[ $rule['property'] ] = $stored; + $style_a['align-self'] = isset( self::$align_self_map[ $stored ] ) ? self::$align_self_map[ $stored ] : 'center'; continue; } @@ -525,21 +538,4 @@ public static function _add_menu_item_class( $classes, $item, $args ) { // phpcs $classes[] = 'menu-item'; return $classes; } - - /** - * Calculate align-self value. - * - * @param string $value vertical-align value. - * @return string - */ - private static function calculate_align_self( $value ) { - $align_self_map = array( - 'top' => 'flex-start', - 'middle' => 'center', - 'bottom' => 'flex-end', - 'baseline' => 'baseline', - ); - - return isset( $align_self_map[ $value ] ) ? $align_self_map[ $value ] : 'center'; - } }