From c589a2b4a6508c01c75a563a6460efcffd7a09e4 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Sun, 20 Sep 2026 18:04:51 +0100 Subject: [PATCH] Treat an unrecognised label visibility as visible Any hmLabelVisibility value outside the enum fell through to 'mobile', so a hand-edited or corrupted attribute hid the label on small screens. It now counts as absent and the legacy flag decides, which leaves every valid combination rendering as before. --- inc/render.php | 15 ++++++--------- src/index.js | 10 +++------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/inc/render.php b/inc/render.php index 94c51a5..2fefda3 100644 --- a/inc/render.php +++ b/inc/render.php @@ -112,8 +112,9 @@ static function ( array $matches ) use ( $icon, $position ): string { * front end is the raw comment JSON, never merged against registered * defaults — see the file docblock in `inc/attributes.php`. So an explicit * `'hidden'` or an explicit `'mobile'` always wins, and a `'visible'` only - * counts once the legacy flag is confirmed clear; otherwise the legacy flag - * decides, exactly as it did before this attribute existed. + * counts once the legacy flag is confirmed clear. Otherwise the legacy flag + * decides, exactly as it did before this attribute existed. A value outside + * the enum is treated as absent, so it never hides a label by itself. * * @param array $attributes The block's attributes. * @return string One of 'visible', 'mobile', 'hidden'. @@ -121,15 +122,11 @@ static function ( array $matches ) use ( $icon, $position ): string { function label_visibility( array $attributes ): string { $visibility = $attributes['hmLabelVisibility'] ?? 'visible'; - if ( 'hidden' === $visibility ) { - return 'hidden'; + if ( in_array( $visibility, [ 'hidden', 'mobile' ], true ) ) { + return $visibility; } - if ( 'visible' === $visibility && empty( $attributes['hmHideLabelOnMobile'] ) ) { - return 'visible'; - } - - return 'mobile'; + return empty( $attributes['hmHideLabelOnMobile'] ) ? 'visible' : 'mobile'; } /** diff --git a/src/index.js b/src/index.js index 1c757eb..5cfe8c7 100644 --- a/src/index.js +++ b/src/index.js @@ -80,15 +80,11 @@ const NO_ICON = { function resolveLabelVisibility( attributes ) { const { hmLabelVisibility, hmHideLabelOnMobile } = attributes; - if ( 'hidden' === hmLabelVisibility ) { - return 'hidden'; + if ( [ 'hidden', 'mobile' ].includes( hmLabelVisibility ) ) { + return hmLabelVisibility; } - if ( 'visible' === hmLabelVisibility && ! hmHideLabelOnMobile ) { - return 'visible'; - } - - return 'mobile'; + return hmHideLabelOnMobile ? 'mobile' : 'visible'; } /**