Completed
Branch BUG/fix-wonky-conditional-in-s... (281b74)
by
unknown
26:43 queued 18:29
created
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.81.rc.008');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.81.rc.008');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Email_messenger.class.php 1 patch
Indentation   +644 added lines, -644 removed lines patch added patch discarded remove patch
@@ -6,648 +6,648 @@
 block discarded – undo
6 6
 class EE_Email_messenger extends EE_messenger
7 7
 {
8 8
 
9
-    /**
10
-     * To field for email
11
-     * @var string
12
-     */
13
-    protected $_to = '';
14
-
15
-
16
-    /**
17
-     * CC field for email.
18
-     * @var string
19
-     */
20
-    protected $_cc = '';
21
-
22
-    /**
23
-     * From field for email
24
-     * @var string
25
-     */
26
-    protected $_from = '';
27
-
28
-
29
-    /**
30
-     * Subject field for email
31
-     * @var string
32
-     */
33
-    protected $_subject = '';
34
-
35
-
36
-    /**
37
-     * Content field for email
38
-     * @var string
39
-     */
40
-    protected $_content = '';
41
-
42
-
43
-    /**
44
-     * constructor
45
-     *
46
-     * @access public
47
-     */
48
-    public function __construct()
49
-    {
50
-        // set name and description properties
51
-        $this->name                = 'email';
52
-        $this->description         = sprintf(
53
-            esc_html__(
54
-                'This messenger delivers messages via email using the built-in %s function included with WordPress',
55
-                'event_espresso'
56
-            ),
57
-            '<code>wp_mail</code>'
58
-        );
59
-        $this->label               = array(
60
-            'singular' => esc_html__('email', 'event_espresso'),
61
-            'plural'   => esc_html__('emails', 'event_espresso'),
62
-        );
63
-        $this->activate_on_install = true;
64
-
65
-        // we're using defaults so let's call parent constructor that will take care of setting up all the other
66
-        // properties
67
-        parent::__construct();
68
-    }
69
-
70
-
71
-    /**
72
-     * see abstract declaration in parent class for details.
73
-     */
74
-    protected function _set_admin_pages()
75
-    {
76
-        $this->admin_registered_pages = array(
77
-            'events_edit' => true,
78
-        );
79
-    }
80
-
81
-
82
-    /**
83
-     * see abstract declaration in parent class for details
84
-     */
85
-    protected function _set_valid_shortcodes()
86
-    {
87
-        // remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
88
-        // message type.
89
-        $this->_valid_shortcodes = array(
90
-            'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
91
-            'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
92
-            'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
93
-        );
94
-    }
95
-
96
-
97
-    /**
98
-     * see abstract declaration in parent class for details
99
-     *
100
-     * @access protected
101
-     * @return void
102
-     */
103
-    protected function _set_validator_config()
104
-    {
105
-        $valid_shortcodes = $this->get_valid_shortcodes();
106
-
107
-        $this->_validator_config = array(
108
-            'to'            => array(
109
-                'shortcodes' => $valid_shortcodes['to'],
110
-                'type'       => 'email',
111
-            ),
112
-            'cc' => array(
113
-                'shortcodes' => $valid_shortcodes['to'],
114
-                'type' => 'email',
115
-            ),
116
-            'from'          => array(
117
-                'shortcodes' => $valid_shortcodes['from'],
118
-                'type'       => 'email',
119
-            ),
120
-            'subject'       => array(
121
-                'shortcodes' => array(
122
-                    'organization',
123
-                    'primary_registration_details',
124
-                    'event_author',
125
-                    'primary_registration_details',
126
-                    'recipient_details',
127
-                ),
128
-            ),
129
-            'content'       => array(
130
-                'shortcodes' => array(
131
-                    'event_list',
132
-                    'attendee_list',
133
-                    'ticket_list',
134
-                    'organization',
135
-                    'primary_registration_details',
136
-                    'primary_registration_list',
137
-                    'event_author',
138
-                    'recipient_details',
139
-                    'recipient_list',
140
-                    'transaction',
141
-                    'messenger',
142
-                ),
143
-            ),
144
-            'attendee_list' => array(
145
-                'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
146
-                'required'   => array('[ATTENDEE_LIST]'),
147
-            ),
148
-            'event_list'    => array(
149
-                'shortcodes' => array(
150
-                    'event',
151
-                    'attendee_list',
152
-                    'ticket_list',
153
-                    'venue',
154
-                    'datetime_list',
155
-                    'attendee',
156
-                    'primary_registration_details',
157
-                    'primary_registration_list',
158
-                    'event_author',
159
-                    'recipient_details',
160
-                    'recipient_list',
161
-                ),
162
-                'required'   => array('[EVENT_LIST]'),
163
-            ),
164
-            'ticket_list'   => array(
165
-                'shortcodes' => array(
166
-                    'event_list',
167
-                    'attendee_list',
168
-                    'ticket',
169
-                    'datetime_list',
170
-                    'primary_registration_details',
171
-                    'recipient_details',
172
-                ),
173
-                'required'   => array('[TICKET_LIST]'),
174
-            ),
175
-            'datetime_list' => array(
176
-                'shortcodes' => array('datetime'),
177
-                'required'   => array('[DATETIME_LIST]'),
178
-            ),
179
-        );
180
-    }
181
-
182
-
183
-    /**
184
-     * @see   parent EE_messenger class for docs
185
-     * @since 4.5.0
186
-     */
187
-    public function do_secondary_messenger_hooks($sending_messenger_name)
188
-    {
189
-        if ($sending_messenger_name === 'html') {
190
-            add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
191
-        }
192
-    }
193
-
194
-
195
-    public function add_email_css(
196
-        $variation_path,
197
-        $messenger,
198
-        $message_type,
199
-        $type,
200
-        $variation,
201
-        $file_extension,
202
-        $url,
203
-        EE_Messages_Template_Pack $template_pack
204
-    ) {
205
-        // prevent recursion on this callback.
206
-        remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
207
-        $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
208
-
209
-        add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
210
-        return $variation;
211
-    }
212
-
213
-
214
-    /**
215
-     * See parent for details
216
-     *
217
-     * @access protected
218
-     * @return void
219
-     */
220
-    protected function _set_test_settings_fields()
221
-    {
222
-        $this->_test_settings_fields = array(
223
-            'to'      => array(
224
-                'input'      => 'text',
225
-                'label'      => esc_html__('Send a test email to', 'event_espresso'),
226
-                'type'       => 'email',
227
-                'required'   => true,
228
-                'validation' => true,
229
-                'css_class'  => 'large-text',
230
-                'format'     => '%s',
231
-                'default'    => get_bloginfo('admin_email'),
232
-            ),
233
-            'subject' => array(
234
-                'input'      => 'hidden',
235
-                'label'      => '',
236
-                'type'       => 'string',
237
-                'required'   => false,
238
-                'validation' => false,
239
-                'format'     => '%s',
240
-                'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
241
-                'default'    => '',
242
-                'css_class'  => '',
243
-            ),
244
-        );
245
-    }
246
-
247
-
248
-    /**
249
-     * _set_template_fields
250
-     * This sets up the fields that a messenger requires for the message to go out.
251
-     *
252
-     * @access  protected
253
-     * @return void
254
-     */
255
-    protected function _set_template_fields()
256
-    {
257
-        // any extra template fields that are NOT used by the messenger but will get used by a messenger field for
258
-        // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
259
-        // they relate to.  This is important for the Messages_admin to know what fields to display to the user.
260
-        //  Also, notice that the "values" are equal to the field type that messages admin will use to know what
261
-        // kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
262
-        // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
263
-        // displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
264
-        // will not be displayed/parsed.
265
-        $this->_template_fields = array(
266
-            'to'      => array(
267
-                'input'      => 'text',
268
-                'label'      => esc_html_x(
269
-                    'To',
270
-                    'Label for the "To" field for email addresses',
271
-                    'event_espresso'
272
-                ),
273
-                'type'       => 'string',
274
-                'required'   => true,
275
-                'validation' => true,
276
-                'css_class'  => 'large-text',
277
-                'format'     => '%s',
278
-            ),
279
-            'cc'      => array(
280
-                'input'      => 'text',
281
-                'label'      => esc_html_x(
282
-                    'CC',
283
-                    'Label for the "Carbon Copy" field used for additional email addresses',
284
-                    'event_espresso'
285
-                ),
286
-                'type'       => 'string',
287
-                'required'   => false,
288
-                'validation' => true,
289
-                'css_class'  => 'large-text',
290
-                'format'     => '%s',
291
-            ),
292
-            'from'    => array(
293
-                'input'      => 'text',
294
-                'label'      => esc_html_x(
295
-                    'From',
296
-                    'Label for the "From" field for email addresses.',
297
-                    'event_espresso'
298
-                ),
299
-                'type'       => 'string',
300
-                'required'   => true,
301
-                'validation' => true,
302
-                'css_class'  => 'large-text',
303
-                'format'     => '%s',
304
-            ),
305
-            'subject' => array(
306
-                'input'      => 'text',
307
-                'label'      => esc_html_x(
308
-                    'Subject',
309
-                    'Label for the "Subject" field (short description of contents) for emails.',
310
-                    'event_espresso'
311
-                ),
312
-                'type'       => 'string',
313
-                'required'   => true,
314
-                'validation' => true,
315
-                'css_class'  => 'large-text',
316
-                'format'     => '%s',
317
-            ),
318
-            'content' => '',
319
-            // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
320
-            'extra'   => array(
321
-                'content' => array(
322
-                    'main'          => array(
323
-                        'input'      => 'wp_editor',
324
-                        'label'      => esc_html__('Main Content', 'event_espresso'),
325
-                        'type'       => 'string',
326
-                        'required'   => true,
327
-                        'validation' => true,
328
-                        'format'     => '%s',
329
-                        'rows'       => '15',
330
-                    ),
331
-                    'event_list'    => array(
332
-                        'input'               => 'wp_editor',
333
-                        'label'               => '[EVENT_LIST]',
334
-                        'type'                => 'string',
335
-                        'required'            => true,
336
-                        'validation'          => true,
337
-                        'format'              => '%s',
338
-                        'rows'                => '15',
339
-                        'shortcodes_required' => array('[EVENT_LIST]'),
340
-                    ),
341
-                    'attendee_list' => array(
342
-                        'input'               => 'textarea',
343
-                        'label'               => '[ATTENDEE_LIST]',
344
-                        'type'                => 'string',
345
-                        'required'            => true,
346
-                        'validation'          => true,
347
-                        'format'              => '%s',
348
-                        'css_class'           => 'large-text',
349
-                        'rows'                => '5',
350
-                        'shortcodes_required' => array('[ATTENDEE_LIST]'),
351
-                    ),
352
-                    'ticket_list'   => array(
353
-                        'input'               => 'textarea',
354
-                        'label'               => '[TICKET_LIST]',
355
-                        'type'                => 'string',
356
-                        'required'            => true,
357
-                        'validation'          => true,
358
-                        'format'              => '%s',
359
-                        'css_class'           => 'large-text',
360
-                        'rows'                => '10',
361
-                        'shortcodes_required' => array('[TICKET_LIST]'),
362
-                    ),
363
-                    'datetime_list' => array(
364
-                        'input'               => 'textarea',
365
-                        'label'               => '[DATETIME_LIST]',
366
-                        'type'                => 'string',
367
-                        'required'            => true,
368
-                        'validation'          => true,
369
-                        'format'              => '%s',
370
-                        'css_class'           => 'large-text',
371
-                        'rows'                => '10',
372
-                        'shortcodes_required' => array('[DATETIME_LIST]'),
373
-                    ),
374
-                ),
375
-            ),
376
-        );
377
-    }
378
-
379
-
380
-    /**
381
-     * See definition of this class in parent
382
-     */
383
-    protected function _set_default_message_types()
384
-    {
385
-        $this->_default_message_types = array(
386
-            'payment',
387
-            'payment_refund',
388
-            'registration',
389
-            'not_approved_registration',
390
-            'pending_approval',
391
-        );
392
-    }
393
-
394
-
395
-    /**
396
-     * @see   definition of this class in parent
397
-     * @since 4.5.0
398
-     */
399
-    protected function _set_valid_message_types()
400
-    {
401
-        $this->_valid_message_types = array(
402
-            'payment',
403
-            'registration',
404
-            'not_approved_registration',
405
-            'declined_registration',
406
-            'cancelled_registration',
407
-            'pending_approval',
408
-            'registration_summary',
409
-            'payment_reminder',
410
-            'payment_declined',
411
-            'payment_refund',
412
-        );
413
-    }
414
-
415
-
416
-    /**
417
-     * setting up admin_settings_fields for messenger.
418
-     */
419
-    protected function _set_admin_settings_fields()
420
-    {
421
-    }
422
-
423
-    /**
424
-     * We just deliver the messages don't kill us!!
425
-     *
426
-     * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
427
-     *              present.
428
-     * @throws EE_Error
429
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
430
-     */
431
-    protected function _send_message()
432
-    {
433
-        $success = wp_mail(
434
-            $this->_to,
435
-            // some old values for subject may be expecting HTML entities to be decoded in the subject
436
-            // and subjects aren't interpreted as HTML, so there should be no HTML in them
437
-            wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),
438
-            $this->_body(),
439
-            $this->_headers()
440
-        );
441
-        if (! $success) {
442
-            EE_Error::add_error(
443
-                sprintf(
444
-                    esc_html__(
445
-                        'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
446
-                        'event_espresso'
447
-                    ),
448
-                    $this->_to,
449
-                    $this->_from,
450
-                    '<br />'
451
-                ),
452
-                __FILE__,
453
-                __FUNCTION__,
454
-                __LINE__
455
-            );
456
-        }
457
-        return $success;
458
-    }
459
-
460
-
461
-    /**
462
-     * see parent for definition
463
-     *
464
-     * @return string html body of the message content and the related css.
465
-     * @throws EE_Error
466
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
467
-     */
468
-    protected function _preview()
469
-    {
470
-        return $this->_body(true);
471
-    }
472
-
473
-
474
-    /**
475
-     * Setup headers for email
476
-     *
477
-     * @access protected
478
-     * @return string formatted header for email
479
-     */
480
-    protected function _headers()
481
-    {
482
-        $this->_ensure_has_from_email_address();
483
-        $from    = $this->_from;
484
-        $headers = array(
485
-            'From:' . $from,
486
-            'Reply-To:' . $from,
487
-            'Content-Type:text/html; charset=utf-8',
488
-        );
489
-
490
-        /**
491
-         * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to
492
-         * cover back compat where there may be users who have saved cc values in their db for the newsletter message
493
-         * type which they are no longer able to change.
494
-         */
495
-        if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) {
496
-            $headers[] = 'cc: ' . $this->_cc;
497
-        }
498
-
499
-        // but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
500
-        // header.
501
-        add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
502
-        add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
503
-        return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
504
-    }
505
-
506
-
507
-    /**
508
-     * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
509
-     * address for the from address to avoid problems with sending emails.
510
-     */
511
-    protected function _ensure_has_from_email_address()
512
-    {
513
-        if (empty($this->_from)) {
514
-            $this->_from = get_bloginfo('admin_email');
515
-        }
516
-    }
517
-
518
-
519
-    /**
520
-     * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
521
-     * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
522
-     * be empty
523
-     *
524
-     * @since 4.3.1
525
-     * @return array
526
-     */
527
-    private function _parse_from()
528
-    {
529
-        if (strpos($this->_from, '<') !== false) {
530
-            $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
531
-            $from_name = str_replace('"', '', $from_name);
532
-            $from_name = trim($from_name);
533
-
534
-            $from_email = substr($this->_from, strpos($this->_from, '<') + 1);
535
-            $from_email = str_replace('>', '', $from_email);
536
-            $from_email = trim($from_email);
537
-        } elseif (trim($this->_from) !== '') {
538
-            $from_name  = '';
539
-            $from_email = trim($this->_from);
540
-        } else {
541
-            $from_name = $from_email = '';
542
-        }
543
-        return array($from_name, $from_email);
544
-    }
545
-
546
-
547
-    /**
548
-     * Callback for the wp_mail_from filter.
549
-     *
550
-     * @since 4.3.1
551
-     * @param string $from_email What the original from_email is.
552
-     * @return string
553
-     */
554
-    public function set_from_address($from_email)
555
-    {
556
-        $parsed_from = $this->_parse_from();
557
-        // includes fallback if the parsing failed.
558
-        $from_email = is_array($parsed_from) && ! empty($parsed_from[1])
559
-            ? $parsed_from[1]
560
-            : get_bloginfo('admin_email');
561
-        return $from_email;
562
-    }
563
-
564
-
565
-    /**
566
-     * Callback fro the wp_mail_from_name filter.
567
-     *
568
-     * @since 4.3.1
569
-     * @param string $from_name The original from_name.
570
-     * @return string
571
-     */
572
-    public function set_from_name($from_name)
573
-    {
574
-        $parsed_from = $this->_parse_from();
575
-        if (is_array($parsed_from) && ! empty($parsed_from[0])) {
576
-            $from_name = $parsed_from[0];
577
-        }
578
-
579
-        // if from name is "WordPress" let's sub in the site name instead (more friendly!)
580
-        // but realize the default name is HTML entity-encoded
581
-        $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;
582
-
583
-        return $from_name;
584
-    }
585
-
586
-
587
-    /**
588
-     * setup body for email
589
-     *
590
-     * @param bool $preview will determine whether this is preview template or not.
591
-     * @return string formatted body for email.
592
-     * @throws EE_Error
593
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
594
-     */
595
-    protected function _body($preview = false)
596
-    {
597
-        // setup template args!
598
-        $this->_template_args = array(
599
-            'subject'   => $this->_subject,
600
-            'from'      => $this->_from,
601
-            'main_body' => wpautop($this->_content),
602
-        );
603
-        $body                 = $this->_get_main_template($preview);
604
-
605
-        /**
606
-         * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
607
-         *
608
-         * @type    bool $preview Indicates whether a preview is being generated or not.
609
-         * @return  bool    true  indicates to use the inliner, false bypasses it.
610
-         */
611
-        if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
612
-            // require CssToInlineStyles library and its dependencies via composer autoloader
613
-            require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
614
-
615
-            // now if this isn't a preview, let's setup the body so it has inline styles
616
-            if (! $preview || ($preview && defined('DOING_AJAX'))) {
617
-                $style = file_get_contents(
618
-                    $this->get_variation(
619
-                        $this->_tmp_pack,
620
-                        $this->_incoming_message_type->name,
621
-                        false,
622
-                        'main',
623
-                        $this->_variation
624
-                    ),
625
-                    true
626
-                );
627
-                $CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
628
-                // for some reason the library has a bracket and new line at the beginning.  This takes care of that.
629
-                $body  = ltrim($CSS->convert(true), ">\n");
630
-                // see https://events.codebasehq.com/projects/event-espresso/tickets/8609
631
-                $body  = ltrim($body, "<?");
632
-            }
633
-        }
634
-        return $body;
635
-    }
636
-
637
-
638
-    /**
639
-     * This just returns any existing test settings that might be saved in the database
640
-     *
641
-     * @access public
642
-     * @return array
643
-     */
644
-    public function get_existing_test_settings()
645
-    {
646
-        $settings = parent::get_existing_test_settings();
647
-        // override subject if present because we always want it to be fresh.
648
-        if (is_array($settings) && ! empty($settings['subject'])) {
649
-            $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
650
-        }
651
-        return $settings;
652
-    }
9
+	/**
10
+	 * To field for email
11
+	 * @var string
12
+	 */
13
+	protected $_to = '';
14
+
15
+
16
+	/**
17
+	 * CC field for email.
18
+	 * @var string
19
+	 */
20
+	protected $_cc = '';
21
+
22
+	/**
23
+	 * From field for email
24
+	 * @var string
25
+	 */
26
+	protected $_from = '';
27
+
28
+
29
+	/**
30
+	 * Subject field for email
31
+	 * @var string
32
+	 */
33
+	protected $_subject = '';
34
+
35
+
36
+	/**
37
+	 * Content field for email
38
+	 * @var string
39
+	 */
40
+	protected $_content = '';
41
+
42
+
43
+	/**
44
+	 * constructor
45
+	 *
46
+	 * @access public
47
+	 */
48
+	public function __construct()
49
+	{
50
+		// set name and description properties
51
+		$this->name                = 'email';
52
+		$this->description         = sprintf(
53
+			esc_html__(
54
+				'This messenger delivers messages via email using the built-in %s function included with WordPress',
55
+				'event_espresso'
56
+			),
57
+			'<code>wp_mail</code>'
58
+		);
59
+		$this->label               = array(
60
+			'singular' => esc_html__('email', 'event_espresso'),
61
+			'plural'   => esc_html__('emails', 'event_espresso'),
62
+		);
63
+		$this->activate_on_install = true;
64
+
65
+		// we're using defaults so let's call parent constructor that will take care of setting up all the other
66
+		// properties
67
+		parent::__construct();
68
+	}
69
+
70
+
71
+	/**
72
+	 * see abstract declaration in parent class for details.
73
+	 */
74
+	protected function _set_admin_pages()
75
+	{
76
+		$this->admin_registered_pages = array(
77
+			'events_edit' => true,
78
+		);
79
+	}
80
+
81
+
82
+	/**
83
+	 * see abstract declaration in parent class for details
84
+	 */
85
+	protected function _set_valid_shortcodes()
86
+	{
87
+		// remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
88
+		// message type.
89
+		$this->_valid_shortcodes = array(
90
+			'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
91
+			'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
92
+			'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
93
+		);
94
+	}
95
+
96
+
97
+	/**
98
+	 * see abstract declaration in parent class for details
99
+	 *
100
+	 * @access protected
101
+	 * @return void
102
+	 */
103
+	protected function _set_validator_config()
104
+	{
105
+		$valid_shortcodes = $this->get_valid_shortcodes();
106
+
107
+		$this->_validator_config = array(
108
+			'to'            => array(
109
+				'shortcodes' => $valid_shortcodes['to'],
110
+				'type'       => 'email',
111
+			),
112
+			'cc' => array(
113
+				'shortcodes' => $valid_shortcodes['to'],
114
+				'type' => 'email',
115
+			),
116
+			'from'          => array(
117
+				'shortcodes' => $valid_shortcodes['from'],
118
+				'type'       => 'email',
119
+			),
120
+			'subject'       => array(
121
+				'shortcodes' => array(
122
+					'organization',
123
+					'primary_registration_details',
124
+					'event_author',
125
+					'primary_registration_details',
126
+					'recipient_details',
127
+				),
128
+			),
129
+			'content'       => array(
130
+				'shortcodes' => array(
131
+					'event_list',
132
+					'attendee_list',
133
+					'ticket_list',
134
+					'organization',
135
+					'primary_registration_details',
136
+					'primary_registration_list',
137
+					'event_author',
138
+					'recipient_details',
139
+					'recipient_list',
140
+					'transaction',
141
+					'messenger',
142
+				),
143
+			),
144
+			'attendee_list' => array(
145
+				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
146
+				'required'   => array('[ATTENDEE_LIST]'),
147
+			),
148
+			'event_list'    => array(
149
+				'shortcodes' => array(
150
+					'event',
151
+					'attendee_list',
152
+					'ticket_list',
153
+					'venue',
154
+					'datetime_list',
155
+					'attendee',
156
+					'primary_registration_details',
157
+					'primary_registration_list',
158
+					'event_author',
159
+					'recipient_details',
160
+					'recipient_list',
161
+				),
162
+				'required'   => array('[EVENT_LIST]'),
163
+			),
164
+			'ticket_list'   => array(
165
+				'shortcodes' => array(
166
+					'event_list',
167
+					'attendee_list',
168
+					'ticket',
169
+					'datetime_list',
170
+					'primary_registration_details',
171
+					'recipient_details',
172
+				),
173
+				'required'   => array('[TICKET_LIST]'),
174
+			),
175
+			'datetime_list' => array(
176
+				'shortcodes' => array('datetime'),
177
+				'required'   => array('[DATETIME_LIST]'),
178
+			),
179
+		);
180
+	}
181
+
182
+
183
+	/**
184
+	 * @see   parent EE_messenger class for docs
185
+	 * @since 4.5.0
186
+	 */
187
+	public function do_secondary_messenger_hooks($sending_messenger_name)
188
+	{
189
+		if ($sending_messenger_name === 'html') {
190
+			add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
191
+		}
192
+	}
193
+
194
+
195
+	public function add_email_css(
196
+		$variation_path,
197
+		$messenger,
198
+		$message_type,
199
+		$type,
200
+		$variation,
201
+		$file_extension,
202
+		$url,
203
+		EE_Messages_Template_Pack $template_pack
204
+	) {
205
+		// prevent recursion on this callback.
206
+		remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
207
+		$variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
208
+
209
+		add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
210
+		return $variation;
211
+	}
212
+
213
+
214
+	/**
215
+	 * See parent for details
216
+	 *
217
+	 * @access protected
218
+	 * @return void
219
+	 */
220
+	protected function _set_test_settings_fields()
221
+	{
222
+		$this->_test_settings_fields = array(
223
+			'to'      => array(
224
+				'input'      => 'text',
225
+				'label'      => esc_html__('Send a test email to', 'event_espresso'),
226
+				'type'       => 'email',
227
+				'required'   => true,
228
+				'validation' => true,
229
+				'css_class'  => 'large-text',
230
+				'format'     => '%s',
231
+				'default'    => get_bloginfo('admin_email'),
232
+			),
233
+			'subject' => array(
234
+				'input'      => 'hidden',
235
+				'label'      => '',
236
+				'type'       => 'string',
237
+				'required'   => false,
238
+				'validation' => false,
239
+				'format'     => '%s',
240
+				'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
241
+				'default'    => '',
242
+				'css_class'  => '',
243
+			),
244
+		);
245
+	}
246
+
247
+
248
+	/**
249
+	 * _set_template_fields
250
+	 * This sets up the fields that a messenger requires for the message to go out.
251
+	 *
252
+	 * @access  protected
253
+	 * @return void
254
+	 */
255
+	protected function _set_template_fields()
256
+	{
257
+		// any extra template fields that are NOT used by the messenger but will get used by a messenger field for
258
+		// shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
259
+		// they relate to.  This is important for the Messages_admin to know what fields to display to the user.
260
+		//  Also, notice that the "values" are equal to the field type that messages admin will use to know what
261
+		// kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
262
+		// indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
263
+		// displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
264
+		// will not be displayed/parsed.
265
+		$this->_template_fields = array(
266
+			'to'      => array(
267
+				'input'      => 'text',
268
+				'label'      => esc_html_x(
269
+					'To',
270
+					'Label for the "To" field for email addresses',
271
+					'event_espresso'
272
+				),
273
+				'type'       => 'string',
274
+				'required'   => true,
275
+				'validation' => true,
276
+				'css_class'  => 'large-text',
277
+				'format'     => '%s',
278
+			),
279
+			'cc'      => array(
280
+				'input'      => 'text',
281
+				'label'      => esc_html_x(
282
+					'CC',
283
+					'Label for the "Carbon Copy" field used for additional email addresses',
284
+					'event_espresso'
285
+				),
286
+				'type'       => 'string',
287
+				'required'   => false,
288
+				'validation' => true,
289
+				'css_class'  => 'large-text',
290
+				'format'     => '%s',
291
+			),
292
+			'from'    => array(
293
+				'input'      => 'text',
294
+				'label'      => esc_html_x(
295
+					'From',
296
+					'Label for the "From" field for email addresses.',
297
+					'event_espresso'
298
+				),
299
+				'type'       => 'string',
300
+				'required'   => true,
301
+				'validation' => true,
302
+				'css_class'  => 'large-text',
303
+				'format'     => '%s',
304
+			),
305
+			'subject' => array(
306
+				'input'      => 'text',
307
+				'label'      => esc_html_x(
308
+					'Subject',
309
+					'Label for the "Subject" field (short description of contents) for emails.',
310
+					'event_espresso'
311
+				),
312
+				'type'       => 'string',
313
+				'required'   => true,
314
+				'validation' => true,
315
+				'css_class'  => 'large-text',
316
+				'format'     => '%s',
317
+			),
318
+			'content' => '',
319
+			// left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
320
+			'extra'   => array(
321
+				'content' => array(
322
+					'main'          => array(
323
+						'input'      => 'wp_editor',
324
+						'label'      => esc_html__('Main Content', 'event_espresso'),
325
+						'type'       => 'string',
326
+						'required'   => true,
327
+						'validation' => true,
328
+						'format'     => '%s',
329
+						'rows'       => '15',
330
+					),
331
+					'event_list'    => array(
332
+						'input'               => 'wp_editor',
333
+						'label'               => '[EVENT_LIST]',
334
+						'type'                => 'string',
335
+						'required'            => true,
336
+						'validation'          => true,
337
+						'format'              => '%s',
338
+						'rows'                => '15',
339
+						'shortcodes_required' => array('[EVENT_LIST]'),
340
+					),
341
+					'attendee_list' => array(
342
+						'input'               => 'textarea',
343
+						'label'               => '[ATTENDEE_LIST]',
344
+						'type'                => 'string',
345
+						'required'            => true,
346
+						'validation'          => true,
347
+						'format'              => '%s',
348
+						'css_class'           => 'large-text',
349
+						'rows'                => '5',
350
+						'shortcodes_required' => array('[ATTENDEE_LIST]'),
351
+					),
352
+					'ticket_list'   => array(
353
+						'input'               => 'textarea',
354
+						'label'               => '[TICKET_LIST]',
355
+						'type'                => 'string',
356
+						'required'            => true,
357
+						'validation'          => true,
358
+						'format'              => '%s',
359
+						'css_class'           => 'large-text',
360
+						'rows'                => '10',
361
+						'shortcodes_required' => array('[TICKET_LIST]'),
362
+					),
363
+					'datetime_list' => array(
364
+						'input'               => 'textarea',
365
+						'label'               => '[DATETIME_LIST]',
366
+						'type'                => 'string',
367
+						'required'            => true,
368
+						'validation'          => true,
369
+						'format'              => '%s',
370
+						'css_class'           => 'large-text',
371
+						'rows'                => '10',
372
+						'shortcodes_required' => array('[DATETIME_LIST]'),
373
+					),
374
+				),
375
+			),
376
+		);
377
+	}
378
+
379
+
380
+	/**
381
+	 * See definition of this class in parent
382
+	 */
383
+	protected function _set_default_message_types()
384
+	{
385
+		$this->_default_message_types = array(
386
+			'payment',
387
+			'payment_refund',
388
+			'registration',
389
+			'not_approved_registration',
390
+			'pending_approval',
391
+		);
392
+	}
393
+
394
+
395
+	/**
396
+	 * @see   definition of this class in parent
397
+	 * @since 4.5.0
398
+	 */
399
+	protected function _set_valid_message_types()
400
+	{
401
+		$this->_valid_message_types = array(
402
+			'payment',
403
+			'registration',
404
+			'not_approved_registration',
405
+			'declined_registration',
406
+			'cancelled_registration',
407
+			'pending_approval',
408
+			'registration_summary',
409
+			'payment_reminder',
410
+			'payment_declined',
411
+			'payment_refund',
412
+		);
413
+	}
414
+
415
+
416
+	/**
417
+	 * setting up admin_settings_fields for messenger.
418
+	 */
419
+	protected function _set_admin_settings_fields()
420
+	{
421
+	}
422
+
423
+	/**
424
+	 * We just deliver the messages don't kill us!!
425
+	 *
426
+	 * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
427
+	 *              present.
428
+	 * @throws EE_Error
429
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
430
+	 */
431
+	protected function _send_message()
432
+	{
433
+		$success = wp_mail(
434
+			$this->_to,
435
+			// some old values for subject may be expecting HTML entities to be decoded in the subject
436
+			// and subjects aren't interpreted as HTML, so there should be no HTML in them
437
+			wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),
438
+			$this->_body(),
439
+			$this->_headers()
440
+		);
441
+		if (! $success) {
442
+			EE_Error::add_error(
443
+				sprintf(
444
+					esc_html__(
445
+						'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
446
+						'event_espresso'
447
+					),
448
+					$this->_to,
449
+					$this->_from,
450
+					'<br />'
451
+				),
452
+				__FILE__,
453
+				__FUNCTION__,
454
+				__LINE__
455
+			);
456
+		}
457
+		return $success;
458
+	}
459
+
460
+
461
+	/**
462
+	 * see parent for definition
463
+	 *
464
+	 * @return string html body of the message content and the related css.
465
+	 * @throws EE_Error
466
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
467
+	 */
468
+	protected function _preview()
469
+	{
470
+		return $this->_body(true);
471
+	}
472
+
473
+
474
+	/**
475
+	 * Setup headers for email
476
+	 *
477
+	 * @access protected
478
+	 * @return string formatted header for email
479
+	 */
480
+	protected function _headers()
481
+	{
482
+		$this->_ensure_has_from_email_address();
483
+		$from    = $this->_from;
484
+		$headers = array(
485
+			'From:' . $from,
486
+			'Reply-To:' . $from,
487
+			'Content-Type:text/html; charset=utf-8',
488
+		);
489
+
490
+		/**
491
+		 * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to
492
+		 * cover back compat where there may be users who have saved cc values in their db for the newsletter message
493
+		 * type which they are no longer able to change.
494
+		 */
495
+		if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) {
496
+			$headers[] = 'cc: ' . $this->_cc;
497
+		}
498
+
499
+		// but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
500
+		// header.
501
+		add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
502
+		add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
503
+		return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
504
+	}
505
+
506
+
507
+	/**
508
+	 * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
509
+	 * address for the from address to avoid problems with sending emails.
510
+	 */
511
+	protected function _ensure_has_from_email_address()
512
+	{
513
+		if (empty($this->_from)) {
514
+			$this->_from = get_bloginfo('admin_email');
515
+		}
516
+	}
517
+
518
+
519
+	/**
520
+	 * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
521
+	 * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
522
+	 * be empty
523
+	 *
524
+	 * @since 4.3.1
525
+	 * @return array
526
+	 */
527
+	private function _parse_from()
528
+	{
529
+		if (strpos($this->_from, '<') !== false) {
530
+			$from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
531
+			$from_name = str_replace('"', '', $from_name);
532
+			$from_name = trim($from_name);
533
+
534
+			$from_email = substr($this->_from, strpos($this->_from, '<') + 1);
535
+			$from_email = str_replace('>', '', $from_email);
536
+			$from_email = trim($from_email);
537
+		} elseif (trim($this->_from) !== '') {
538
+			$from_name  = '';
539
+			$from_email = trim($this->_from);
540
+		} else {
541
+			$from_name = $from_email = '';
542
+		}
543
+		return array($from_name, $from_email);
544
+	}
545
+
546
+
547
+	/**
548
+	 * Callback for the wp_mail_from filter.
549
+	 *
550
+	 * @since 4.3.1
551
+	 * @param string $from_email What the original from_email is.
552
+	 * @return string
553
+	 */
554
+	public function set_from_address($from_email)
555
+	{
556
+		$parsed_from = $this->_parse_from();
557
+		// includes fallback if the parsing failed.
558
+		$from_email = is_array($parsed_from) && ! empty($parsed_from[1])
559
+			? $parsed_from[1]
560
+			: get_bloginfo('admin_email');
561
+		return $from_email;
562
+	}
563
+
564
+
565
+	/**
566
+	 * Callback fro the wp_mail_from_name filter.
567
+	 *
568
+	 * @since 4.3.1
569
+	 * @param string $from_name The original from_name.
570
+	 * @return string
571
+	 */
572
+	public function set_from_name($from_name)
573
+	{
574
+		$parsed_from = $this->_parse_from();
575
+		if (is_array($parsed_from) && ! empty($parsed_from[0])) {
576
+			$from_name = $parsed_from[0];
577
+		}
578
+
579
+		// if from name is "WordPress" let's sub in the site name instead (more friendly!)
580
+		// but realize the default name is HTML entity-encoded
581
+		$from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;
582
+
583
+		return $from_name;
584
+	}
585
+
586
+
587
+	/**
588
+	 * setup body for email
589
+	 *
590
+	 * @param bool $preview will determine whether this is preview template or not.
591
+	 * @return string formatted body for email.
592
+	 * @throws EE_Error
593
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
594
+	 */
595
+	protected function _body($preview = false)
596
+	{
597
+		// setup template args!
598
+		$this->_template_args = array(
599
+			'subject'   => $this->_subject,
600
+			'from'      => $this->_from,
601
+			'main_body' => wpautop($this->_content),
602
+		);
603
+		$body                 = $this->_get_main_template($preview);
604
+
605
+		/**
606
+		 * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
607
+		 *
608
+		 * @type    bool $preview Indicates whether a preview is being generated or not.
609
+		 * @return  bool    true  indicates to use the inliner, false bypasses it.
610
+		 */
611
+		if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
612
+			// require CssToInlineStyles library and its dependencies via composer autoloader
613
+			require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
614
+
615
+			// now if this isn't a preview, let's setup the body so it has inline styles
616
+			if (! $preview || ($preview && defined('DOING_AJAX'))) {
617
+				$style = file_get_contents(
618
+					$this->get_variation(
619
+						$this->_tmp_pack,
620
+						$this->_incoming_message_type->name,
621
+						false,
622
+						'main',
623
+						$this->_variation
624
+					),
625
+					true
626
+				);
627
+				$CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
628
+				// for some reason the library has a bracket and new line at the beginning.  This takes care of that.
629
+				$body  = ltrim($CSS->convert(true), ">\n");
630
+				// see https://events.codebasehq.com/projects/event-espresso/tickets/8609
631
+				$body  = ltrim($body, "<?");
632
+			}
633
+		}
634
+		return $body;
635
+	}
636
+
637
+
638
+	/**
639
+	 * This just returns any existing test settings that might be saved in the database
640
+	 *
641
+	 * @access public
642
+	 * @return array
643
+	 */
644
+	public function get_existing_test_settings()
645
+	{
646
+		$settings = parent::get_existing_test_settings();
647
+		// override subject if present because we always want it to be fresh.
648
+		if (is_array($settings) && ! empty($settings['subject'])) {
649
+			$settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
650
+		}
651
+		return $settings;
652
+	}
653 653
 }
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Html_messenger.class.php 1 patch
Indentation   +544 added lines, -544 removed lines patch added patch discarded remove patch
@@ -12,548 +12,548 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * The following are the properties that this messenger requires for displaying the html
17
-     */
18
-    /**
19
-     * This is the html body generated by the template via the message type.
20
-     *
21
-     * @var string
22
-     */
23
-    protected $_content;
24
-
25
-
26
-    /**
27
-     * This is for the page title that gets displayed.  (Why use "subject"?  Because the "title" tag in html is
28
-     * equivalent to the "subject" of the page.
29
-     *
30
-     * @var string
31
-     */
32
-    protected $_subject;
33
-
34
-
35
-    /**
36
-     * EE_Html_messenger constructor.
37
-     */
38
-    public function __construct()
39
-    {
40
-        // set properties
41
-        $this->name = 'html';
42
-        $this->description = __('This messenger outputs a message to a browser for display.', 'event_espresso');
43
-        $this->label = array(
44
-            'singular' => __('html', 'event_espresso'),
45
-            'plural' => __('html', 'event_espresso'),
46
-        );
47
-        $this->activate_on_install = true;
48
-        // add the "powered by EE" credit link to the HTML receipt and invoice
49
-        add_filter(
50
-            'FHEE__EE_Html_messenger___send_message__main_body',
51
-            array($this, 'add_powered_by_credit_link_to_receipt_and_invoice'),
52
-            10,
53
-            3
54
-        );
55
-        parent::__construct();
56
-    }
57
-
58
-
59
-    /**
60
-     * HTML Messenger desires execution immediately.
61
-     *
62
-     * @see    parent::send_now() for documentation.
63
-     * @since  4.9.0
64
-     * @return bool
65
-     */
66
-    public function send_now()
67
-    {
68
-        return true;
69
-    }
70
-
71
-
72
-    /**
73
-     * HTML Messenger allows an empty to field.
74
-     *
75
-     * @see    parent::allow_empty_to_field() for documentation
76
-     * @since  4.9.0
77
-     * @return bool
78
-     */
79
-    public function allow_empty_to_field()
80
-    {
81
-        return true;
82
-    }
83
-
84
-
85
-    /**
86
-     * @see abstract declaration in EE_messenger for details.
87
-     */
88
-    protected function _set_admin_pages()
89
-    {
90
-        $this->admin_registered_pages = array('events_edit' => true);
91
-    }
92
-
93
-
94
-    /**
95
-     * @see abstract declaration in EE_messenger for details.
96
-     */
97
-    protected function _set_valid_shortcodes()
98
-    {
99
-        $this->_valid_shortcodes = array();
100
-    }
101
-
102
-
103
-    /**
104
-     * @see abstract declaration in EE_messenger for details.
105
-     */
106
-    protected function _set_validator_config()
107
-    {
108
-        $this->_validator_config = array(
109
-            'subject' => array(
110
-                'shortcodes' => array('organization', 'primary_registration_details', 'email', 'transaction'),
111
-            ),
112
-            'content' => array(
113
-                'shortcodes' => array(
114
-                    'organization',
115
-                    'primary_registration_list',
116
-                    'primary_registration_details',
117
-                    'email',
118
-                    'transaction',
119
-                    'event_list',
120
-                    'payment_list',
121
-                    'venue',
122
-                    'line_item_list',
123
-                    'messenger',
124
-                    'ticket_list',
125
-                ),
126
-            ),
127
-            'event_list' => array(
128
-                'shortcodes' => array(
129
-                    'event',
130
-                    'ticket_list',
131
-                    'venue',
132
-                    'primary_registration_details',
133
-                    'primary_registration_list',
134
-                    'event_author',
135
-                ),
136
-                'required' => array('[EVENT_LIST]'),
137
-            ),
138
-            'ticket_list' => array(
139
-                'shortcodes' => array(
140
-                    'attendee_list',
141
-                    'ticket',
142
-                    'datetime_list',
143
-                    'primary_registration_details',
144
-                    'line_item_list',
145
-                    'venue',
146
-                ),
147
-                'required' => array('[TICKET_LIST]'),
148
-            ),
149
-            'ticket_line_item_no_pms' => array(
150
-                'shortcodes' => array('line_item', 'ticket'),
151
-                'required' => array('[TICKET_LINE_ITEM_LIST]'),
152
-            ),
153
-            'ticket_line_item_pms' => array(
154
-                'shortcodes' => array('line_item', 'ticket', 'line_item_list'),
155
-                'required' => array('[TICKET_LINE_ITEM_LIST]'),
156
-            ),
157
-            'price_modifier_line_item_list' => array(
158
-                'shortcodes' => array('line_item'),
159
-                'required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
160
-            ),
161
-            'datetime_list' => array(
162
-                'shortcodes' => array('datetime'),
163
-                'required' => array('[DATETIME_LIST]'),
164
-            ),
165
-            'attendee_list' => array(
166
-                'shortcodes' => array('attendee'),
167
-                'required' => array('[ATTENDEE_LIST]'),
168
-            ),
169
-            'tax_line_item_list' => array(
170
-                'shortcodes' => array('line_item'),
171
-                'required' => array('[TAX_LINE_ITEM_LIST]'),
172
-            ),
173
-            'additional_line_item_list' => array(
174
-                'shortcodes' => array('line_item'),
175
-                'required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
176
-            ),
177
-            'payment_list' => array(
178
-                'shortcodes' => array('payment'),
179
-                'required' => array('[PAYMENT_LIST_*]'),
180
-            ),
181
-        );
182
-    }
183
-
184
-
185
-    /**
186
-     * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger
187
-     * is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary
188
-     * (i.e. swap out css files or something else).
189
-     *
190
-     * @since 4.5.0
191
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
192
-     * @return void
193
-     */
194
-    public function do_secondary_messenger_hooks($sending_messenger_name)
195
-    {
196
-        if ($sending_messenger_name === 'pdf') {
197
-            add_filter('EE_messenger__get_variation__variation', array($this, 'add_html_css'), 10, 8);
198
-        }
199
-    }
200
-
201
-
202
-    /**
203
-     * @param                            $variation_path
204
-     * @param \EE_Messages_Template_Pack $template_pack
205
-     * @param                            $messenger_name
206
-     * @param                            $message_type_name
207
-     * @param                            $url
208
-     * @param                            $type
209
-     * @param                            $variation
210
-     * @param                            $skip_filters
211
-     * @return string
212
-     */
213
-    public function add_html_css(
214
-        $variation_path,
215
-        EE_Messages_Template_Pack $template_pack,
216
-        $messenger_name,
217
-        $message_type_name,
218
-        $url,
219
-        $type,
220
-        $variation,
221
-        $skip_filters
222
-    ) {
223
-        $variation = $template_pack->get_variation(
224
-            $this->name,
225
-            $message_type_name,
226
-            $type,
227
-            $variation,
228
-            $url,
229
-            '.css',
230
-            $skip_filters
231
-        );
232
-        return $variation;
233
-    }
234
-
235
-
236
-    /**
237
-     * Takes care of enqueuing any necessary scripts or styles for the page.  A do_action() so message types using this
238
-     * messenger can add their own js.
239
-     *
240
-     * @return void.
241
-     */
242
-    public function enqueue_scripts_styles()
243
-    {
244
-        parent::enqueue_scripts_styles();
245
-        do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles');
246
-    }
247
-
248
-
249
-    /**
250
-     * _set_template_fields
251
-     * This sets up the fields that a messenger requires for the message to go out.
252
-     *
253
-     * @access  protected
254
-     * @return void
255
-     */
256
-    protected function _set_template_fields()
257
-    {
258
-        // any extra template fields that are NOT used by the messenger
259
-        // but will get used by a messenger field for shortcode replacement
260
-        // get added to the 'extra' key in an associated array
261
-        // indexed by the messenger field they relate to.
262
-        // This is important for the Messages_admin to know what fields to display to the user.
263
-        // Also, notice that the "values" are equal to the field type
264
-        // that messages admin will use to know what kind of field to display.
265
-        // The values ALSO have one index labeled "shortcode".
266
-        // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE])
267
-        // is required in order for this extra field to be displayed.
268
-        //  If the required shortcode isn't part of the shortcodes array
269
-        // then the field is not needed and will not be displayed/parsed.
270
-        $this->_template_fields = array(
271
-            'subject' => array(
272
-                'input' => 'text',
273
-                'label' => __('Page Title', 'event_espresso'),
274
-                'type' => 'string',
275
-                'required' => true,
276
-                'validation' => true,
277
-                'css_class' => 'large-text',
278
-                'format' => '%s',
279
-            ),
280
-            'content' => '',
281
-            // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
282
-            'extra' => array(
283
-                'content' => array(
284
-                    'main' => array(
285
-                        'input' => 'wp_editor',
286
-                        'label' => __('Main Content', 'event_espresso'),
287
-                        'type' => 'string',
288
-                        'required' => true,
289
-                        'validation' => true,
290
-                        'format' => '%s',
291
-                        'rows' => '15',
292
-                    ),
293
-                    'event_list' => array(
294
-                        'input' => 'wp_editor',
295
-                        'label' => '[EVENT_LIST]',
296
-                        'type' => 'string',
297
-                        'required' => true,
298
-                        'validation' => true,
299
-                        'format' => '%s',
300
-                        'rows' => '15',
301
-                        'shortcodes_required' => array('[EVENT_LIST]'),
302
-                    ),
303
-                    'ticket_list' => array(
304
-                        'input' => 'textarea',
305
-                        'label' => '[TICKET_LIST]',
306
-                        'type' => 'string',
307
-                        'required' => true,
308
-                        'validation' => true,
309
-                        'format' => '%s',
310
-                        'css_class' => 'large-text',
311
-                        'rows' => '10',
312
-                        'shortcodes_required' => array('[TICKET_LIST]'),
313
-                    ),
314
-                    'ticket_line_item_no_pms' => array(
315
-                        'input' => 'textarea',
316
-                        'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
317
-                            'Ticket Line Item List with no Price Modifiers',
318
-                            'event_espresso'
319
-                        ),
320
-                        'type' => 'string',
321
-                        'required' => false,
322
-                        'validation' => true,
323
-                        'format' => '%s',
324
-                        'css_class' => 'large-text',
325
-                        'rows' => '5',
326
-                        'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
327
-                    ),
328
-                    'ticket_line_item_pms' => array(
329
-                        'input' => 'textarea',
330
-                        'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
331
-                            'Ticket Line Item List with Price Modifiers',
332
-                            'event_espresso'
333
-                        ),
334
-                        'type' => 'string',
335
-                        'required' => false,
336
-                        'validation' => true,
337
-                        'format' => '%s',
338
-                        'css_class' => 'large-text',
339
-                        'rows' => '5',
340
-                        'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
341
-                    ),
342
-                    'price_modifier_line_item_list' => array(
343
-                        'input' => 'textarea',
344
-                        'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]',
345
-                        'type' => 'string',
346
-                        'required' => false,
347
-                        'validation' => true,
348
-                        'format' => '%s',
349
-                        'css_class' => 'large-text',
350
-                        'rows' => '5',
351
-                        'shortcodes_required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
352
-                    ),
353
-                    'datetime_list' => array(
354
-                        'input' => 'textarea',
355
-                        'label' => '[DATETIME_LIST]',
356
-                        'type' => 'string',
357
-                        'required' => true,
358
-                        'validation' => true,
359
-                        'format' => '%s',
360
-                        'css_class' => 'large-text',
361
-                        'rows' => '5',
362
-                        'shortcodes_required' => array('[DATETIME_LIST]'),
363
-                    ),
364
-                    'attendee_list' => array(
365
-                        'input' => 'textarea',
366
-                        'label' => '[ATTENDEE_LIST]',
367
-                        'type' => 'string',
368
-                        'required' => true,
369
-                        'validation' => true,
370
-                        'format' => '%s',
371
-                        'css_class' => 'large-text',
372
-                        'rows' => '5',
373
-                        'shortcodes_required' => array('[ATTENDEE_LIST]'),
374
-                    ),
375
-                    'tax_line_item_list' => array(
376
-                        'input' => 'textarea',
377
-                        'label' => '[TAX_LINE_ITEM_LIST]',
378
-                        'type' => 'string',
379
-                        'required' => false,
380
-                        'validation' => true,
381
-                        'format' => '%s',
382
-                        'css_class' => 'large-text',
383
-                        'rows' => '5',
384
-                        'shortcodes_required' => array('[TAX_LINE_ITEM_LIST]'),
385
-                    ),
386
-                    'additional_line_item_list' => array(
387
-                        'input' => 'textarea',
388
-                        'label' => '[ADDITIONAL_LINE_ITEM_LIST]',
389
-                        'type' => 'string',
390
-                        'required' => false,
391
-                        'validation' => true,
392
-                        'format' => '%s',
393
-                        'css_class' => 'large-text',
394
-                        'rows' => '5',
395
-                        'shortcodes_required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
396
-                    ),
397
-                    'payment_list' => array(
398
-                        'input' => 'textarea',
399
-                        'label' => '[PAYMENT_LIST]',
400
-                        'type' => 'string',
401
-                        'required' => true,
402
-                        'validation' => true,
403
-                        'format' => '%s',
404
-                        'css_class' => 'large-text',
405
-                        'rows' => '5',
406
-                        'shortcodes_required' => array('[PAYMENT_LIST_*]'),
407
-                    ),
408
-                ),
409
-            ),
410
-        );
411
-    }
412
-
413
-
414
-    /**
415
-     * @see   definition of this method in parent
416
-     * @since 4.5.0
417
-     */
418
-    protected function _set_default_message_types()
419
-    {
420
-        $this->_default_message_types = array('receipt', 'invoice');
421
-    }
422
-
423
-
424
-    /**
425
-     * @see   definition of this method in parent
426
-     * @since 4.5.0
427
-     */
428
-    protected function _set_valid_message_types()
429
-    {
430
-        $this->_valid_message_types = array('receipt', 'invoice');
431
-    }
432
-
433
-
434
-    /**
435
-     * Displays the message in the browser.
436
-     *
437
-     * @since 4.5.0
438
-     * @return string.
439
-     */
440
-    protected function _send_message()
441
-    {
442
-        $this->_template_args = array(
443
-            'page_title' => $this->_subject,
444
-            'base_css' => $this->get_variation(
445
-                $this->_tmp_pack,
446
-                $this->_incoming_message_type->name,
447
-                true,
448
-                'base',
449
-                $this->_variation
450
-            ),
451
-            'print_css' => $this->get_variation(
452
-                $this->_tmp_pack,
453
-                $this->_incoming_message_type->name,
454
-                true,
455
-                'print',
456
-                $this->_variation
457
-            ),
458
-            'main_css' => $this->get_variation(
459
-                $this->_tmp_pack,
460
-                $this->_incoming_message_type->name,
461
-                true,
462
-                'main',
463
-                $this->_variation
464
-            ),
465
-            'main_body' => wpautop(
466
-                apply_filters(
467
-                    'FHEE__EE_Html_messenger___send_message__main_body',
468
-                    $this->_content,
469
-                    $this->_content,
470
-                    $this->_incoming_message_type
471
-                )
472
-            )
473
-        );
474
-        $this->_deregister_wp_hooks();
475
-        add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
476
-        echo $this->_get_main_template();
477
-        exit();
478
-    }
479
-
480
-
481
-    /**
482
-     * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't
483
-     * interfere with our templates.  If users want to add any custom styles or scripts they must use the
484
-     * AHEE__EE_Html_messenger__enqueue_scripts_styles hook.
485
-     *
486
-     * @since 4.5.0
487
-     * @return void
488
-     */
489
-    protected function _deregister_wp_hooks()
490
-    {
491
-        remove_all_actions('wp_head');
492
-        remove_all_actions('wp_footer');
493
-        remove_all_actions('wp_print_footer_scripts');
494
-        remove_all_actions('wp_enqueue_scripts');
495
-        global $wp_scripts, $wp_styles;
496
-        $wp_scripts = $wp_styles = array();
497
-        // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
498
-        add_action('wp_footer', 'wp_print_footer_scripts');
499
-        add_action('wp_print_footer_scripts', '_wp_footer_scripts');
500
-        add_action('wp_head', 'wp_enqueue_scripts');
501
-    }
502
-
503
-
504
-    /**
505
-     * Overwrite parent _get_main_template for display_html purposes.
506
-     *
507
-     * @since  4.5.0
508
-     * @param bool $preview
509
-     * @return string
510
-     */
511
-    protected function _get_main_template($preview = false)
512
-    {
513
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, 'main');
514
-        // include message type as a template arg
515
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
516
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
517
-    }
518
-
519
-
520
-    /**
521
-     * @return string
522
-     */
523
-    protected function _preview()
524
-    {
525
-        return $this->_send_message();
526
-    }
527
-
528
-
529
-    protected function _set_admin_settings_fields()
530
-    {
531
-    }
532
-
533
-
534
-    /**
535
-     * add the "powered by EE" credit link to the HTML receipt and invoice
536
-     *
537
-     * @param string $content
538
-     * @param string $content_again
539
-     * @param \EE_message_type $incoming_message_type
540
-     * @return string
541
-     */
542
-    public function add_powered_by_credit_link_to_receipt_and_invoice(
543
-        $content = '',
544
-        $content_again = '',
545
-        EE_message_type $incoming_message_type
546
-    ) {
547
-        if (($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt')
548
-            && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true)
549
-        ) {
550
-            $content .= \EEH_Template::powered_by_event_espresso(
551
-                'aln-cntr',
552
-                '',
553
-                array('utm_content' => 'messages_system')
554
-            )
555
-                . EEH_HTML::div(EEH_HTML::p('&nbsp;'));
556
-        }
557
-        return $content;
558
-    }
15
+	/**
16
+	 * The following are the properties that this messenger requires for displaying the html
17
+	 */
18
+	/**
19
+	 * This is the html body generated by the template via the message type.
20
+	 *
21
+	 * @var string
22
+	 */
23
+	protected $_content;
24
+
25
+
26
+	/**
27
+	 * This is for the page title that gets displayed.  (Why use "subject"?  Because the "title" tag in html is
28
+	 * equivalent to the "subject" of the page.
29
+	 *
30
+	 * @var string
31
+	 */
32
+	protected $_subject;
33
+
34
+
35
+	/**
36
+	 * EE_Html_messenger constructor.
37
+	 */
38
+	public function __construct()
39
+	{
40
+		// set properties
41
+		$this->name = 'html';
42
+		$this->description = __('This messenger outputs a message to a browser for display.', 'event_espresso');
43
+		$this->label = array(
44
+			'singular' => __('html', 'event_espresso'),
45
+			'plural' => __('html', 'event_espresso'),
46
+		);
47
+		$this->activate_on_install = true;
48
+		// add the "powered by EE" credit link to the HTML receipt and invoice
49
+		add_filter(
50
+			'FHEE__EE_Html_messenger___send_message__main_body',
51
+			array($this, 'add_powered_by_credit_link_to_receipt_and_invoice'),
52
+			10,
53
+			3
54
+		);
55
+		parent::__construct();
56
+	}
57
+
58
+
59
+	/**
60
+	 * HTML Messenger desires execution immediately.
61
+	 *
62
+	 * @see    parent::send_now() for documentation.
63
+	 * @since  4.9.0
64
+	 * @return bool
65
+	 */
66
+	public function send_now()
67
+	{
68
+		return true;
69
+	}
70
+
71
+
72
+	/**
73
+	 * HTML Messenger allows an empty to field.
74
+	 *
75
+	 * @see    parent::allow_empty_to_field() for documentation
76
+	 * @since  4.9.0
77
+	 * @return bool
78
+	 */
79
+	public function allow_empty_to_field()
80
+	{
81
+		return true;
82
+	}
83
+
84
+
85
+	/**
86
+	 * @see abstract declaration in EE_messenger for details.
87
+	 */
88
+	protected function _set_admin_pages()
89
+	{
90
+		$this->admin_registered_pages = array('events_edit' => true);
91
+	}
92
+
93
+
94
+	/**
95
+	 * @see abstract declaration in EE_messenger for details.
96
+	 */
97
+	protected function _set_valid_shortcodes()
98
+	{
99
+		$this->_valid_shortcodes = array();
100
+	}
101
+
102
+
103
+	/**
104
+	 * @see abstract declaration in EE_messenger for details.
105
+	 */
106
+	protected function _set_validator_config()
107
+	{
108
+		$this->_validator_config = array(
109
+			'subject' => array(
110
+				'shortcodes' => array('organization', 'primary_registration_details', 'email', 'transaction'),
111
+			),
112
+			'content' => array(
113
+				'shortcodes' => array(
114
+					'organization',
115
+					'primary_registration_list',
116
+					'primary_registration_details',
117
+					'email',
118
+					'transaction',
119
+					'event_list',
120
+					'payment_list',
121
+					'venue',
122
+					'line_item_list',
123
+					'messenger',
124
+					'ticket_list',
125
+				),
126
+			),
127
+			'event_list' => array(
128
+				'shortcodes' => array(
129
+					'event',
130
+					'ticket_list',
131
+					'venue',
132
+					'primary_registration_details',
133
+					'primary_registration_list',
134
+					'event_author',
135
+				),
136
+				'required' => array('[EVENT_LIST]'),
137
+			),
138
+			'ticket_list' => array(
139
+				'shortcodes' => array(
140
+					'attendee_list',
141
+					'ticket',
142
+					'datetime_list',
143
+					'primary_registration_details',
144
+					'line_item_list',
145
+					'venue',
146
+				),
147
+				'required' => array('[TICKET_LIST]'),
148
+			),
149
+			'ticket_line_item_no_pms' => array(
150
+				'shortcodes' => array('line_item', 'ticket'),
151
+				'required' => array('[TICKET_LINE_ITEM_LIST]'),
152
+			),
153
+			'ticket_line_item_pms' => array(
154
+				'shortcodes' => array('line_item', 'ticket', 'line_item_list'),
155
+				'required' => array('[TICKET_LINE_ITEM_LIST]'),
156
+			),
157
+			'price_modifier_line_item_list' => array(
158
+				'shortcodes' => array('line_item'),
159
+				'required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
160
+			),
161
+			'datetime_list' => array(
162
+				'shortcodes' => array('datetime'),
163
+				'required' => array('[DATETIME_LIST]'),
164
+			),
165
+			'attendee_list' => array(
166
+				'shortcodes' => array('attendee'),
167
+				'required' => array('[ATTENDEE_LIST]'),
168
+			),
169
+			'tax_line_item_list' => array(
170
+				'shortcodes' => array('line_item'),
171
+				'required' => array('[TAX_LINE_ITEM_LIST]'),
172
+			),
173
+			'additional_line_item_list' => array(
174
+				'shortcodes' => array('line_item'),
175
+				'required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
176
+			),
177
+			'payment_list' => array(
178
+				'shortcodes' => array('payment'),
179
+				'required' => array('[PAYMENT_LIST_*]'),
180
+			),
181
+		);
182
+	}
183
+
184
+
185
+	/**
186
+	 * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger
187
+	 * is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary
188
+	 * (i.e. swap out css files or something else).
189
+	 *
190
+	 * @since 4.5.0
191
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
192
+	 * @return void
193
+	 */
194
+	public function do_secondary_messenger_hooks($sending_messenger_name)
195
+	{
196
+		if ($sending_messenger_name === 'pdf') {
197
+			add_filter('EE_messenger__get_variation__variation', array($this, 'add_html_css'), 10, 8);
198
+		}
199
+	}
200
+
201
+
202
+	/**
203
+	 * @param                            $variation_path
204
+	 * @param \EE_Messages_Template_Pack $template_pack
205
+	 * @param                            $messenger_name
206
+	 * @param                            $message_type_name
207
+	 * @param                            $url
208
+	 * @param                            $type
209
+	 * @param                            $variation
210
+	 * @param                            $skip_filters
211
+	 * @return string
212
+	 */
213
+	public function add_html_css(
214
+		$variation_path,
215
+		EE_Messages_Template_Pack $template_pack,
216
+		$messenger_name,
217
+		$message_type_name,
218
+		$url,
219
+		$type,
220
+		$variation,
221
+		$skip_filters
222
+	) {
223
+		$variation = $template_pack->get_variation(
224
+			$this->name,
225
+			$message_type_name,
226
+			$type,
227
+			$variation,
228
+			$url,
229
+			'.css',
230
+			$skip_filters
231
+		);
232
+		return $variation;
233
+	}
234
+
235
+
236
+	/**
237
+	 * Takes care of enqueuing any necessary scripts or styles for the page.  A do_action() so message types using this
238
+	 * messenger can add their own js.
239
+	 *
240
+	 * @return void.
241
+	 */
242
+	public function enqueue_scripts_styles()
243
+	{
244
+		parent::enqueue_scripts_styles();
245
+		do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles');
246
+	}
247
+
248
+
249
+	/**
250
+	 * _set_template_fields
251
+	 * This sets up the fields that a messenger requires for the message to go out.
252
+	 *
253
+	 * @access  protected
254
+	 * @return void
255
+	 */
256
+	protected function _set_template_fields()
257
+	{
258
+		// any extra template fields that are NOT used by the messenger
259
+		// but will get used by a messenger field for shortcode replacement
260
+		// get added to the 'extra' key in an associated array
261
+		// indexed by the messenger field they relate to.
262
+		// This is important for the Messages_admin to know what fields to display to the user.
263
+		// Also, notice that the "values" are equal to the field type
264
+		// that messages admin will use to know what kind of field to display.
265
+		// The values ALSO have one index labeled "shortcode".
266
+		// The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE])
267
+		// is required in order for this extra field to be displayed.
268
+		//  If the required shortcode isn't part of the shortcodes array
269
+		// then the field is not needed and will not be displayed/parsed.
270
+		$this->_template_fields = array(
271
+			'subject' => array(
272
+				'input' => 'text',
273
+				'label' => __('Page Title', 'event_espresso'),
274
+				'type' => 'string',
275
+				'required' => true,
276
+				'validation' => true,
277
+				'css_class' => 'large-text',
278
+				'format' => '%s',
279
+			),
280
+			'content' => '',
281
+			// left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
282
+			'extra' => array(
283
+				'content' => array(
284
+					'main' => array(
285
+						'input' => 'wp_editor',
286
+						'label' => __('Main Content', 'event_espresso'),
287
+						'type' => 'string',
288
+						'required' => true,
289
+						'validation' => true,
290
+						'format' => '%s',
291
+						'rows' => '15',
292
+					),
293
+					'event_list' => array(
294
+						'input' => 'wp_editor',
295
+						'label' => '[EVENT_LIST]',
296
+						'type' => 'string',
297
+						'required' => true,
298
+						'validation' => true,
299
+						'format' => '%s',
300
+						'rows' => '15',
301
+						'shortcodes_required' => array('[EVENT_LIST]'),
302
+					),
303
+					'ticket_list' => array(
304
+						'input' => 'textarea',
305
+						'label' => '[TICKET_LIST]',
306
+						'type' => 'string',
307
+						'required' => true,
308
+						'validation' => true,
309
+						'format' => '%s',
310
+						'css_class' => 'large-text',
311
+						'rows' => '10',
312
+						'shortcodes_required' => array('[TICKET_LIST]'),
313
+					),
314
+					'ticket_line_item_no_pms' => array(
315
+						'input' => 'textarea',
316
+						'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
317
+							'Ticket Line Item List with no Price Modifiers',
318
+							'event_espresso'
319
+						),
320
+						'type' => 'string',
321
+						'required' => false,
322
+						'validation' => true,
323
+						'format' => '%s',
324
+						'css_class' => 'large-text',
325
+						'rows' => '5',
326
+						'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
327
+					),
328
+					'ticket_line_item_pms' => array(
329
+						'input' => 'textarea',
330
+						'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
331
+							'Ticket Line Item List with Price Modifiers',
332
+							'event_espresso'
333
+						),
334
+						'type' => 'string',
335
+						'required' => false,
336
+						'validation' => true,
337
+						'format' => '%s',
338
+						'css_class' => 'large-text',
339
+						'rows' => '5',
340
+						'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
341
+					),
342
+					'price_modifier_line_item_list' => array(
343
+						'input' => 'textarea',
344
+						'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]',
345
+						'type' => 'string',
346
+						'required' => false,
347
+						'validation' => true,
348
+						'format' => '%s',
349
+						'css_class' => 'large-text',
350
+						'rows' => '5',
351
+						'shortcodes_required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
352
+					),
353
+					'datetime_list' => array(
354
+						'input' => 'textarea',
355
+						'label' => '[DATETIME_LIST]',
356
+						'type' => 'string',
357
+						'required' => true,
358
+						'validation' => true,
359
+						'format' => '%s',
360
+						'css_class' => 'large-text',
361
+						'rows' => '5',
362
+						'shortcodes_required' => array('[DATETIME_LIST]'),
363
+					),
364
+					'attendee_list' => array(
365
+						'input' => 'textarea',
366
+						'label' => '[ATTENDEE_LIST]',
367
+						'type' => 'string',
368
+						'required' => true,
369
+						'validation' => true,
370
+						'format' => '%s',
371
+						'css_class' => 'large-text',
372
+						'rows' => '5',
373
+						'shortcodes_required' => array('[ATTENDEE_LIST]'),
374
+					),
375
+					'tax_line_item_list' => array(
376
+						'input' => 'textarea',
377
+						'label' => '[TAX_LINE_ITEM_LIST]',
378
+						'type' => 'string',
379
+						'required' => false,
380
+						'validation' => true,
381
+						'format' => '%s',
382
+						'css_class' => 'large-text',
383
+						'rows' => '5',
384
+						'shortcodes_required' => array('[TAX_LINE_ITEM_LIST]'),
385
+					),
386
+					'additional_line_item_list' => array(
387
+						'input' => 'textarea',
388
+						'label' => '[ADDITIONAL_LINE_ITEM_LIST]',
389
+						'type' => 'string',
390
+						'required' => false,
391
+						'validation' => true,
392
+						'format' => '%s',
393
+						'css_class' => 'large-text',
394
+						'rows' => '5',
395
+						'shortcodes_required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
396
+					),
397
+					'payment_list' => array(
398
+						'input' => 'textarea',
399
+						'label' => '[PAYMENT_LIST]',
400
+						'type' => 'string',
401
+						'required' => true,
402
+						'validation' => true,
403
+						'format' => '%s',
404
+						'css_class' => 'large-text',
405
+						'rows' => '5',
406
+						'shortcodes_required' => array('[PAYMENT_LIST_*]'),
407
+					),
408
+				),
409
+			),
410
+		);
411
+	}
412
+
413
+
414
+	/**
415
+	 * @see   definition of this method in parent
416
+	 * @since 4.5.0
417
+	 */
418
+	protected function _set_default_message_types()
419
+	{
420
+		$this->_default_message_types = array('receipt', 'invoice');
421
+	}
422
+
423
+
424
+	/**
425
+	 * @see   definition of this method in parent
426
+	 * @since 4.5.0
427
+	 */
428
+	protected function _set_valid_message_types()
429
+	{
430
+		$this->_valid_message_types = array('receipt', 'invoice');
431
+	}
432
+
433
+
434
+	/**
435
+	 * Displays the message in the browser.
436
+	 *
437
+	 * @since 4.5.0
438
+	 * @return string.
439
+	 */
440
+	protected function _send_message()
441
+	{
442
+		$this->_template_args = array(
443
+			'page_title' => $this->_subject,
444
+			'base_css' => $this->get_variation(
445
+				$this->_tmp_pack,
446
+				$this->_incoming_message_type->name,
447
+				true,
448
+				'base',
449
+				$this->_variation
450
+			),
451
+			'print_css' => $this->get_variation(
452
+				$this->_tmp_pack,
453
+				$this->_incoming_message_type->name,
454
+				true,
455
+				'print',
456
+				$this->_variation
457
+			),
458
+			'main_css' => $this->get_variation(
459
+				$this->_tmp_pack,
460
+				$this->_incoming_message_type->name,
461
+				true,
462
+				'main',
463
+				$this->_variation
464
+			),
465
+			'main_body' => wpautop(
466
+				apply_filters(
467
+					'FHEE__EE_Html_messenger___send_message__main_body',
468
+					$this->_content,
469
+					$this->_content,
470
+					$this->_incoming_message_type
471
+				)
472
+			)
473
+		);
474
+		$this->_deregister_wp_hooks();
475
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
476
+		echo $this->_get_main_template();
477
+		exit();
478
+	}
479
+
480
+
481
+	/**
482
+	 * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't
483
+	 * interfere with our templates.  If users want to add any custom styles or scripts they must use the
484
+	 * AHEE__EE_Html_messenger__enqueue_scripts_styles hook.
485
+	 *
486
+	 * @since 4.5.0
487
+	 * @return void
488
+	 */
489
+	protected function _deregister_wp_hooks()
490
+	{
491
+		remove_all_actions('wp_head');
492
+		remove_all_actions('wp_footer');
493
+		remove_all_actions('wp_print_footer_scripts');
494
+		remove_all_actions('wp_enqueue_scripts');
495
+		global $wp_scripts, $wp_styles;
496
+		$wp_scripts = $wp_styles = array();
497
+		// just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
498
+		add_action('wp_footer', 'wp_print_footer_scripts');
499
+		add_action('wp_print_footer_scripts', '_wp_footer_scripts');
500
+		add_action('wp_head', 'wp_enqueue_scripts');
501
+	}
502
+
503
+
504
+	/**
505
+	 * Overwrite parent _get_main_template for display_html purposes.
506
+	 *
507
+	 * @since  4.5.0
508
+	 * @param bool $preview
509
+	 * @return string
510
+	 */
511
+	protected function _get_main_template($preview = false)
512
+	{
513
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, 'main');
514
+		// include message type as a template arg
515
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
516
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
517
+	}
518
+
519
+
520
+	/**
521
+	 * @return string
522
+	 */
523
+	protected function _preview()
524
+	{
525
+		return $this->_send_message();
526
+	}
527
+
528
+
529
+	protected function _set_admin_settings_fields()
530
+	{
531
+	}
532
+
533
+
534
+	/**
535
+	 * add the "powered by EE" credit link to the HTML receipt and invoice
536
+	 *
537
+	 * @param string $content
538
+	 * @param string $content_again
539
+	 * @param \EE_message_type $incoming_message_type
540
+	 * @return string
541
+	 */
542
+	public function add_powered_by_credit_link_to_receipt_and_invoice(
543
+		$content = '',
544
+		$content_again = '',
545
+		EE_message_type $incoming_message_type
546
+	) {
547
+		if (($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt')
548
+			&& apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true)
549
+		) {
550
+			$content .= \EEH_Template::powered_by_event_espresso(
551
+				'aln-cntr',
552
+				'',
553
+				array('utm_content' => 'messages_system')
554
+			)
555
+				. EEH_HTML::div(EEH_HTML::p('&nbsp;'));
556
+		}
557
+		return $content;
558
+	}
559 559
 }
Please login to merge, or discard this patch.