简体   繁体   English

Wordpress comment_text() 缺失<p>标签</p>

[英]Wordpress comment_text() missing <p> tags

I'm creating my own WordPress Bootstrap theme and have run in to a strange issue.我正在创建自己的 WordPress Bootstrap 主题并遇到了一个奇怪的问题。

When I submit a comment and it's waiting for moderation, comment_text() does not output any <p> tags.当我提交评论并等待审核时, comment_text()不会 output 任何<p>标签。

I've tried disabling all the plugins and renaming my functions.php file and the issue persists.我试过禁用所有插件并重命名我的functions.php文件,问题仍然存在。

My code:我的代码:

<div class="comment-content my-4"><?php comment_text(); ?></div>

Approved comment ( has <p> tags ):批准的评论(有<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>

Waiting for moderation ( no <p> tags ):等待审核(无<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>

Also, when I enable the subscribe to comments reloaded plugin, the comment looks like this:此外,当我启用订阅评论重新加载插件时,评论如下所示:

<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>

Looking at the source code for the plugin, they also add <p> tags for their message, but those are getting removed as well.查看插件的源代码,他们还为消息添加了<p>标签,但这些标签也被删除了。

I'm at a loss to what the issue could be.我不知道问题可能是什么。 Any suggestions?有什么建议么?

I finally found the solution to the problem.我终于找到了解决问题的方法。

The WordPress function wp_kses in Walker_Comment::filter_comment_text() strips all <p> tags by default ( <p> tag is not listed in the "$allowedtags" array). wp_kses Walker_Comment::filter_comment_text()中的 WordPress function wp_kses 默认去除所有<p>标签( <p>标签未列在“$allowedtags”数组中)。

https://github.com/WordPress/wordpress-develop/blob/6.0.2/src/wp-includes/kses.php#L379-L413 https://github.com/WordPress/wordpress-develop/blob/6.0.2/src/wp-includes/kses.php#L379-L413

To solve this issue, I only wanted to allow <p> tags in comments so I added the following function inside my Bootstrap_Comment_Walker extends Walker_Comment class:为了解决这个问题,我只想在评论中允许<p>标签,所以我在我的Bootstrap_Comment_Walker extends Walker_Comment class 中添加了以下 function:

public function filter_comment_text( $comment_text, $comment )
{
    $allowedtags = array(
            'p' => array(),
    );
    return wp_kses( $comment_text, $allowedtags );
}

Everything is working as expected now.现在一切都按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM