File tree Expand file tree Collapse file tree
src/wp-includes/block-supports
tests/phpunit/tests/block-supports Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -171,8 +171,17 @@ function wp_get_color_classes_and_styles( $block_attributes ) {
171171 );
172172
173173 foreach ( $ preset_attributes as $ feature => list ( $ preset_attribute , $ preset_type ) ) {
174- $ preset_slug = $ block_attributes [ $ preset_attribute ] ?? null ;
175- $ preset_value = is_string ( $ preset_slug ) && '' !== $ preset_slug ? "var:preset| {$ preset_type }| {$ preset_slug }" : null ;
174+ $ preset_slug = $ block_attributes [ $ preset_attribute ] ?? null ;
175+ if ( true === $ preset_slug ) {
176+ $ preset_slug = 'true ' ;
177+ }
178+
179+ // Mirrors JS truthiness, so '0' is a slug. Arrays cannot form a class name.
180+ $ has_preset = is_string ( $ preset_slug )
181+ ? '' !== $ preset_slug
182+ : ( is_int ( $ preset_slug ) || is_float ( $ preset_slug ) ) && 0.0 !== (float ) $ preset_slug ;
183+
184+ $ preset_value = $ has_preset ? "var:preset| {$ preset_type }| {$ preset_slug }" : null ;
176185 $ custom_value = $ block_attributes ['style ' ]['color ' ][ $ feature ] ?? null ;
177186 $ color_block_styles [ $ feature ] = $ preset_value ?? $ custom_value ;
178187 }
Original file line number Diff line number Diff line change @@ -78,6 +78,14 @@ public function data_get_color_classes_and_styles() {
7878 'style ' => 'color:#d92828; ' ,
7979 ),
8080 ),
81+ 'numeric preset ' => array (
82+ 'block_attributes ' => array (
83+ 'textColor ' => 1 ,
84+ ),
85+ 'expected ' => array (
86+ 'class ' => 'has-text-color has-1-color ' ,
87+ ),
88+ ),
8189 'empty ' => array (
8290 'block_attributes ' => array (),
8391 'expected ' => array (),
You can’t perform that action at this time.
0 commit comments