/var/www/html_us/wp-content/plugins/woocommerce/src/Admin/ReportCSVEmail.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
 * Handles emailing users CSV Export download links.
 */

namespace Automattic\WooCommerce\Admin;

if ( ! 
defined'ABSPATH' ) ) {
    exit;
}

/**
 * Include dependencies.
 */
if ( ! class_exists'WC_Email'false ) ) {
    include_once 
WC_ABSPATH 'includes/emails/class-wc-email.php';
}

/**
 * ReportCSVEmail Class.
 */
class ReportCSVEmail extends \WC_Email {

    
/**
     * Report labels.
     *
     * @var array
     */
    
protected $report_labels;

    
/**
     * Report type (e.g. 'customers').
     *
     * @var string
     */
    
protected $report_type;

    
/**
     * Download URL.
     *
     * @var string
     */
    
protected $download_url;

    
/**
     * Constructor.
     */
    
public function __construct() {
        
$this->id             'admin_report_export_download';
        
$this->template_base  WC()->plugin_path() . '/includes/react-admin/emails/';
        
$this->template_html  'html-admin-report-export-download.php';
        
$this->template_plain 'plain-admin-report-export-download.php';
        
$this->report_labels  = array(
            
'categories' => __'Categories''woocommerce' ),
            
'coupons'    => __'Coupons''woocommerce' ),
            
'customers'  => __'Customers''woocommerce' ),
            
'downloads'  => __'Downloads''woocommerce' ),
            
'orders'     => __'Orders''woocommerce' ),
            
'products'   => __'Products''woocommerce' ),
            
'revenue'    => __'Revenue''woocommerce' ),
            
'stock'      => __'Stock''woocommerce' ),
            
'taxes'      => __'Taxes''woocommerce' ),
            
'variations' => __'Variations''woocommerce' ),
        );

        
// Call parent constructor.
        
parent::__construct();
    }

    
/**
     * This email has no user-facing settings.
     */
    
public function init_form_fields() {}

    
/**
     * This email has no user-facing settings.
     */
    
public function init_settings() {}

    
/**
     * Return email type.
     *
     * @return string
     */
    
public function get_email_type() {
        return 
class_exists'DOMDocument' ) ? 'html' 'plain';
    }

    
/**
     * Get email heading.
     *
     * @return string
     */
    
public function get_default_heading() {
        return 
__'Your Report Download''woocommerce' );
    }

    
/**
     * Get email subject.
     *
     * @return string
     */
    
public function get_default_subject() {
        return 
__'[{site_title}]: Your {report_name} Report download is ready''woocommerce' );
    }

    
/**
     * Get content html.
     *
     * @return string
     */
    
public function get_content_html() {
        return 
wc_get_template_html(
            
$this->template_html,
            array(
                
'report_name'   => $this->report_type,
                
'download_url'  => $this->download_url,
                
'email_heading' => $this->get_heading(),
                
'sent_to_admin' => true,
                
'plain_text'    => false,
                
'email'         => $this,
            ),
            
'',
            
$this->template_base
        
);
    }

    
/**
     * Get content plain.
     *
     * @return string
     */
    
public function get_content_plain() {
        return 
wc_get_template_html(
            
$this->template_plain,
            array(
                
'report_name'   => $this->report_type,
                
'download_url'  => $this->download_url,
                
'email_heading' => $this->get_heading(),
                
'sent_to_admin' => true,
                
'plain_text'    => true,
                
'email'         => $this,
            ),
            
'',
            
$this->template_base
        
);
    }

    
/**
     * Trigger the sending of this email.
     *
     * @param int    $user_id User ID to email.
     * @param string $report_type The type of report export being emailed.
     * @param string $download_url The URL for downloading the report.
     */
    
public function trigger$user_id$report_type$download_url ) {
        
$user               = new \WP_User$user_id );
        
$this->recipient    $user->user_email;
        
$this->download_url $download_url;

        if ( isset( 
$this->report_labels$report_type ] ) ) {
            
$this->report_type                   $this->report_labels$report_type ];
            
$this->placeholders['{report_name}'] = $this->report_type;
        }

        
$this->send(
            
$this->get_recipient(),
            
$this->get_subject(),
            
$this->get_content(),
            
$this->get_headers(),
            
$this->get_attachments()
        );
    }
}