comment_post (if comment is approved OR $comment_approved === 1) not working?
I am working on a code through which I can send emails to the user when his/her comments get approved. then I get to know about comment_post. but it is not working.
comment_post is working for the condition in which user adds a new comment it sends the mail but not when the comment get approved..
#Means ($comment_approved === 1) is not working. here is my current and same code as I found on the internet -
function show_message_function( $comment_ID, $comment_approved ) {
if ( $comment_approved === 1 ) { // $comment_approved === 0 is working when to send email whenever user insert a new comment
$message = The Message I'd like to send back to the commenter;
$comment=get_comment($comment_ID);
$mailTo = $comment-comment_author_email ;
$subject = sprintf( 'Your comment is approved, comment by: %s', $comment-comment_author.$comment-comment_author_email );
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail($mailTo, $subject, $message, $headers);
}
}
add_action( 'comment_post', 'show_message_function', 10, 2 );
What I have tried
tried using wp_get_comment_status()
function show_message_function( $comment_ID, $comment_approved ) {
$status = wp_get_comment_status( $comment_id );
if ( 'approved' === $status ) {
$message = The Message I'd like to send back to the commenter; $comment=get_comment($comment_ID);
$mailTo = $comment-comment_author_email ;
$subject = sprintf( 'New Comment by: %s', $comment-comment_author.$comment-comment_author_email );
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail($mailTo, $subject, $message, $headers);
}
}
add_action( 'comment_post', 'show_message_function', 10, 2 );
tried replacing '===' with '=' '==' (single and double equals symbols) [when added single equal symbol ($comment_approved = 1), it sends mail when user enteres/submits a comment but not on approval]
function show_message_function( $comment_ID, $comment_approved ) { if ( $comment_approved = 1 ) { // tried double equal symbols also.
$message = The Message I'd like to send back to the commenter;
$comment=get_comment($comment_ID);
$mailTo = $comment-comment_author_email ;
$subject = sprintf( 'Your comment is approved, comment by: %s', $comment-comment_author.$comment-comment_author_email );
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail($mailTo, $subject, $message, $headers);
}
}
add_action( 'comment_post', 'show_message_function', 10, 2 );