/** * Hook called after comment is posted. */ public function comment_post($id, $status = NULL) { global $wpdb; $comment = get_comment($id); $status = $status ? (string) $status : $comment->comment_approved; $is_live = TRUE; // comment deleted? if (!$comment) { $is_live = FALSE; } else { // don't process pingbacks and other non-comments... if ($comment->comment_type !== "") { $is_live = FALSE; } // make sure comment is approved (i.e. not deleted & not spam): //if ($comment->comment_approved !== "1") { // $is_live = FALSE; //} if ($status !== "approve" && $status !== "1") { $is_live = FALSE; } $post = get_post($comment->comment_post_ID); if (!$post) { // post deleted $is_live = FALSE; } else { if ($post->post_status == "bbpp-thankmelater-pv") { // not a real post -- used for previews $is_live = FALSE; } } // check whether user has opted out of emails $opt_out_row = $wpdb->get_row($wpdb->prepare("\r\n\t\t\t\tSELECT `email` FROM `{$wpdb->prefix}bbpp_thankmelater_opt_outs`\r\n\t\t\t\tWHERE `email` = %s\r\n\t\t\t", $comment->comment_author_email)); if ($opt_out_row !== NULL) { $is_live = FALSE; } } if ($is_live) { // schedule the messages to be sent for this comment. $message = new Bbpp_ThankMeLater_Message(); $message->scheduleMessages($comment); } else { // remove any scheduled mails, this comment has been spammed or trashed $schedule = new Bbpp_ThankMeLater_Schedule(); $schedule->readUnsent($id); $schedule->delete(); } }