gpt4 book ai didi

php - 内容上的 WordPress esc_html

转载 作者:行者123 更新时间:2023-12-02 05:16:38 25 4
gpt4 key购买 nike

我有这个代码:

the_content( sprintf(
__( 'Continue reading %s', 'twentyfifteen' ),
the_title( '<span class="screen-reader-text">', '</span>', false )
) );

如何出于安全问题对上面的代码进行转义?我一直在使用下面的代码来解决问题:

<?php echo esc_html(get_the_title()) ; ?>

最佳答案

the_title() , the_excerpt()the_content()不会转义(the_content() 会进行一些字符串替换),这可能会导致安全问题,例如当编辑器安装了恶意浏览器扩展程序时。

正确的做法是将get_*包裹起来这些功能的版本到 esc_html_e() (它运行 esc_html(),通过文本域进行翻译,然后回显结果),因此在您的情况下:

<?php esc_html_e(get_the_content($more_link_text, $strip_teaser)); ?>

关于php - 内容上的 WordPress esc_html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39531061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com