我需要在发布新评论和批准新评论时发送两封电子邮件。该网站是多语言的,并使用qtranslate-x插件
下面是代码,在发布评论时发送电子邮件。在本例中,“get\\u the\\u title($post->ID)”按预期返回一种语言的帖子标题。
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 );
下面是代码,当评论获得批准时,它会发送电子邮件。在本例中,“get\\u the\\u title($post->ID)”返回格式如下的完整帖子标题:“[:en]英语标题[:ru]俄语标题”。
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);
有没有一种方法可以使用语言环境获取一种语言的帖子标题?