wp_global_styles_render_svg_filters()
云策文档标注
概述
此函数用于渲染由 theme.json 提供的 SVG 过滤器,但已在 WordPress 6.3.0 版本中被弃用。它主要用于在块编辑器页面中输出全局样式过滤器,以满足 Safari 浏览器的渲染需求。
关键要点
- 函数 wp_global_styles_render_svg_filters() 已被弃用,建议开发者使用块支持中的每块处理方式。
- 它仅渲染 theme.json 提供的全局 SVG 过滤器,不处理每块用户定义的过滤器(由 wp_render_duotone_support 处理)。
- 在管理界面中,函数仅在块编辑器页面中渲染 SVG 过滤器,以避免不必要的输出。
代码示例
function wp_global_styles_render_svg_filters() {
_deprecated_function( __FUNCTION__, '6.3.0' );
/*
* When calling via the in_admin_header action, we only want to render the
* SVGs on block editor pages.
*/
if (
is_admin() &&
! get_current_screen()->is_block_editor()
) {
return;
}
$filters = wp_get_global_styles_svg_filters();
if ( ! empty( $filters ) ) {
echo $filters;
}
}注意事项
- 此函数自 WordPress 6.3.0 起已弃用,开发者应迁移到块支持中的新方法。
- 渲染应在过滤内容之前进行,以确保在 Safari 浏览器中正确显示。
- 相关函数包括 wp_get_global_styles_svg_filters()、get_current_screen()、is_admin() 和 _deprecated_function()。
原文内容
Renders the SVG filters supplied by theme.json.
Description
Note that this doesn’t render the per-block user-defined filters which are handled by wp_render_duotone_support, but it should be rendered before the filtered content in the body to satisfy Safari’s rendering quirks.
Source
function wp_global_styles_render_svg_filters() {
_deprecated_function( __FUNCTION__, '6.3.0' );
/*
* When calling via the in_admin_header action, we only want to render the
* SVGs on block editor pages.
*/
if (
is_admin() &&
! get_current_screen()->is_block_editor()
) {
return;
}
$filters = wp_get_global_styles_svg_filters();
if ( ! empty( $filters ) ) {
echo $filters;
}
}