0

I need some customization of WORDPRESS comment area, so I've used this code in my child theme :

    <div id="comments" class="x-comments-area">

    <?php if ( have_comments() ) : ?>

    <?php
    //The author of current post
    $author_ID = get_the_author_meta("ID");
    //The current post ID
    $p_ID = get_the_ID();
    ?>

    <h2 class="h-comments-title"><span><?php _e( 'Comments' , '__x__' ); ?>  <small>
    <?php 
    //Number of guest comments
    echo ztjalali_persian_num(number_format_i18n(count(get_comments(array('post_id' => $p_ID,'author__not_in' => array($author_ID))))));
 ?></small></span></h2>
    <ol class="x-comments-list">
    <?php
    wp_list_comments( array(
    'callback' => 'x_icon_comment',
    'style'    => 'ol'
  ) );
  ?>
    </ol>

    <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
    <nav id="comment-nav-below" class="navigation" role="navigation">
    <h1 class="visually-hidden"><?php _e( 'Comment navigation', '__x__' ); ?></h1>
    <div class="nav-previous"><?php previous_comments_link( __( '&larr; Older Comments', '__x__' ) ); ?></div>
    <div class="nav-next"><?php next_comments_link( __( 'Newer Comments &rarr;', '__x__' ) ); ?></div>
    </nav>
    <?php endif; ?>

    <?php if ( ! comments_open() && get_comments_number() ) : ?>
    <p class="nocomments"><?php _e( 'Comments are closed.' , '__x__' ); ?></p>
    <?php endif; ?>

    <?php endif; ?>

    <?php
//Loading of smilies
    ob_start(); cs_print_smilies(); $cs_print_smilies = ob_get_clean();
//Comment form re-arrangement
    comment_form( array(
    'comment_notes_before' => '',
    'comment_notes_after'  => '',
    'id_submit'            => 'entry-comment-submit',
    'label_submit'         => __( 'Submit' , '__x__' ),
    'title_reply'          => __( '<span>Leave a Comment</span>' , '__x__' ),
    'fields'               => array(
    'author' =>
    '<p class="comment-form-author">' .
    '<input id="author" name="author" type="text" value="' . get_comment_author()  . '" placeholder="' . __( 'Name *', '__x__' ) . ' ' . '" size="30"/>' .
    '</p>',
    'email'  =>
    '<p class="comment-form-email">' .

      '<input id="email" name="email" type="email" aria-required="true" aria-invalid="false" value="' .get_comment_author_email() . '" placeholder="' . __( 'Email *', '__x__' ) . ' ' . '" size="30"/>' .
    '</p>',
    'url'    =>
    '<p class="comment-form-url">' .

      '<input id="url" name="url" type="text" value="' . get_comment_author_url() . '" placeholder="' . __( 'URL', '__x__' ) . '" size="30" />' .
    '</p>'
),
    'comment_field' => '<p class="comment-form-comment">' .
                     '</br>'.
                      $cs_print_smilies .
                     '<textarea id="comment" name="comment" cols="45" rows="4" placeholder="' . _x( 'Comment *', 'noun', '__x__' ) . '" aria-required="true"></textarea>' .
                   '</p>'

) );
?>

    </div>

But with using above code I will have these PHP notices in my published posts, above the comments area:

Notice: Trying to get property of non-object in /home/foo/public_html/wp-includes/comment-template.php on line 28

Notice: Trying to get property of non-object in /home/foo/public_html/wp-includes/comment-template.php on line 46

Notice: Trying to get property of non-object in /home/foo/public_html/wp-includes/comment-template.php on line 97

Notice: Trying to get property of non-object in /home/foo/public_html/wp-includes/comment-template.php on line 97

Notice: Trying to get property of non-object in /home/foo/public_html/wp-includes/comment-template.php on line 296

Notice: Trying to get property of non-object in /home/foo/public_html/wp-includes/comment-template.php on line 296

Notice: Trying to get property of non-object in /home/foo/public_html/wp-includes/comment-template.php on line 309

While I know the problem is not inside of comment-template.php file.

How may I get rid of them?

0

This notice comes because object $comments is null. So the have_comments() must wrap all the thing to be sure there are comments before using any property.

in your case :

<?php if ( have_comments() ) : 
 /* the code */
endif; ?>
-1

It was about calling the fields value containers which are arrays, so:

   get_comment_author()

should change to something like this:

   $commenter['comment_author']
-2

I have same problem when i had tried to change the default location of comment form input fields this error appears so first verify it and check the condition on comment template. Also try define('WP_DEBUG', false);

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.