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(strip_tags($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); $current_user_email = get_the_author_meta( 'user_email', $post->post_author); $admin_email = get_option( 'admin_email' ); if($admin_email != $current_user_email) $emails['admin'] = $admin_email; if(empty($emails) || !$emails) return false; $emails = array_unique ($emails); $parent = get_post($post->post_parent); $subject = __('New Answer on: ', 'ap'). $parent->post_title; $message = sprintf(__('Hello!,

A new answer is posted by %s
', 'ap'), ap_user_display_name($post->post_author, true)); $message .= ap_truncate_chars(strip_tags($post->post_content), 100); $message .= "

".__('View Answer', 'ap')."
"; $message .= '

'.__('Powered by', 'ap').'AnsPress

'; if(!empty($emails)) foreach($emails as $email){ if(is_email($email)) wp_mail($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!,

A new comment is posted by %s
', 'ap'), ap_user_display_name($comment->user_id, true)); $message .= ap_truncate_chars($comment->comment_content , 100); $message .= "

".__('View comment', 'ap')."
"; $message .= '

'.__('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!,

A new comment is posted by %s
', 'ap'), ap_user_display_name($comment->user_id, true)); $message .= ap_truncate_chars($comment->comment_content , 100); $message .= "

".__('View comment', 'ap')."
"; $message .= '

'.__('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!,

You answer on %s is selected as best by %s
', 'ap'), $pos->post_title, ap_user_display_name($user_id, true)); $message .= "

".__('View question', 'ap')."
"; $message .= '

'.__('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();