/var/www/html_us/wp-content/plugins/wp-smtp/inc/Logger/Process.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

namespace WPSMTP\Logger;

use 
SolidWP\Mail\Admin\SettingsScreen;
use 
WP_Error;
use 
WPSMTP\Admin;

class 
Process {

    private 
$mail_id;
    private 
$wsOptions;

    
/**
     * The new solid mail settings.
     *
     * @var false|mixed|null
     */
    
private $solidMailOptions;

    public function 
__construct() {
        
$this->wsOptions get_option'wp_smtp_options' );

        
$this->solidMailOptions get_optionSettingsScreen::SETTINGS_SLUG );

        if ( ! isset( 
$this->solidMailOptions['disable_logs'] ) || 'yes' !== $this->solidMailOptions['disable_logs'] ) {
            
add_filter'wp_mail', [ $this'log_mails' ], PHP_INT_MAX );
        }

        
add_action'wp_mail_failed', [ $this'update_failed_status' ], PHP_INT_MAX );
    }

    public function 
log_mails$parts ) {

        
$data $parts;

        unset( 
$data['attachments'] );

        
$this->mail_id Db::get_instance()->insert$data );

        return 
$parts;
    }

    
/**
     * @param WP_Error $wp_error
     */
    
public function update_failed_status$wp_error ) {

        
Admin::$phpmailer_error $wp_error;

        if ( ! isset( 
$this->wsOptions['disable_logs'] ) || 'yes' !== $this->wsOptions['disable_logs'] ) {

            
$data $wp_error->get_error_data'wp_mail_failed' );

            unset( 
$data['phpmailer_exception_code'] );
            unset( 
$data['attachments'] );

            
$data['error'] = $wp_error->get_error_message();

            if ( ! 
is_numeric$this->mail_id ) ) {
                
Db::get_instance()->insert$data );
            } else {
                
Db::get_instance()->update$data, [ 'mail_id' => $this->mail_id ] );
            }
        }
    }
}