我正在創建自己的 WordPress Bootstrap 主題并遇到了一個奇怪的問題。
當我提交評論并等待審核時,comment_text()不會輸出任何<p>標簽。
我嘗試禁用所有插件并重命名我的functions.php檔案,但問題仍然存在。
我的代碼:
<div ><?php comment_text(); ?></div>
批準的評論(有<p>標簽):
<div id="comment-10" class="comment even thread-even depth-1 media">
<div class="d-flex mt-2 p-2 border rounded">
<div class="flex-grow-1 ms-3">
<div class="author">Barry says</div>
<div class="small"><a href="https://example.com/test/#comment-10" class="text-decoration-none">September 11, 2022 at 8:06 am</a></div>
<div class="comment-content my-4"><p>Testing to see how this comment looks</p></div>
等待審核(無<p>標簽):
<div id="comment-59" class="comment even thread-even depth-1 media">
<div class="d-flex mt-2 p-2 border rounded">
<div class="flex-grow-1 ms-3">
<div class="author">Dave says</div>
<div class="small"><a href="https://example.com/test/#comment-59" class="text-decoration-none">October 5, 2022 at 8:14 pm</a></div>
<p class="card-text comment-awaiting-moderation label label-info text-muted">Your comment is awaiting moderation.</p>
<div class="comment-content my-4">ok how does this look</div>
此外,當我啟用訂閱評論重新加載插件時,評論看起來像這樣:
<div id="comment-63" class="comment even thread-even depth-1 media">
<div class="d-flex mt-2 p-2 border rounded">
<div class="flex-grow-1 ms-3">
<div class="author">Ken says</div>
<div class="small"><a href="https://example.com/test/#comment-63" class="text-decoration-none">October 5, 2022 at 8:45 pm</a></div>
<p class="card-text comment-awaiting-moderation label label-info text-muted">Your comment is awaiting moderation.</p>
<div class="comment-content my-4">Check your email to confirm your subscription.
Ok this doesn't look right
</div>
查看插件的源代碼,他們還<p>為他們的訊息添加了標簽,但這些標簽也被洗掉了。
我不知道問題可能是什么。有什么建議么?
uj5u.com熱心網友回復:
我終于找到了解決問題的方法。
默認情況下,WordPress 函式會去除所有標簽(標簽未列在“$allowedtags”陣列中)wp_kses。Walker_Comment::filter_comment_text()<p><p>
https://github.com/WordPress/wordpress-develop/blob/6.0.2/src/wp-includes/kses.php#L379-L413
為了解決這個問題,我只想<p>在評論中允許標簽,所以我在我的Bootstrap_Comment_Walker extends Walker_Comment類中添加了以下函式:
public function filter_comment_text( $comment_text, $comment )
{
$allowedtags = array(
'p' => array(),
);
return wp_kses( $comment_text, $allowedtags );
}
現在一切都按預期作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/517405.html
