📄 原始资料 | 展开查看原始 JSON(bricks-svg-allowed_attributes.json){ “name”: “bricks/svg/allowed_attributes”, “kind”: “filter”, “url”: “https://academy.bricksbuilder.io/developer/hooks/filters/bricks-svg-allowed_attributes/”, “scraped_at”: “2026-08-29”, “hook_name”: “bricks/svg/allowed_attributes”,…
📄 原始资料 | 展开查看原始 JSON(bricks-svg-allowed_attributes.json)
{
"name": "bricks/svg/allowed_attributes",
"kind": "filter",
"url": "https://academy.bricksbuilder.io/developer/hooks/filters/bricks-svg-allowed_attributes/",
"scraped_at": "2026-08-29",
"hook_name": "bricks/svg/allowed_attributes",
"description": {
"en": "Filters the list of allowed SVG attributes during sanitization. This is used by the Bricks SVG sanitizer to ensure that uploaded or rendered SVGs do not contain malicious attributes.",
"zh": "筛选清理过程中允许的 SVG 属性列表。由 Bricks SVG 清理器使用,以确保上传或渲染的 SVG 不包含恶意属性。"
},
"parameters": [
{
"name": "attributes",
"type": "array",
"type_zh": null,
"description": {
"en": "Array of allowed SVG attributes.",
"zh": "允许的 SVG 属性数组。"
}
}
],
"example_usage": "add_filter( 'bricks/svg/allowed_attributes', function( $attributes ) {\n // Example: Allow 'data-custom' attribute\n $attributes[] = 'data-custom';\n\n\n return $attributes;\n} );"
}
前言
筛选清理过程中允许的 SVG 属性列表。由 Bricks SVG 清理器使用,以确保上传或渲染的 SVG 不包含恶意属性。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/svg/allowed_attributes', function( $attributes ) {
// Example: Allow 'data-custom' attribute
$attributes[] = 'data-custom';
return $attributes;
} );
参数
$attributes (array):允许的 SVG 属性数组。
示例代码
筛选返回值
add_filter( 'bricks/svg/allowed_attributes', function( $attributes ) {
// Example: Allow 'data-custom' attribute
$attributes[] = 'data-custom';
return $attributes;
} );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/svg/allowed_attributes', function( $value, $attributes ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。