C:\xampp\htdocs\landing\wp-content\plugins\wpforms-lite\src\Admin\Pages\SMTP.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
<?php

namespace WPForms\Admin\Pages;

/**
 * SMTP Sub-page.
 *
 * @since 1.5.7
 */
class SMTP {

    
/**
     * Admin menu page slug.
     *
     * @since 1.5.7
     *
     * @var string
     */
    
const SLUG 'wpforms-smtp';

    
/**
     * Configuration.
     *
     * @since 1.5.7
     *
     * @var array
     */
    
private $config = array(
        
'lite_plugin'       => 'wp-mail-smtp/wp_mail_smtp.php',
        
'lite_wporg_url'    => 'https://wordpress.org/plugins/wp-mail-smtp/',
        
'lite_download_url' => 'https://downloads.wordpress.org/plugin/wp-mail-smtp.zip',
        
'pro_plugin'        => 'wp-mail-smtp-pro/wp_mail_smtp.php',
        
'smtp_settings'     => 'admin.php?page=wp-mail-smtp',
    );

    
/**
     * Runtime data used for generating page HTML.
     *
     * @since 1.5.7
     *
     * @var array
     */
    
private $output_data = array();

    
/**
     * Constructor.
     *
     * @since 1.5.7
     */
    
public function __construct() {

        if ( ! \
wpforms_current_user_can() ) {
            return;
        }

        
$this->hooks();
    }

    
/**
     * Hooks.
     *
     * @since 1.5.7
     */
    
public function hooks() {

        if ( 
wp_doing_ajax() ) {
            
add_action'wp_ajax_wpforms_smtp_page_check_plugin_status', array( $this'ajax_check_plugin_status' ) );
        }

        
// Check what page we are on.
        
$page = isset( $_GET['page'] ) ? \sanitize_key( \wp_unslash$_GET['page'] ) ) : ''// phpcs:ignore WordPress.CSRF.NonceVerification

        // Only load if we are actually on the SMTP page.
        
if ( self::SLUG !== $page ) {
            return;
        }

        
add_action'admin_init', array( $this'redirect_to_smtp_settings' ) );
        
add_filter'wpforms_admin_header''__return_false' );
        
add_action'wpforms_admin_page', array( $this'output' ) );
        
add_action'admin_enqueue_scripts', array( $this'enqueue_assets' ) );

        
// Hook for addons.
        
do_action'wpforms_admin_pages_smtp_hooks' );
    }

    
/**
     * Enqueue JS and CSS files.
     *
     * @since 1.5.7
     */
    
public function enqueue_assets() {

        
$min = \wpforms_get_min_suffix();

        
// Lity.
        
wp_enqueue_style(
            
'wpforms-lity',
            
WPFORMS_PLUGIN_URL 'assets/css/lity.min.css',
            
null,
            
'3.0.0'
        
);

        
wp_enqueue_script(
            
'wpforms-lity',
            
WPFORMS_PLUGIN_URL 'assets/js/lity.min.js',
            array( 
'jquery' ),
            
'3.0.0',
            
true
        
);

        
wp_enqueue_script(
            
'wpforms-admin-page-smtp',
            
WPFORMS_PLUGIN_URL "assets/js/components/admin/pages/smtp{$min}.js",
            array( 
'jquery' ),
            
WPFORMS_VERSION,
            
true
        
);

        \
wp_localize_script(
            
'wpforms-admin-page-smtp',
            
'wpforms_pluginlanding',
            
$this->get_js_strings()
        );
    }

    
/**
     * JS Strings.
     *
     * @since 1.5.7
     *
     * @return array Array of strings.
     */
    
protected function get_js_strings() {

        
$error_could_not_install sprintf(
            
wp_kses/* translators: %s - Lite plugin download URL. */
                
__'Could not install plugin. Please <a href="%s">download</a> and install manually.''wpforms-lite' ),
                array(
                    
'a' => array(
                        
'href' => true,
                    ),
                )
            ),
            
esc_url$this->config['lite_download_url'] )
        );

        
$error_could_not_activate sprintf(
            
wp_kses/* translators: %s - Lite plugin download URL. */
                
__'Could not activate plugin. Please activate from the <a href="%s">Plugins page</a>.''wpforms-lite' ),
                array(
                    
'a' => array(
                        
'href' => true,
                    ),
                )
            ),
            
esc_urladmin_url'plugins.php' ) )
        );

        return array(
            
'installing'               => esc_html__'Installing...''wpforms-lite' ),
            
'activating'               => esc_html__'Activating...''wpforms-lite' ),
            
'activated'                => esc_html__'WP Mail SMTP Installed & Activated''wpforms-lite' ),
            
'install_now'              => esc_html__'Install Now''wpforms-lite' ),
            
