function aheadzen_wp_mail_filter($args)
{
    global $wpdb;
    $debug_trace = debug_backtrace();
    if ($debug_trace) {
        foreach ($debug_trace as $key => $val) {
            if (strstr($val['function'], 'wp_mail')) {
                $type = $function = $debug_trace[$key + 1]['function'];
                if (is_admin()) {
                    $file = $debug_trace[$key]['file'];
                } else {
                    $file = $debug_trace[$key + 1]['file'];
                }
                if (!$file) {
                    $file = $debug_trace[$key]['file'];
                }
                $file_arr = explode('\\', $file);
                if (count($file_arr) <= 1) {
                    $file_arr = explode('/', $file);
                }
                $content_key = array_search('wp-content', $file_arr);
                $includes_key = array_search('wp-includes', $file_arr);
                if ($content_key) {
                    $component = $file_arr[$content_key + 2];
                    //component name
                } elseif ($includes_key) {
                    $component = $file_arr[$includes_key + 2];
                    //component name
                    if (!$component) {
                        $file_arr = explode('\\', $val['file']);
                        $content_key = array_search('wp-content', $file_arr);
                        $component = $file_arr[$content_key + 2];
                        break;
                    } else {
                        $component = $file_arr[$content_key + 2];
                        //component name
                    }
                }
                $headers = $args['headers'];
                $headers_arr1 = explode('From:', $headers);
                $from_data = trim($headers_arr1[1]);
                $str = strpos($from_data, '<') + 1;
                $end = strpos($from_data, '>') - $str;
                $from_email = substr($from_data, $str, $end);
                $emails_arr = array();
                if ($from_email) {
                    $user_email_ids = '"' . $from_email . '","' . $args['to'] . '"';
                    $res = $wpdb->get_results("select ID,user_email from {$wpdb->users} where user_email in ({$user_email_ids})");
                    foreach ($res as $resobj) {
                        $emails_arr[$resobj->user_email] = $resobj->ID;
                    }
                }
                $from_user_id = $emails_arr[$from_email];
                $to_user_id = $emails_arr[$args['to']];
                if (!$from_user_id) {
                    global $current_user;
                    $from_user_id = $current_user->ID;
                }
                $args = array('user_id' => $from_user_id, 'from_email' => $from_email, 'item_id' => $to_user_id, 'to_email' => $args['to'], 'component' => $component, 'type' => $type, 'action' => $args['subject'], 'content' => $args['message']);
                $theid = my_log_add($args);
            }
        }
    }
    return $args;
}
Пример #2
0
 public function sendEmail($to, $subject, $message, $log = array())
 {
     $defaults = array('from_id' => 1, 'to_id' => 1, 'type' => 'unknown');
     $r = wp_parse_args($log, $defaults);
     extract($r, EXTR_SKIP);
     if (wp_mail($to, $subject, $message)) {
         my_log_add(array('user_id' => $from_id, 'action' => $subject, 'content' => $message, 'component' => 'email', 'item_id' => $to_id, 'type' => $type));
         return true;
     }
     return false;
 }