我们必须更深入地了解一下,才能得到您问题的答案。
所以bloginfo 是一个简单的包装get_bloginfo.
<?php
function bloginfo( $show=\'\' ) {
echo get_bloginfo( $show, \'display\' );
}
注意第二个参数
display. 让我们看看它有什么作用。
<?php
function get_bloginfo( $show = \'\', $filter = \'raw\' ) {
// snip snip, $output is fetched somewhere in here
if ( \'display\' == $filter ) {
if ( $url )
$output = apply_filters(\'bloginfo_url\', $output, $show);
else
$output = apply_filters(\'bloginfo\', $output, $show);
}
return $output;
}
如果过滤器设置为
display 的输出
get_bloginfo 通过过滤器运行。
而不是像调用esc_html 在一个函数中,WP使用它自己的挂钩系统来做事情。找到发生这种情况的地方是wp-includes/default-filters.php. 快速搜索bloginfo 在该文件中显示。。。
<?php
// Format strings for display.
foreach ( array( \'comment_author\', \'term_name\', \'link_name\', \'link_description\', \'link_notes\', \'bloginfo\', \'wp_title\', \'widget_title\' ) as $filter ) {
add_filter( $filter, \'wptexturize\' );
add_filter( $filter, \'convert_chars\' );
add_filter( $filter, \'esc_html\' );
}
bloginfo 隐藏在
foreach 大堆如您所见
bloginfo 使用逃逸
esc_html.
换句话说,这:
<?php
bloginfo(\'name\');
相当于:
<?php
echo esc_html(get_bloginfo(\'name\'));
或者这个:
<?php
echo get_bloginfo(\'name\', \'display\');
所以,不,输出
bloginfo 不需要逃逸。的输出
get_bloginfo 只要第二个参数设置为
display.
然而,需要注意的是,任何人都可以删除esc_html 筛选自bloginfo. 因此,逃避输出可能更安全。当然,如果您使用bloginfo 对于HTML显示以外的任何内容(例如,在图像的alt属性中),您应该运行它esc_attr.