钩子文档

safecss_filter_attr_allow_css

💡 云策文档标注

概述

safecss_filter_attr_allow_css 是一个 WordPress 过滤器,用于在 safecss_filter_attr 函数中控制不安全 CSS 的检查。它允许开发者自定义 CSS 字符串的安全性判断,决定是否允许其输出。

关键要点

  • 过滤器名称为 safecss_filter_attr_allow_css,用于过滤 CSS 安全性检查。
  • 默认情况下,如果 CSS 字符串包含特定不安全字符(如 、&、}、= 或注释),则返回 false 表示不安全。
  • 开发者可以通过返回 true 来允许原本被视为不安全的 CSS 部分被包含在输出中。
  • 参数包括 $allow_css(布尔值,表示 CSS 是否安全)和 $css_test_string(字符串,要测试的 CSS 内容)。
  • 相关函数为 safecss_filter_attr(),位于 wp-includes/kses.php,用于过滤内联样式属性并移除不允许的规则。
  • 该过滤器自 WordPress 5.5.0 版本引入。

📄 原文内容

Filters the check for unsafe CSS in safecss_filter_attr.

Description

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.

Parameters

$allow_cssbool
Whether the CSS in the test string is considered safe.
$css_test_stringstring
The CSS string to test.

Source

$allow_css = apply_filters( 'safecss_filter_attr_allow_css', $allow_css, $css_test_string );

Changelog

Version Description
5.5.0 Introduced.