I need to send 2 emails, when new comment is posted and when new comment is approved. Site is multilingual and uses qtranslate-x plugin.
Here is code, which sends email when comment is posted. In this case 'get_the_title($post->ID)' returns post title on one language as expected.
function kvkoolitus_email_comment_posted( $comment_ID, $comment_approved ) {
if( 0 === $comment_approved ){
$comment = get_comment( $comment_ID );
$post = get_post( $comment->comment_post_ID );
$blog_mail = get_option('admin_email');
$comment_text = $comment->comment_content;
$email = $comment->comment_author_email;
$to = $blog_mail;
$from = 'KVKoolituskeskus <' . $blog_mail . '>';
$subject = "KV Koolitused - Registreeru koolitusele";
$message = '<html><body>';
$message .= '<p>' . get_the_title($post->ID) . '</p>';
$message .= '</body></html>';
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-to: " . $from . "\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8";
mail($to, $subject, $message, $headers);
}
}
add_action( 'comment_post', 'kvkoolitus_email_comment_posted', 10, 2 );
Here is code, which sends email when comment is approved. In this case
'get_the_title($post->ID)' returns full post title formated like this: '[:en]Title in English[:ru]Title in Russian'.
function kvkoolitus_email_comment_approved($new_status, $old_status, $comment) {
if($old_status != $new_status) {
if($new_status == 'approved') {
$post = get_post( $comment->comment_post_ID );
$name = $comment->comment_author;
$comment_mail = $comment->comment_author_email;
$blog_mail = get_option('admin_email');
$to = $blog_mail;
$from = 'KVKoolituskeskus <' . $comment_mail . '>';
$subject = "Comment approved on - " . get_the_title($post->ID);
$message = '<html><body>';
$message .= '<p>'. get_the_title($post->ID) . '</p>';
$message .= '</body></html>';
$headers = "From: ".$from."\r\n";
$headers .= "Reply-to: ".$from."\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8";
mail($to, $subject, $message, $headers);
}
}
}
add_action('transition_comment_status', 'kvkoolitus_email_comment_approved', 10, 3);
Is there a way to get post title on one language using locale?