我有下面的代码,它标记了一个警告,主题审阅者要求我修复该警告。
WARNING All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found \'$fontListStr\'.
警告消息中的$fontListStr引用了以下代码的最后一行:
foreach( $this->fontList as $key => $value ) {
$fontCounter++;
$fontListStr .= \'<option value="\' . esc_attr($value->family) . \'" \' . selected( $this->fontValues->font, $value->family, false ) . \'>\' . esc_html($value->family) . \'</option>\';
if ( $this->fontValues->font === $value->family ) {
$isFontInList = true;
}
if ( is_int( $this->fontCount ) && $fontCounter === $this->fontCount ) {
break;
}
}
if ( !$isFontInList && $this->fontListIndex ) {
// If the default or saved font value isn\'t in the list of displayed fonts, add it to the top of the list as the default font
$fontListStr = \'<option value="\' . esc_attr($this->fontList[$this->fontListIndex]->family) . \'" \' . selected( $this->fontValues->font, $this->fontList[$this->fontListIndex]->family, false ) . \'>\' . esc_html($this->fontList[$this->fontListIndex]->family) . \' (default)</option>\' . $fontListStr;
}
// Display our list of font options
echo $fontListStr;
我一辈子都不知道如何在不破坏输出的情况下逃离最后一行代码。事实上,我不明白为什么我需要这样做,因为我避开了前面提到的所有潜在漏洞。
你能帮我妥善地避开这件事吗。谢谢