3

So not sure if i have missed something but awaiting comments dont have a own class, so is there a way to add in a simple way a custom class to comments that are awaiting moderation so that I can style there comments with CSS.

1

Here's one way to add a custom .wpse-comment-awaiting-moderation comment class through the comment_class filter:

add_filter( 'comment_class', 'wpse_259326_comment_classes', 10, 5 );

function wpse_259326_comment_classes ( $classes, $class, $comment_ID, $comment, $post_id )
{
    if( 'unapproved' === wp_get_comment_status( $comment ) && is_array( $classes ) )
        $classes[] = 'wpse-comment-awaiting-moderation';

    return $classes;
}

where we used that wp_get_comment_status( $comment ) returns 'unapproved' for unappproved comments.

  • this outputs a error: Warning: join() [function.join]: Invalid arguments passed in C:\wamp\www\xxxxxx\wp-includes\comment-template.php on line 430 i am using wp_list_comments() to outpu the comments – user759235 Mar 8 '17 at 14:55
  • strange, I don't see any obvious problems with the snippet. I just tested this on a default theme without an error and it worked there. @user759235 – birgire Mar 8 '17 at 15:22
  • Sounds like your get_comment_class() is returning a string instead of an array? Do you have another filters in place? What PHP are you using? – birgire Mar 8 '17 at 15:31
  • php 5.3.0 with wp 4.7.2 and no other files or code – user759235 Mar 8 '17 at 15:38
  • 1
    okay not sure why, but it now works....thanks!!!! – user759235 Mar 8 '17 at 15:55

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.