admin管理员组

文章数量:1279237

I moved a wordpress installation from one server to another. I dumped the DB, copied over all the files, put all DB data into a new database, changed wp-config.php to the new database info, and after the DNS servers agreed to point the domain to the new ip, the site seemed to work fine. also, I moved the wordpress installation from www.domain.tld/WP/ one folder up to www.domain.tld (without the WP subfolder), a day or two later, and that also worked fine. I then noticed that all comments do not show up. I know the following:

  • Comments worked before the move.
  • All old and new comments are still there in the backend.
  • The line "2 comments for Post Title" is still generated correctly.
  • The comments do not show up at all, the generated html looks like this:
        <ol class="commentlist">
            <ul class="children">
</li><!-- #comment-## -->
</ul><!-- .children -->
</li><!-- #comment-## -->
        </ol><!-- mentlist -->
  • The form to write a new comment does show up, and it works, users can write a comment, it gets queued for review, the author of the post gets an email and can allow or disallow the comment, answer it, just as usual. The comment count on that post then goes up ("3 comments for...") but the comments still won't show up.

There is no output at all in the debug log.

Any ideas on how to fix this?

EDIT: I fixed it. It was a problem with the theme, "Destin Basic". If anyone else has that problem: in functions.php, in the function bavotasan_comment on line 382 replace (or add to)

case '' :

with

case 'comment' :

To repair the issue.

More Information: I am guessing at the moment that there is a wordpress update which changed functionality, though that is unlikely in some way too - I did not investigate. After examining, the problem boils down to the following: The theme does not use the wordpress standard comment output, but it uses a callback function called bavotasan_comment which gets called for each comment. This function decides from the current comment type if it is a comment (and displays it as a a comment) or a pingback/trackback (which is displayed differently). it does that by a switch:

switch ( $comment->comment_type ) :

which has the three allowed values '', 'pingback', 'trackback' while '' seems to stand for "comment". but in my case, $comment->comment_type is 'comment' so the function simply falls through and does not output anything at all. As there is no error, no debug output is written.

While it is obvious that bavotasan_comment could be easily made with a default case for handling "unkown" comment types, I have no idea if comment->comment_type always was comment for a normal comment or if this is something new in a recent update, which I somewhat doubt too while it is my best guess at the moment. I can say for sure that it is reproducable in my case, even after disabling all plugins.

Also, I seem to be not the only one having trouble with this. These people here simply removed the callback function alltogether to resolve it:

/

The post is about a month old, so there might be some update to wordpress breaking this functionality.

edit: It was not an update. I have no idea why this worked in the first place.

For the interested, here is the relevant part of functions.php including my fix at the beginning:

<?php /* this line is added by me for the syntax highlighter */
function bavotasan_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case '' :
case 'comment' :
    ?>
    <li <?php comment_class(); ?>>
        <div id="comment-<?php comment_ID(); ?>" class="comment-body">
            <div class="comment-avatar">
                <?php echo get_avatar( $comment, 55 ); ?>
            </div>
            <div class="comment-content">
                <div class="comment-author">
                    <?php echo get_comment_author_link() . ' '; ?>
                </div>
                <div class="comment-meta">
                    <?php
                    printf( __( '%1$s at %2$s', 'destin-basic' ), get_comment_date(), get_comment_time() );
                    edit_comment_link( __( 'Edit', 'destin-basic' ), '  ', '' );
                    ?>
                </div>
                <div class="comment-text">
                    <?php if ( '0' == $comment->comment_approved ) { echo '<em>' . __( 'Your comment is awaiting moderation.', 'destin-basic' ) . '</em>'; } ?>
                    <?php comment_text() ?>
                </div>
                <?php if ( $args['max_depth'] != $depth && comments_open() && 'pingback' != $comment->comment_type ) { ?>
                <div class="reply">
                    <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
                </div>
                <?php } ?>
            </div>
        </div>
        <?php
        break;

case 'pingback'  :
case 'trackback' :
    ?>
    <li id="comment-<?php comment_ID(); ?>" class="pingback">
        <div class="comment-body">
            <i class="fa fa-paperclip"></i>
            <?php _e( 'Pingback:', 'destin-basic' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(edit)', 'destin-basic' ), ' ' ); ?>
        </div>
        <?php
        break;
endswitch;
}

本文标签: Comments invisible after moving Wordpress to new serverwhile commenting still works