'activate_now'             => esc_html__'Activate Now''wpforms-lite' ),
            
'download_now'             => esc_html__'Download Now''wpforms-lite' ),
            
'plugins_page'             => esc_html__'Go to Plugins page''wpforms-lite' ),
            
'error_could_not_install'  => $error_could_not_install,
            
'error_could_not_activate' => $error_could_not_activate,
            
'manual_install_url'       => $this->config['lite_download_url'],
            
'manual_activate_url'      => admin_url'plugins.php' ),
            
'smtp_settings_button'     => esc_html__'Go to SMTP Settings''wpforms-lite' ),
        );
    }

    
/**
     * Generate and output page HTML.
     *
     * @since 1.5.7
     */
    
public function output() {

        echo 
'<div id="wpforms-admin-smtp" class="wrap wpforms-admin-wrap wpforms-admin-plugin-landing">';

        
$this->output_section_heading();
        
$this->output_section_screenshot();
        
$this->output_section_step_install();
        
$this->output_section_step_setup();

        echo 
'</div>';
    }

    
/**
     * Generate and output heading section HTML.
     *
     * @since 1.5.7
     */
    
protected function output_section_heading() {

        
// Heading section.
        
printf(
            
'<section class="top">
                <img class="img-top" src="%1$s" srcset="%2$s 2x" alt="%3$s"/>
                <h1>%4$s</h1>
                <p>%5$s</p>
            </section>'
,
            
esc_urlWPFORMS_PLUGIN_URL 'assets/images/smtp/wpforms-wpmailsmtp.png' ),
            
esc_urlWPFORMS_PLUGIN_URL 'assets/images/smtp/wpforms-wpmailsmtp@2x.png' ),
            
esc_attr__'WPForms ♥ WP Mail SMTP''wpforms-lite' ),
            
esc_html__'Making Email Deliverability Easy for WordPress''wpforms-lite' ),
            
esc_html__'WP Mail SMTP allows you to easily set up WordPress to use a trusted provider to reliably send emails, including form notifications. Built by the same folks behind WPForms.''wpforms-lite' )
        );
    }

    
/**
     * Generate and output screenshot section HTML.
     *
     * @since 1.5.7
     */
    
protected function output_section_screenshot() {

        
// Screenshot section.
        
printf(
            
'<section class="screenshot">
                <div class="cont">
                    <img src="%1$s" alt="%2$s"/>
                    <a href="%3$s" class="hover" data-lity></a>
                </div>
                <ul>
                    <li>%4$s</li>
                    <li>%5$s</li>
                    <li>%6$s</li>
                    <li>%7$s</li>
                </ul>
            </section>'
,
            
esc_urlWPFORMS_PLUGIN_URL 'assets/images/smtp/screenshot-tnail.png' ),
            
esc_attr__'WP Mail SMTP screenshot''wpforms-lite' ),
            
esc_urlWPFORMS_PLUGIN_URL 'assets/images/smtp/screenshot-full.png' ),
            
esc_html__'Over 2,000,000 websites use WP Mail SMTP.''wpforms-lite' ),
            
esc_html__'Send emails authenticated via trusted parties.''wpforms-lite' ),
            
esc_html__'Transactional Mailers: SMTP.com, Pepipost, SendinBlue, Mailgun, SendGrid, Amazon SES.''wpforms-lite' ),
            
esc_html__'Web Mailers: Gmail, G Suite, Office 365, Outlook.com.''wpforms-lite' )
        );
    }

    
/**
     * Generate and output step 'Install' section HTML.
     *
     * @since 1.5.7
     */
    
protected function output_section_step_install() {

        
$step $this->get_data_step_install();

        if ( empty( 
$step ) ) {
            return;
        }

        
$button_format       '<button class="button %3$s" data-plugin="%1$s" data-action="%4$s">%2$s</button>';
        
$button_allowed_html = [
            
'button' => [
                
'class'       => true,
                
'data-plugin' => true,
                
'data-action' => true,
            ],
        ];

        if (
            ! 
$this->output_data['plugin_installed'] &&
            ! 
$this->output_data['pro_plugin_installed'] &&
            ! 
wpforms_can_install'plugin' )
        ) {
            
$button_format       '<a class="link" href="%1$s" target="_blank" rel="nofollow noopener">%2$s <span aria-hidden="true" class="dashicons dashicons-external"></span></a>';
            
$button_allowed_html = [
                
'a'    => [
                    
'class'  => true,
                    
'href'   => true,
                    
'target' => true,
                    
'rel'    => true,
                ],
                
'span' => [
                    
'class'       => true,
                    
'aria-hidden' => true,
                ],
            ];
        }

        
