I have figured it out. There were a bunch of issues with the existing code.
The code wasn’t getting $author_email
appropriately which was causing it to fail and causing wp_mail()
not to fire.
add_action('comment_post', 'comment_email_notification', 11, 2);
function comment_email_notification($comment_ID, $comment_approved) {
$post_type = get_post_type();
if ($post_type !== 'jobs') {
return;
}
$comment = get_comment($comment_ID);
$post_ID = $comment->comment_post_ID;
$author_ID = get_post_field( 'post_author', $post_ID );
$author_email = get_the_author_meta( 'user_email', $author_ID );
if (isset($author_email) && is_email($author_email)) {
$message="New comment on <a href="" . get_permalink($post_ID) . '">' .
get_the_title($postid) . '</a>';
add_filter('wp_mail_content_type',
create_function('', 'return "text/html";'));
wp_mail($author_email, 'New Comment', $message);
}
}