Make WordPress Core

Opened 7 weeks ago

Last modified 7 weeks ago

#63046 new enhancement

Add background-clip to the safe_style_css filter

Reported by: mi5t4n's profile mi5t4n Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Formatting Keywords: has-patch
Focuses: Cc:

Description

Currently, when using the following code, CSS properties like background-clip and display are stripped out during the wp_kses_post() sanitization process.

<?php
add_action('init', function() {
    $html = '
        <span style="
            background-clip: text;
            display: inline-block;">
            Gradient Text
        </span>
    ';

    $sanitize_post = wp_kses_post( $html );
});

Expected Output:

<span style="background-clip: text; display: inline-block;">
    Gradient Text
</span>

Current Output:

<span>
    Gradient Text
</span>

The issue occurs because CSS properties like background-clip and display are removed. It would be helpful to allow additional CSS properties through the wp_kses_post() function by extending the safe_style_css filter to support these properties.

Change History (6)

This ticket was mentioned in PR #8445 on WordPress/wordpress-develop by @mi5t4n.


7 weeks ago
#1

  • Keywords has-patch added

Trac ticket: https://core.trac.wordpress.org/ticket/63046

This PR adds background-clip and display CSS rule to safecss_filter_attr() function.

#2 @sabernhardt
7 weeks ago

The committed change on #56122 did not include display so the function would not allow display: none (by default).
https://github.com/WordPress/wordpress-develop/pull/2928#discussion_r912554761

#3 @mi5t4n
7 weeks ago

@sabernhardt Thanks for the context. It looks like the display:none was deliberately left out. Should I proceed with updating the PR to include just the background-clip CSS rule?

#4 @sabernhardt
7 weeks ago

Adding only background-clip would make the PR—and ticket—more focused. That sounds good :)

#5 @mi5t4n
7 weeks ago

@sabernhardt PR has been updated.

#6 @sabernhardt
7 weeks ago

  • Component changed from General to Formatting
  • Summary changed from Add additional CSS style properties to the safe_style_css filter to Add background-clip to the safe_style_css filter

Thanks!

Note: See TracTickets for help on using tickets.