Php WordPress esc_内容上的html
我有以下代码:Php WordPress esc_内容上的html,php,wordpress,security,Php,Wordpress,Security,我有以下代码: the_content( sprintf( __( 'Continue reading %s', 'twentyfifteen' ), the_title( '<span class="screen-reader-text">', '</span>', false ) ) ); ( __(“继续读取%s”,“二十一五”), 标题(“”,“”为假) ) ); 如何针对
the_content( sprintf(
__( 'Continue reading %s', 'twentyfifteen' ),
the_title( '<span class="screen-reader-text">', '</span>', false )
) );
(
__(“继续读取%s”,“二十一五”),
标题(“”,“”为假)
) );
如何针对安全问题逃逸上述代码?我一直在使用下面的代码修复问题:
<?php echo esc_html(get_the_title()) ; ?>
来自:
需要注意的是,大多数WordPress函数正确地准备了输出数据,您不需要再次转义
因此,对于此函数,您不必再次转义标题()
,因为此函数本身已经完成了转义
对于所有其他转义/清理需要,请查看。标题()
,摘录()
和内容()
不会转义(内容()
会进行一些字符串替换),这可能会导致安全问题,例如,当编辑器安装了恶意浏览器扩展时
正确的方法是将这些函数的get.*
版本包装到esc\u html\u e()
(它运行esc\u html(),通过文本域进行翻译,并返回结果),因此在您的情况下:
这是不正确的,未转义标题(标题|摘录|内容)。