$button sprintf$button_formatesc_attr$step['plugin'] ), esc_html$step['button_text'] ), esc_attr$step['button_class'] ), esc_attr$step['button_action'] ) );

        
printf(
            
'<section class="step step-install">
                <aside class="num">
                    <img src="%1$s" alt="%2$s" />
                    <i class="loader hidden"></i>
                </aside>
                <div>
                    <h2>%3$s</h2>
                    <p>%4$s</p>
                    %5$s
                </div>
            </section>'
,
            
esc_urlWPFORMS_PLUGIN_URL 'assets/images/' $step['icon'] ),
            
esc_attr__'Step 1''wpforms-lite' ),
            
esc_html$step['heading'] ),
            
esc_html$step['description'] ),
            
wp_kses$button$button_allowed_html )
        );
    }

    
/**
     * Generate and output step 'Setup' section HTML.
     *
     * @since 1.5.7
     */
    
protected function output_section_step_setup() {

        
$step $this->get_data_step_setup();

        if ( empty( 
$step ) ) {
            return;
        }

        
printf(
            
'<section class="step step-setup %1$s">
                <aside class="num">
                    <img src="%2$s" alt="%3$s" />
                    <i class="loader hidden"></i>
                </aside>
                <div>
                    <h2>%4$s</h2>
                    <p>%5$s</p>
                    <button class="button %6$s" data-url="%7$s">%8$s</button>
                </div>
            </section>'
,
            
esc_attr$step['section_class'] ),
            
esc_urlWPFORMS_PLUGIN_URL 'assets/images/' $step['icon'] ),
            
esc_attr__'Step 2''wpforms-lite' ),
            
esc_html__'Set Up WP Mail SMTP''wpforms-lite' ),
            
esc_html__'Select and configure your mailer.''wpforms-lite' ),
            
esc_attr$step['button_class'] ),
            
esc_urladmin_url$this->config['smtp_settings'] ) ),
            
esc_html$step['button_text'] )
        );
    }

    
/**
     * Step 'Install' data.
     *
     * @since 1.5.7
     *
     * @return array Step data.
     */
    
protected function get_data_step_install() {

        
$step                = array();
        
$step['heading']     = esc_html__'Install and Activate WP Mail SMTP''wpforms-lite' );
        
$step['description'] = esc_html__'Install WP Mail SMTP from the WordPress.org plugin repository.''wpforms-lite' );

        
$this->output_data['all_plugins']          = get_plugins();
        
$this->output_data['plugin_installed']     = array_key_exists$this->config['lite_plugin'], $this->output_data['all_plugins'] );
        
$this->output_data['pro_plugin_installed'] = array_key_exists$this->config['pro_plugin'], $this->output_data['all_plugins'] );
        
$this->output_data['plugin_activated']     = false;
        
$this->output_data['plugin_setup']         = false;

        if ( ! 
$this->output_data['plugin_installed'] && ! $this->output_data['pro_plugin_installed'] ) {
            
$step['icon']          = 'step-1.svg';
            
$step['button_text']   = esc_html__'Install WP Mail SMTP''wpforms-lite' );
            
$step['button_class']  = '';
            
$step['button_action'] = 'install';
            
$step['plugin']        = $this->config['lite_download_url'];

            if ( ! 
wpforms_can_install'plugin' ) ) {
                
$step['heading']     = esc_html__'WP Mail SMTP''wpforms-lite' );
                
$step['description'] = '';
                
$step['button_text'] = esc_html__'WP Mail SMTP on WordPress.org''wpforms-lite' );
                
$step['plugin']      = $this->config['lite_wporg_url'];
            }
        } else {
            
$this->output_data['plugin_activated'] = $this->is_smtp_activated();
            
$this->output_data['plugin_setup']     = $this->is_smtp_configured();
            
$step['icon']                          = $this->output_data['plugin_activated'] ? 'step-complete.svg' 'step-1.svg';
            
$step['button_text']                   = $this->output_data['plugin_activated'] ? esc_html__'WP Mail SMTP Installed & Activated''wpforms-lite' ) : esc_html__'Activate WP Mail SMTP''wpforms-lite' );
            
$step['button_class']                  = $this->output_data['plugin_activated'] ? 'grey disabled' '';
            
$step['button_action']                 = $this->output_data['plugin_activated'] ? '' 'activate';
            
$step['plugin']                        = $this->output_data['pro_plugin_installed'] ? $this->config['pro_plugin'] : $this->config['lite_plugin'];
        }

        return 
$step;
    }

    
/**
     * Step 'Setup' data.
     *
     * @since 1.5.7
     *
     * @return array Step data.
     */
    
protected function get_data_step_setup() {

        
$step = array();

        
$step['icon']          = 'step-2.svg';
        
$step['section_class'] = $this->output_data['plugin_activated'] ? '' 'grey';
        
$step['button_text']   = esc_html__'Start Setup''wpforms-lite' );
        
