Make WordPress Core


Ignore:
Timestamp:
05/11/2026 02:04:05 AM (5 months ago)
Author:
ramonopoly
Message:

WP_Theme_JSON: Prevent implicit coercion in to_ruleset

to_ruleset used string concatenation ($element['name'] . ': ' . $element['value'] . ';'), so PHP implicitly coerced non-string values (e.g. booleans → '1'/'', arrays → 'Array'). That could emit invalid or misleading CSS.

At the same time, pass a style theme.json path in test_get_styles_with_appearance_tools() to simulate a style node. Before it was settings.

Props ramonopoly, andrewserong, isabel_brison.

Fixes #64848.

--This line, and those below, will be ignored--

M src/wp-includes/class-wp-theme-json.php
M tests/phpunit/tests/theme/wpThemeJson.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json.php

    r62178 r62347  
    19831983         *
    19841984         * @since 5.8.0
     1985         * @since 7.1.0 Skip declarations whose value is not a plain string (booleans, arrays, objects, etc.).
    19851986         *
    19861987         * @param string $selector     CSS selector.
    … …  
    19961997                        $declarations,
    19971998                        static function ( $carry, $element ) {
    1998                                 return $carry .= $element['name'] . ': ' . $element['value'] . ';'; },
     1999                                $value = $element['value'];
     2000
     2001                                if ( is_numeric( $value ) ) {
     2002                                        $value = (string) $value;
     2003                                }
     2004
     2005                                if ( ! is_string( $value ) ) {
     2006                                        return $carry;
     2007                                }
     2008
     2009                                return $carry .= $element['name'] . ': ' . $value . ';';
     2010                        },
    19992011                        ''
    20002012                );
Note: See TracChangeset for help on using the changeset viewer.