Formatting: new filter `safecss_filter_attr_allow_css` on css parts.
Enables developers to determine whether a section of CSS should be allowed or discarded. By default, the value will be false if the part contains \ ( & } = or comments. Returning true allows the CSS part to be included in the output. Replaces the `safe_style_disallowed_chars` filter introduced in r47891. Props azaozz. Fixes #37134. Built from https://develop.svn.wordpress.org/trunk@48086 git-svn-id: http://core.svn.wordpress.org/trunk@47853 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
50ffc3843b
commit
810e9c3c2b
|
@ -2357,23 +2357,29 @@ function safecss_filter_attr( $css, $deprecated = '' ) {
|
|||
}
|
||||
|
||||
if ( $found ) {
|
||||
// Check for any CSS containing \ ( & } = or comments, except for url() usage checked above.
|
||||
$allow_css = ! preg_match( '%[\\\(&=}]|/\*%', $css_test_string );
|
||||
|
||||
/**
|
||||
* Filters the regex limiting the list of characters not allowed in CSS rules.
|
||||
* Filters the check for unsafe CSS in `safecss_filter_attr`.
|
||||
*
|
||||
* Default behaviour is to remove any CSS containing \ ( & } = or comments,
|
||||
* except for url() usage.
|
||||
* Enables developers to determine whether a section of CSS should be allowed or discarded.
|
||||
* By default, the value will be false if the part contains \ ( & } = or comments.
|
||||
* Return true to allow the CSS part to be included in the output.
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @param string $regex Regex pattern of disallowed characters in CSS rules.
|
||||
* Default is '%[\\\(&=}]|/\*%'.
|
||||
* @param string $css_test_string CSS value to test.
|
||||
* @param bool $allow_css Whether the CSS in the test string is considered safe.
|
||||
* @param string $css_test_string The css string to test.
|
||||
*/
|
||||
$disallowed_chars = apply_filters( 'safe_style_disallowed_chars', '%[\\\(&=}]|/\*%', $css_test_string );
|
||||
if ( ! preg_match( $disallowed_chars, $css_test_string ) ) {
|
||||
$allow_css = apply_filters( 'safecss_filter_attr_allow_css', $allow_css, $css_test_string );
|
||||
|
||||
// Only add the css part if it passes the regex check.
|
||||
if ( $allow_css ) {
|
||||
if ( '' !== $css ) {
|
||||
$css .= ';';
|
||||
}
|
||||
|
||||
$css .= $css_item;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.5-alpha-48085';
|
||||
$wp_version = '5.5-alpha-48086';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue