Make WordPress Core


Ignore:
Timestamp:
01/15/2026 12:08:01 PM (3 months ago)
Author:
jonsurrell
Message:

Customize: Allow arbitrary CSS in global styles custom CSS.

Relax Global Styles custom CSS filters to allow arbitrary CSS.

Escape HTML characters <>& in Global Styles data to prevent it from being mangled by post content filters. The data is JSON encoded and stored in post_content. Filters operating on post_content expect it to contain HTML. Some KSES filters would otherwise remove essential CSS features like the <custom-ident> CSS data type because they appear to be HTML tags.

[61418] changed STYLE tag generation to use the HTML API for improved safety.

Developed in https://github.com/WordPress/wordpress-develop/pull/10641.

Props jonsurrell, dmsnell, westonruter, ramonopoly, oandregal, jorgefilipecosta, sabernhardt, soyebsalar01.
See #64418.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/kses.php

    r61467 r61486  
    23872387
    23882388        $data_to_encode['isGlobalStylesUserThemeJSON'] = true;
    2389         return wp_slash( wp_json_encode( $data_to_encode ) );
     2389        /**
     2390         * JSON encode the data stored in post content.
     2391         * Escape characters that are likely to be mangled by HTML filters: "<>&".
     2392         *
     2393         * This matches the escaping in {@see WP_REST_Global_Styles_Controller::prepare_item_for_database()}.
     2394         */
     2395        return wp_slash( wp_json_encode( $data_to_encode, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) );
    23902396    }
    23912397    return $data;
Note: See TracChangeset for help on using the changeset viewer.