post_title;
$message = sprintf(__('Hello! Admin,
A new question is posted by %s
', 'ap'), ap_user_display_name($post->post_author, true));
$message .= ap_truncate_chars($post->post_content, 100);
$message .= "
".__('View question', 'ap')."
";
$message .= '
'.__('Powered by', 'ap').' AnsPress
'; //sends email wp_mail(get_option( 'admin_email' ), $subject, $message ); } } public function new_answer_email( $post_id ) { // lets check if post is not revision if ( !wp_is_post_revision( $post_id ) ) { $post = get_post($post_id); $emails = ap_get_email_to_notify($post->post_parent, $post->post_author); $parent = get_post($post->post_parent); $subject = __('New Answer on: ', 'ap'). $parent->post_title; $message = sprintf(__('Hello!,'.__('Powered by', 'ap').'AnsPress
'; //sends email if(!empty($emails)) foreach($emails as $email){ wp_mail($email, $subject, $message ); } $admin_email = get_option( 'admin_email' ); $current_user_email = get_the_author_meta( 'user_email', $post->post_author); if($admin_email != $current_user_email) wp_mail($admin_email, $subject, $message ); } } public function new_comment($comment, $post_type, $question_id){ $emails = ap_get_email_to_notify($comment->comment_post_ID, $comment->user_id); $post = get_post($question_id); if($post_type == 'question'){ $subject = __('New comment on: ', 'ap'). $post->post_title; $message = sprintf(__('Hello!,'.__('Powered by', 'ap').'AnsPress
'; if(!empty($emails)) foreach($emails as $email){ wp_mail($email, $subject, $message ); } }else{ $subject = __('New comment on answer of: ', 'ap'). $post->post_title; $message = sprintf(__('Hello!,'.__('Powered by', 'ap').'AnsPress
'; if(!empty($emails)) foreach($emails as $email){ wp_mail($email, $subject, $message ); } } } public function select_answer($user_id, $question_id, $answer_id){ $post_url = get_permalink( $question_id ); $post = get_post($post_id); $subject = __('Your answer is selected as a best', 'ap'); $message = sprintf(__('Hello!,'.__('Powered by', 'ap').' AnsPress
'; $emails = ap_get_email_to_notify($post->post_parent, $user_id); if(!empty($emails)) foreach($emails as $email){ wp_mail($email, $subject, $message ); } //sends email wp_mail(get_option( 'admin_email' ), $subject, $message ); } } function ap_get_email_to_notify($post_id, $current_user){ $parti_emails = ap_get_parti_emails($post_id); if(isset($parti_emails[$current_user])) unset($parti_emails[$current_user]); // return if no email found if(empty($parti_emails)) return false; return $parti_emails; } AP_Basic_Email_Addon::get_instance();