@@ -83,41 +83,27 @@ function wp_render_block_visibility_support( $block_content, $block ) {
8383 return $ block_content ;
8484 }
8585
86- // If the block is hidden on all breakpoints, return empty string .
86+ // If the block is hidden on all breakpoints, do not render the block .
8787 if ( count ( $ hidden_on ) === count ( $ breakpoint_queries ) ) {
8888 return '' ;
8989 }
9090
91- // Generate a unique class name based on which breakpoints are hidden .
91+ // Maintain consistent order of breakpoints for class name generation .
9292 sort ( $ hidden_on );
9393
94- // Sanitize breakpoint names for use in HTML class attribute.
95- $ sanitized_hidden_on = array_map ( 'sanitize_html_class ' , $ hidden_on );
96- $ sanitized_hidden_on = array_filter ( $ sanitized_hidden_on );
97-
98- // If all breakpoint names were invalid after sanitization, return unchanged.
99- if ( empty ( $ sanitized_hidden_on ) ) {
100- return $ block_content ;
101- }
102-
103- $ visibility_class = 'wp-block-hidden- ' . implode ( '- ' , $ sanitized_hidden_on );
104-
105- // Generate CSS rules for each hidden breakpoint.
106- $ css_rules = array ();
94+ $ visibility_class = 'wp-block-hidden- ' . implode ( '- ' , $ hidden_on );
95+ $ css_rules = array ();
10796
10897 foreach ( $ hidden_on as $ breakpoint ) {
109- if ( isset ( $ breakpoint_queries [ $ breakpoint ] ) ) {
110- $ css_rules [] = array (
111- 'selector ' => '. ' . $ visibility_class ,
112- 'declarations ' => array (
113- 'display ' => 'none !important ' ,
114- ),
115- 'rules_group ' => $ breakpoint_queries [ $ breakpoint ],
116- );
117- }
98+ $ css_rules [] = array (
99+ 'selector ' => '. ' . $ visibility_class ,
100+ 'declarations ' => array (
101+ 'display ' => 'none !important ' ,
102+ ),
103+ 'rules_group ' => $ breakpoint_queries [ $ breakpoint ],
104+ );
118105 }
119106
120- // Use the style engine to enqueue the CSS.
121107 if ( ! empty ( $ css_rules ) ) {
122108 wp_style_engine_get_stylesheet_from_css_rules (
123109 $ css_rules ,
@@ -127,7 +113,6 @@ function wp_render_block_visibility_support( $block_content, $block ) {
127113 )
128114 );
129115
130- // Add the visibility class to the block content.
131116 if ( ! empty ( $ block_content ) ) {
132117 $ processor = new WP_HTML_Tag_Processor ( $ block_content );
133118 if ( $ processor ->next_tag () ) {
0 commit comments