$step['button_class']  = 'grey disabled';

        if ( 
$this->output_data['plugin_setup'] ) {
            
$step['icon']          = 'step-complete.svg';
            
$step['section_class'] = '';
            
$step['button_text']   = esc_html__'Go to SMTP settings''wpforms-lite' );
        } else {
            
$step['button_class'] = $this->output_data['plugin_activated'] ? '' 'grey disabled';
        }

        return 
$step;
    }

    
/**
     * Ajax endpoint. Check plugin setup status.
     * Used to properly init step 'Setup' section after completing step 'Install'.
     *
     * @since 1.5.7
     */
    
public function ajax_check_plugin_status() {

        
// Security checks.
        
if (
            ! 
check_ajax_referer'wpforms-admin''nonce'false ) ||
            ! 
wpforms_current_user_can()
        ) {
            
wp_send_json_error(
                array(
                    
'error' => esc_html__'You do not have permission.''wpforms-lite' ),
                )
            );
        }

        
$result = array();

        if ( ! 
$this->is_smtp_activated() ) {
            
wp_send_json_error(
                array(
                    
'error' => esc_html__'Plugin unavailable.''wpforms-lite' ),
                )
            );
        }

        
$result['setup_status']  = (int) $this->is_smtp_configured();
        
$result['license_level'] = wp_mail_smtp()->get_license_type();

        
wp_send_json_success$result );
    }

    
/**
     * Get $phpmailer instance.
     *
     * @since 1.5.7
     * @since 1.6.1.2 Conditionally returns $phpmailer v5 or v6.
     *
     * @return \PHPMailer|\PHPMailer\PHPMailer\PHPMailer Instance of PHPMailer.
     */
    
protected function get_phpmailer() {

        if ( 
version_compareget_bloginfo'version' ), '5.5-alpha''<' ) ) {
            
$phpmailer $this->get_phpmailer_v5();
        } else {
            
$phpmailer $this->get_phpmailer_v6();
        }

        return 
$phpmailer;
    }

    
/**
     * Get $phpmailer v5 instance.
     *
     * @since 1.6.1.2
     *
     * @return \PHPMailer Instance of PHPMailer.
     */
    
private function get_phpmailer_v5() {

        global 
$phpmailer;

        if ( ! ( 
$phpmailer instanceof \PHPMailer ) ) {
            require_once 
ABSPATH WPINC '/class-phpmailer.php';
            require_once 
ABSPATH WPINC '/class-smtp.php';
            
$phpmailer = new \PHPMailertrue ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
        
}

        return 
$phpmailer;
    }

    
/**
     * Get $phpmailer v6 instance.
     *
     * @since 1.6.1.2
     *
     * @return \PHPMailer\PHPMailer\PHPMailer Instance of PHPMailer.
     */
    
private function get_phpmailer_v6() {

        global 
$phpmailer;

        if ( ! ( 
$phpmailer instanceof \PHPMailer\PHPMailer\PHPMailer ) ) {
            require_once 
ABSPATH WPINC '/PHPMailer/PHPMailer.php';
            require_once 
ABSPATH WPINC '/PHPMailer/SMTP.php';
            require_once 
ABSPATH WPINC '/PHPMailer/Exception.php';
            
$phpmailer = new \PHPMailer\PHPMailer\PHPMailertrue ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
        
}

        return 
$phpmailer;
    }

    
/**
     * Whether WP Mail SMTP plugin configured or not.
     *
     * @since 1.5.7
     *
     * @return bool True if some mailer is selected and configured properly.
     */
    
protected function is_smtp_configured() {

        if ( ! 
$this->is_smtp_activated() ) {
            return 
false;
        }

        
$phpmailer $this->get_phpmailer();

        
$mailer             = \WPMailSMTP\Options::init()->get'mail''mailer' );
        
$is_mailer_complete = empty( $mailer ) ? false wp_mail_smtp()->get_providers()->get_mailer$mailer$phpmailer )->is_mailer_complete();

        return 
'mail' !== $mailer && $is_mailer_complete;
    }

    
/**
     * Whether WP Mail SMTP plugin active or not.
     *
     * @since 1.5.7
     *
     * @return bool True if SMTP plugin is active.
     */
    
protected function is_smtp_activated() {

        return 
function_exists'wp_mail_smtp' ) && ( is_plugin_active$this->config['lite_plugin'] ) || is_plugin_active$this->config['pro_plugin'] ) );
    }

    
/**
     * Redirect to SMTP settings page.
     *
     * @since 1.5.7
     */
    
public function redirect_to_smtp_settings() {

        
// Redirect to SMTP plugin if it is activated.
        
if ( $this->is_smtp_configured() ) {
            
wp_safe_redirectadmin_url$this->config['smtp_settings'] ) );
            exit;
        }
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586