1

I built my callback function using class-walker-comment.php as a reference and am at a loss as to why it's not working. Any help is greatly appreciated.

The issues I'm encountering are:

1) Avatars don't display.

2) This error displays above every comment:

Warning: array_merge() [function.array-merge]: Argument #1 is not an array

The error appears to be the result of this bit of code in my function:

comment_reply_link(array_merge

Here's the full callback function I'm using:

function custom_comment( $comment, $depth, $args ) { 

$tag = ( 'div' === $args['style'] ) ? 'div' : 'li'; ?>

<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $args['has_children'] ? 'parent' : '', $comment ); ?>>

    <article id="div-comment-<?php comment_ID(); ?>" class="comment-inner">
    <div class="comment-header"> 

    <?php  
    if ( 0 != $args['avatar_size'] ) { ?>

        <div class="comment-avatar">
            <?php echo get_avatar( $comment, $args['avatar_size'] ); ?>
        </div>

    <?php } ?>

        <div class="comment-meta-wrap">
        <div class="comment-author vcard">
            <!--  translators: %s: comment author link -->
            <?php printf(   __( '%s <span class="says">says:</span>' ), sprintf( '<b class="fn">%s</b>', get_comment_author_link( $comment ) ) ); ?>
        </div><!-- .comment-author -->

        <div class="comment-meta commentmetadata">

        <a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
        <time datetime="<?php comment_time( 'c' ); ?>">
        <!-- translators: 1: comment date, 2: comment time -->
            <?php printf( __( '%1$s at %2$s' ), get_comment_date( '', $comment ), get_comment_time() ); ?>
        </time>
        </a>

        <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>

        </div><!-- .comment-meta -->

        </div><!-- .comment-meta-wrap -->

        </div><!-- .comment-header --> <div class="clearboth"></div>

        <div class="comment-content">

        <?php if ( '0' == $comment->comment_approved ) : ?>
            <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p>
        <?php endif; ?>

            <?php comment_text(); ?>

        </div><!-- .comment-content -->

        <?php
        comment_reply_link(
            array_merge(
                $args, array(
                    'add_below' => 'div-comment',
                    'depth'     => $depth,
                    'max_depth' => $args['max_depth'],
                    'before'    => '<div class="reply">',
                    'after'     => '</div>',
                )
            )
        ); ?>

        </article><!-- .comment-inner -->

And here's my comments.php:

<?php
// You can start editing here -- including this comment!
if ( have_comments() ) :
?>
    <h2 class="comments-title">
        <?php
        $comments_number = get_comments_number();
        if ( '1' === $comments_number ) {
            /* translators: %s: post title */
            printf( _x( 'One Reply to &ldquo;%s&rdquo;', 'comments title', 'textdomain' ), get_the_title() );
        } else {
            printf(
                /* translators: 1: number of comments, 2: post title */
                _nx(
                    '%1$s Reply to &ldquo;%2$s&rdquo;',
                    '%1$s Replies to &ldquo;%2$s&rdquo;',
                    $comments_number,
                    'comments title',
                    'textdomain'
                ),
                number_format_i18n( $comments_number ),
                get_the_title()
            );
        }
        ?>
    </h2>

    <ol class="comment-list">
        <?php
            wp_list_comments(
                array(
                    'avatar_size' => 100,
                    'style'       => 'ol',
                    'callback'    => 'custom_comment',
                    'short_ping'  => true,
                )
            );
        ?>
    </ol>

    <?php
    the_comments_pagination(
        array(
            'prev_text' => '<span class="screen-reader-text">' . __( 'Previous', 'textdomain' ) . '</span>',
            'next_text' => '<span class="screen-reader-text">' . __( 'Next', 'textdomain' ) . '</span>',
        )
    );

endif; // Check for have_comments().

// If comments are closed and there are comments, let's leave a little note, shall we?
if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :
?>

    <p class="no-comments"><?php _e( 'Comments are closed.', 'textdomain' ); ?></p>
<?php
endif;

comment_form();
?>

1

Did you try var_dump on the array_merge & avatar parameters? That would tell you if the variables are what you expect.

Anyway - it looks like you have the parameter order wrong.

You are using

custom_comment( $comment, $depth, $args )

but it should be

custom_comment( $comment, $args, $depth )

Hope that helps

| improve this answer | |
  • I think that would do it! Can also be avoided if task is done with a custom comment Walker object instead of a callback. – CK MacLeod Jul 15 '18 at 20:02
  • I can't believe that's what the issue ended up being! Thank You(!) for taking the time to come over.. I really appreciate it. – J. Amy Jul 18 '18 at 0:12
  • No worries - I'm sure we have all done similar things at one time or another, I know I have! :) – BinaryMoon Jul 19 '18 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.