wp_list_comments reply-link抛出Uncaught TypeError

时间:2018-03-02 16:41:35

标签: javascript php wordpress

使用wp_list_comments时,我遇到了一些意想不到的行为。

生成的链接:

<a rel="nofollow" class="comment-reply-link" href="http://localhost/mypost/?replytocom=2#respond" onclick="return addComment.moveForm( &quot;div-comment-2&quot;, &quot;2&quot;, &quot;respond&quot;, &quot;9&quot; )" aria-label="reply to NAME">Reply</a>

当我点击回复链接时,JavaScript控制台会抛出错误:

期待单击回复按钮时,textarea将显示在当前评论下。

Uncaught TypeError: Cannot read property 'getElementsByTagName' of null
    at Object.moveForm (comment-reply.min.js?ver=4.9.4:1)
    at HTMLAnchorElement.onclick (VM18269:489)

现在出乎意料的行为。我正在使用Plugin AdvancedCustomFields。当我禁用插件时,会抛出以下错误:

Uncaught ReferenceError: addComment is not defined
    at HTMLAnchorElement.onclick (VM18404:489)

要解决此特定问题,我尝试手动添加comment-reply.js

的functions.php

// enable reply to comments 
function theme_queue_js(){
if ( (!is_admin()) && is_singular() && comments_open() && get_option('thread_comments') )
  wp_enqueue_script( 'comment-reply' );
}
add_action('wp_enqueue_scripts', 'theme_queue_js');

然而,这并没有像预期的那样对脚本进行排队。仍在抛出Uncaught ReferenceError(注意ACF插件仍然被禁用)。

的comments.php

    <ul id="comments">
    <?php wp_list_comments(array(
        'walker'            => null,
        'max_depth'         => '',
        'style'             => 'ul',
        'callback'          => null,
        'end-callback'      => null,
        'type'              => 'comment',
        'reply_text'        => 'Reply',
        'page'              => '',
        'per_page'          => '',
        'avatar_size'       => 32,
        'reverse_top_level' => null,
        'reverse_children'  => '',
        'format'            => 'html5', // or 'xhtml' if no 'HTML5' theme support
        'short_ping'        => false,   // @since 3.6
        'echo'              => true     // boolean, default is true
    )); ?>
    </ul>

一些或多或少有用的信息:

  • 我正在使用comment-list主题支持
  • 我已清除缓存
  • 我使用过多个其他浏览器(登录并退出)
  • 抛出没有其他javascript错误

我已经做了相当多的研究。我也偶然发现了LastPass扩展导致上述错误的情况。但遗憾的是,给定的解决方案(禁用和/或从扩展程序注销)并没有解决我的问题。

1 个答案:

答案 0 :(得分:0)

解决方案(至少对我而言)是添加comment_form()

我成功地监督了这个简单的功能几个小时。

<div id="comments">
<ul>
    <?php wp_list_comments(array(
        'walker'            => null,
        'max_depth'         => '',
        'style'             => 'ul',
        'callback'          => null,
        'end-callback'      => null,
        'type'              => 'comment',
        'reply_text'        => 'Reply',
        'page'              => '',
        'per_page'          => '',
        'avatar_size'       => 32,
        'reverse_top_level' => null,
        'reverse_children'  => '',
        'format'            => 'html5', // or 'xhtml' if no 'HTML5' theme support
        'short_ping'        => false,   // @since 3.6
        'echo'              => true     // boolean, default is true
    )); ?>
</ul>

<?php comment_form(); ?>