rveitch
11/3/2015 - 5:57 PM

Recent Comments Widget Post Author/Commenter Validation

Recent Comments Widget Post Author/Commenter Validation

<?php

foreach( $recent_comments as $recent_comment ) {
  
  /* Get the Post Author */
  $post_id = $recent_comment->comment_post_ID; // Returns ID for the Post the Comment was made on
  $post_author_id = get_post_field( 'post_author', $post_id ); //Returns Post Author ID

  /* Get the Commenter */
  $commenter_email = $recent_comment->comment_author_email;
  $comment_user = get_user_by( 'email', $commenter_email );
  $comment_author_id = $comment_user->ID;

  /* Compare the IDs */
  if ( $comment_author_id == $post_author_id ) {
    //Do something if Bob
  } else {
    //Do something else if NOT BOB
  }
  
}// end for