PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.05.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.05.02
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / controllers / FrmSMTPController.php

FrmSMTPController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 4.05.02, at classes/controllers/FrmSMTPController.php

537 lines 16.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * SMTP Sub-page.
5 *
6 * @since 4.04.04
7 */
8 class FrmSMTPController {
9
10 /**
11 * Admin menu page slug.
12 *
13 * @since 4.04.04
14 *
15 * @var string
16 */
17 private $slug = 'formidable-smtp';
18
19 /**
20 * @since 4.04.04
21 *
22 * @var array
23 */
24 private $config = array(
25 'lite_plugin' => 'wp-mail-smtp/wp_mail_smtp.php',
26 'lite_download_url' => 'https://downloads.wordpress.org/plugin/wp-mail-smtp.zip',
27 'pro_plugin' => 'wp-mail-smtp-pro/wp_mail_smtp.php',
28 'smtp_settings' => 'admin.php?page=wp-mail-smtp',
29 );
30
31 /**
32 * Runtime data used for generating page HTML.
33 *
34 * @since 4.04.04
35 *
36 * @var array
37 */
38 private $output_data = array();
39
40 /**
41 * Hooks.
42 *
43 * @since 4.04.04
44 */
45 public static function load_hooks() {
46
47 add_filter( 'wp_mail_smtp_is_white_labeled', '__return_true' );
48
49 $self = new self();
50 if ( wp_doing_ajax() ) {
51 add_action( 'wp_ajax_frm_smtp_page_check_plugin_status', array( $self, 'ajax_check_plugin_status' ) );
52 }
53
54 add_filter( 'wp_mail_smtp_core_get_upgrade_link', array( $self, 'link' ) );
55 add_action( 'admin_menu', array( $self, 'menu' ), 999 );
56 add_action( 'wp_mail_smtp_core_recommendations_plugins', 'FrmAppController::remove_wpforms_nag' );
57
58 // Only load if we are actually on the SMTP page.
59 if ( ! FrmAppHelper::is_admin_page( $self->slug ) ) {
60 return;
61 }
62
63 add_action( 'admin_init', array( $self, 'redirect_to_smtp_settings' ) );
64
65 // Hook for addons.
66 do_action( 'frm_admin_pages_smtp_hooks' );
67 }
68
69 /**
70 * Customize the upgrade link.
71 */
72 public function link( $link ) {
73 $new_link = 'formidableforms.com/go-wp-mail-smtp/?urllink=wpmailsmtp%2Ecom%2Flite%2Dupgrade&';
74 $link = str_replace( 'wpmailsmtp.com/lite-upgrade/?', $new_link, $link );
75 return $link;
76 }
77
78 /**
79 * Don't nag people to install WPForms
80 *
81 * @since 4.04.04
82 */
83 public static function remove_wpforms_nag( $upsell ) {
84 if ( is_array( $upsell ) ) {
85 foreach ( $upsell as $k => $plugin ) {
86 if ( strpos( $plugin['slug'], 'wpforms' ) !== false ) {
87 unset( $upsell[ $k ] );
88 }
89 }
90 }
91
92 return $upsell;
93 }
94
95 /**
96 * SMTP submenu page.
97 */
98 public function menu() {
99 add_submenu_page( 'formidable', __( 'SMTP', 'formidable' ) . ' | Formidable', __( 'SMTP', 'formidable' ), 'activate_plugins', $this->slug, array( $this, 'output' ) );
100 }
101
102 /**
103 * Generate and output page HTML.
104 *
105 * @since 4.04.04
106 */
107 public function output() {
108 FrmAppHelper::include_svg();
109 $this->css();
110
111 echo '<div id="frm-admin-smtp" class="wrap frm-wrap frm-admin-plugin-landing">';
112
113 $this->output_section_heading();
114 $this->output_section_screenshot();
115 $this->output_section_step_install();
116 $this->output_section_step_setup();
117
118 echo '</div>';
119 }
120
121 /**
122 * Generate and output heading section HTML.
123 *
124 * @since 4.04.04
125 */
126 protected function output_section_heading() {
127 $size = array(
128 'height' => 90,
129 'width' => 90,
130 );
131
132 // Heading section.
133 ?>
134 <section class="top">
135 <div class="frm-smtp-logos">
136 <?php
137 FrmAppHelper::show_logo( $size );
138 FrmAppHelper::icon_by_class(
139 'frmfont frm_heart_solid_icon',
140 array(
141 'aria-label' => 'Loves',
142 'style' => 'width:30px;height:30px;margin:0 35px;',
143 'color' => '#d11c25',
144 )
145 );
146 $this->stmp_logo();
147 ?>
148 </div>
149 <h1><?php esc_html_e( 'Making Email Deliverability Easy for WordPress', 'formidable' ); ?></h1>
150 <p><?php esc_html_e( 'WP Mail SMTP allows you to easily set up WordPress to use a trusted provider to reliably send emails, including form notifications.', 'formidable' ); ?></p>
151 </section>
152 <?php
153 }
154
155 /**
156 * Generate and output screenshot section HTML.
157 *
158 * @since 4.04.04
159 */
160 protected function output_section_screenshot() {
161
162 printf(
163 '<section class="screenshot">
164 <div class="cont">
165 <img src="%1$s" alt="%2$s"/>
166 </div>
167 <ul>
168 <li>%3$s %4$s</li>
169 <li>%3$s %5$s</li>
170 <li>%3$s %6$s</li>
171 <li>%3$s %7$s</li>
172 </ul>
173 </section>',
174 esc_url( FrmAppHelper::plugin_url() . '/images/smtp-screenshot-tnail.png' ),
175 esc_attr__( 'WP Mail SMTP screenshot', 'formidable' ),
176 '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 492 492" width="14" height="14"><path d="M484 227L306 49a27 27 0 00-38 0l-16 16a27 27 0 000 38l104 105H27c-15 0-27 11-27 26v23c0 15 12 27 27 27h330L252 389a27 27 0 000 38l16 16a27 27 0 0038 0l178-178a27 27 0 000-38z" fill="#5bbfa5"/></svg> &nbsp;',
177 esc_html__( 'Over 1,000,000 websites use WP Mail SMTP.', 'formidable' ),
178 esc_html__( 'Send emails authenticated via trusted parties.', 'formidable' ),
179 esc_html__( 'Transactional Mailers: Pepipost, SendinBlue, Mailgun, SendGrid, Amazon SES.', 'formidable' ),
180 esc_html__( 'Web Mailers: Gmail, G Suite, Office 365, Outlook.com.', 'formidable' )
181 );
182 }
183
184 /**
185 * Generate and output step 'Install' section HTML.
186 *
187 * @since 4.04.04
188 */
189 protected function output_section_step_install() {
190
191 $step = $this->get_data_step_install();
192
193 if ( empty( $step ) ) {
194 return;
195 }
196
197 $icon = FrmAppHelper::icon_by_class(
198 'frmfont ' . $step['icon'],
199 array(
200 'aria-label' => __( 'Step 1', 'formidable' ),
201 'echo' => false,
202 'style' => 'width:50px;height:50px;',
203 )
204 );
205
206 /* translators: %s: Name of the plugin */
207 $label = sprintf( __( 'Install and Activate %s', 'formidable' ), 'WP Mail SMTP' );
208
209 printf(
210 '<section class="step step-install">
211 <aside class="num">
212 %1$s
213 <i class="loader hidden"></i>
214 </aside>
215 <div>
216 <h2>%2$s</h2>
217 <p>%3$s</p>
218 <span><a rel="%4$s" class="button button-primary frm-button-primary %5$s" aria-label="%6$s">%7$s</a></span>
219 </div>
220 </section>',
221 FrmAppHelper::kses( $icon, array( 'a', 'i', 'span', 'use', 'svg' ) ), // WPCS: XSS ok.
222 esc_html( $label ),
223 esc_html__( 'Install WP Mail SMTP from the WordPress.org plugin repository.', 'formidable' ),
224 esc_attr( $step['plugin'] ),
225 esc_attr( $step['button_class'] ),
226 esc_attr( $step['button_action'] ),
227 esc_html( $step['button_text'] )
228 ); // WPCS: XSS ok.
229 }
230
231 /**
232 * Generate and output step 'Setup' section HTML.
233 *
234 * @since 4.04.04
235 */
236 protected function output_section_step_setup() {
237
238 $step = $this->get_data_step_setup();
239
240 if ( empty( $step ) ) {
241 return;
242 }
243
244 $icon = FrmAppHelper::icon_by_class(
245 'frmfont ' . $step['icon'],
246 array(
247 'aria-label' => __( 'Step 2', 'formidable' ),
248 'echo' => false,
249 'style' => 'width:50px;height:50px;',
250 )
251 );
252
253 printf(
254 '<section class="step step-setup %1$s">
255 <aside class="num">
256 %2$s
257 <i class="loader hidden"></i>
258 </aside>
259 <div>
260 <h2>%3$s</h2>
261 <p>%4$s</p>
262 <span><a href="%5$s" class="button button-primary frm-button-primary %6$s">%7$s</a></span>
263 </div>
264 </section>',
265 esc_attr( $step['section_class'] ),
266 FrmAppHelper::kses( $icon, array( 'a', 'i', 'span', 'use', 'svg' ) ), // WPCS: XSS ok.
267 esc_html__( 'Set Up WP Mail SMTP', 'formidable' ),
268 esc_html__( 'Select and configure your mailer.', 'formidable' ),
269 esc_url( admin_url( $this->config['smtp_settings'] ) ),
270 esc_attr( $step['button_class'] ),
271 esc_html( $step['button_text'] )
272 ); // WPCS: XSS ok.
273 }
274
275 /**
276 * Step 'Install' data.
277 *
278 * @since 4.04.04
279 *
280 * @return array Step data.
281 */
282 protected function get_data_step_install() {
283
284 $lite_plugin = new FrmInstallPlugin( array( 'plugin_file' => $this->config['lite_plugin'] ) );
285 $pro_plugin = new FrmInstallPlugin( array( 'plugin_file' => $this->config['pro_plugin'] ) );
286
287 $this->output_data['plugin_installed'] = $lite_plugin->is_installed();
288 $this->output_data['pro_plugin_installed'] = $pro_plugin->is_installed();
289 $this->output_data['plugin_activated'] = false;
290 $this->output_data['plugin_setup'] = false;
291
292 $step = array(
293 'icon' => 'frm_step1_icon',
294 'button_action' => '',
295 );
296
297 $is_installed = $this->output_data['plugin_installed'] || $this->output_data['pro_plugin_installed'];
298 if ( ! $is_installed ) {
299 // Return the download url.
300 $step['button_text'] = __( 'Install WP Mail SMTP', 'formidable' );
301 $step['button_class'] = 'frm-install-addon';
302 $step['button_action'] = __( 'Install', 'formidable' );
303 $step['plugin'] = $this->config['lite_download_url'];
304 return $step;
305 }
306
307 $this->output_data['plugin_activated'] = $this->is_smtp_activated();
308 $this->output_data['plugin_setup'] = $this->is_smtp_configured();
309
310 $step['plugin'] = $this->output_data['pro_plugin_installed'] ? $this->config['pro_plugin'] : $this->config['lite_plugin'];
311
312 if ( $this->output_data['plugin_activated'] ) {
313 $step['icon'] = 'frm_step_complete_icon';
314 $step['button_text'] = __( 'WP Mail SMTP Installed & Activated', 'formidable' );
315 $step['button_class'] = 'grey disabled';
316 } else {
317 $step['button_text'] = __( 'Activate WP Mail SMTP', 'formidable' );
318 $step['button_class'] = 'frm-activate-addon';
319 $step['button_action'] = __( 'Activate', 'formidable' );
320 }
321
322 return $step;
323 }
324
325 /**
326 * Step 'Setup' data.
327 *
328 * @since 4.04.04
329 *
330 * @return array Step data.
331 */
332 protected function get_data_step_setup() {
333
334 $step = array();
335
336 $step['icon'] = 'frm_step2_icon';
337 $step['section_class'] = $this->output_data['plugin_activated'] ? '' : 'grey';
338 $step['button_text'] = esc_html__( 'Start Setup', 'formidable' );
339 $step['button_class'] = 'grey disabled';
340
341 if ( $this->output_data['plugin_setup'] ) {
342 $step['icon'] = 'frm_step_complete_icon';
343 $step['section_class'] = '';
344 $step['button_text'] = esc_html__( 'Go to SMTP settings', 'formidable' );
345 } elseif ( $this->output_data['plugin_activated'] ) {
346 $step['button_class'] = '';
347 }
348
349 return $step;
350 }
351
352 /**
353 * Whether WP Mail SMTP plugin configured or not.
354 *
355 * @since 4.04.04
356 *
357 * @return bool True if some mailer is selected and configured properly.
358 */
359 protected function is_smtp_configured() {
360
361 if ( ! $this->is_smtp_activated() ) {
362 return false;
363 }
364
365 $phpmailer = $this->get_phpmailer();
366
367 $mailer = WPMailSMTP\Options::init()->get( 'mail', 'mailer' );
368 $is_mailer_complete = wp_mail_smtp()->get_providers()->get_mailer( $mailer, $phpmailer )->is_mailer_complete();
369
370 return 'mail' !== $mailer && $is_mailer_complete;
371 }
372
373 /**
374 * Whether WP Mail SMTP plugin active or not.
375 *
376 * @since 4.04.04
377 *
378 * @return bool True if SMTP plugin is active.
379 */
380 protected function is_smtp_activated() {
381 return function_exists( 'wp_mail_smtp' ) && ( is_plugin_active( $this->config['lite_plugin'] ) || is_plugin_active( $this->config['pro_plugin'] ) );
382 }
383
384
385 /**
386 * Get $phpmailer instance.
387 *
388 * @since 4.04.04
389 *
390 * @return PHPMailer Instance of PHPMailer.
391 */
392 protected function get_phpmailer() {
393 global $phpmailer;
394
395 if ( ! is_object( $phpmailer ) || ! is_a( $phpmailer, 'PHPMailer' ) ) {
396 require_once ABSPATH . WPINC . '/class-phpmailer.php';
397 $phpmailer = new PHPMailer( true ); // phpcs:ignore
398 }
399
400 return $phpmailer;
401 }
402
403 /**
404 * Redirect to SMTP settings page if it is activated..
405 *
406 * @since 4.04.04
407 */
408 public function redirect_to_smtp_settings() {
409 if ( $this->is_smtp_configured() ) {
410 wp_safe_redirect( admin_url( $this->config['smtp_settings'] ) );
411 exit;
412 }
413 }
414
415 private function stmp_logo() {
416 ?>
417 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 60" height="90" width="90"><defs><style>.cls-11,.cls-12{fill-rule:evenodd}.cls-4{fill:none}.cls-11{fill:#86a196}.cls-12{fill:#fff}</style></defs><path class="cls-4" d="M-6.3 0h60v60h-60z"/><path d="M16.7 8.1a15.4 15.4 0 00-8 10.2 23.5 23.5 0 1030 0 15.4 15.4 0 00-9.3-10.8 3.4 3.4 0 00-2.1-2.7A4.6 4.6 0 0018.4 3a24.4 24.4 0 00-1.7 5z" fill="#395360" fill-rule="evenodd"/><path fill="#fbaa6f" d="M18 26h12v14H18z"/><path d="M25.9 33.2l-.1-.1a1.4 1.4 0 111.6-2.3 1.9 1.9 0 00-1.2.8 1.9 1.9 0 00-.3 1.6zm-4.5 0a1.8 1.8 0 00-.4-1.6 2 2 0 00-1.2-.8 1.4 1.4 0 011.6 2.3zm7.2-3.2h.5l-1 4.8-2.2 6.5h-4.3l-3.2-5.4 1.1-3.2 2.1 2.7c.6.5 2.7.5 3.8-.6a26.2 26.2 0 003.2-4.8z" fill="#dc7f3c" fill-rule="evenodd"/><path d="M9.7 29H15v-9h-4a13 13 0 017.4-10q1.2-5 2.8-6.8l.1-.1.1-.1a2.3 2.3 0 011.1-.5 2.3 2.3 0 012.2 3.8 1.6 1.6 0 01-.4.3A15 15 0 0023 8a5 5 0 013-1.5 1.4 1.4 0 01.7.2 1.3 1.3 0 01.5 1.8 1.3 1.3 0 01-.6.6 13 13 0 0110.1 11l.1.8H33v8h4.8l1.8 13.4q-6.3 4-15.8 4T8 42.4zM25 38.4q3.8-6.4 3.8-7.6c0-2.2-3.2-4-4.8-4s-4.9 1.7-4.9 4q0 1.2 3.8 7.6a1.2 1.2 0 001 .6 1 1 0 001-.6z" fill="#bdcfc8" fill-rule="evenodd"/><path class="cls-4" d="M19 31h9.6L27 47.2h-6.4l-1.6-16z"/><path d="M39.8 48.8a20 20 0 01-32 0l.8-6a2.7 2.7 0 001 .1 2.8 2.8 0 002.8-2.4v1.2a2.8 2.8 0 005.6 0v1.6a2.9 2.9 0 005.7 0 2.8 2.8 0 005.7 0v-1.6a2.8 2.8 0 105.7 0v-1.2A2.8 2.8 0 0038 43a2.9 2.9 0 001-.2l.8 6z" fill="#809eb0" fill-rule="evenodd"/><path d="M8.3 44.6l.3-1.8a2.7 2.7 0 001 .2 2.8 2.8 0 002.8-2.5v1.2a2.8 2.8 0 005.7 0v1.7a2.9 2.9 0 005.6 0 2.8 2.8 0 005.7 0v-1.7a2.8 2.8 0 105.7 0v-1.2A2.8 2.8 0 0038 43a2.9 2.9 0 001-.2l.3 2a2.9 2.9 0 01-4.1-2.2v1.2a2.8 2.8 0 11-5.7 0v1.6a2.8 2.8 0 01-5.7 0 2.9 2.9 0 01-5.7 0v-1.7a2.8 2.8 0 01-5.7 0v-1.2A2.8 2.8 0 019.6 45a2.9 2.9 0 01-1.3-.3z" fill="#738e9e" fill-rule="evenodd"/><path class="cls-11" d="M37.8 22.4c-1-2.9-3-4.7-4.7-4.5-2.2.2-2.8 3.7-2.3 8s1.7 7.5 3.9 7.3 4-3.9 3.6-8c0 1.2-.5 2.3-1.3 2.4-1.2 0-1.5-1.2-1.6-2.9s-.2-3 1-3a1.5 1.5 0 011.4.7z"/><path class="cls-12" d="M37 21.8c-.6-1.3-1.5-2-2.4-1.9-1.5.1-1.9 2.6-1.6 5.5s1.2 5.1 2.7 5c1.1-.2 2-1.5 2.2-3.4a1.2 1.2 0 01-1 .6c-1 0-1.4-1.2-1.5-2.9s-.1-3 1-3a1.6 1.6 0 01.6 0z"/><path class="cls-11" d="M9.6 22.4c1-2.9 3-4.7 4.7-4.5 2.2.2 2.8 3.7 2.3 8s-1.7 7.5-3.9 7.3-4-3.9-3.7-8c.1 1.2.5 2.3 1.4 2.4 1.1 0 1.5-1.2 1.6-2.9s.1-3-1-3a1.5 1.5 0 00-1.4.7z"/><path class="cls-12" d="M10.4 21.8c.6-1.3 1.5-2 2.4-1.9 1.5.1 1.8 2.6 1.5 5.5s-1.1 5.1-2.6 5c-1.1-.2-2-1.5-2.2-3.4a1.2 1.2 0 00.9.6c1.1 0 1.4-1.2 1.6-2.9s.1-3-1-3a1.7 1.7 0 00-.7 0z"/><path d="M19 28.6a5.3 5.3 0 010-.7c0-2.4 1.2-5.2 4.9-5.2s4.8 2.8 4.8 5.2a4.4 4.4 0 010 1c-.9-1.3-2.4-2.1-4.9-2.1-2.4 0-3.9.7-4.8 1.8z" fill="#f4f8ff" fill-rule="evenodd"/><path class="cls-11" d="M26.5 9.2L23.3 9l4-1.2a1.4 1.4 0 01-.8 1.4zm-3.5-1l-1.3 1a16.8 16.8 0 002-3.8 6.6 6.6 0 00.3-2.7A2.4 2.4 0 0125.2 5a2.4 2.4 0 01-.7 1.5A15 15 0 0023 8.1z"/></svg>
418 <?php
419 }
420
421 private function css() {
422 ?>
423 <style>
424 #frm-admin-smtp *, #frm-admin-smtp *::before, #frm-admin-smtpp *::after {
425 -webkit-box-sizing: border-box;
426 -moz-box-sizing: border-box;
427 box-sizing: border-box;
428 }
429 #frm-admin-smtp{
430 width: 700px;
431 margin: 0 auto;
432 }
433 #frm-admin-smtp p {
434 font-size: 15px;
435 }
436 #frm-admin-smtp section{
437 margin: 50px 0;
438 text-align: left;
439 clear: both;
440 }
441 #frm-admin-smtp .top{
442 text-align: center;
443 }
444 .frm-smtp-logos {
445 margin-bottom: 38px;
446 }
447 .frm-smtp-logos svg {
448 vertical-align: middle;
449 }
450 #frm-admin-smtp .top h1 {
451 font-size: 26px;
452 font-weight: 600;
453 margin-bottom: 0;
454 padding: 0;
455 }
456 #frm-admin-smtp .top p {
457 font-size: 17px;
458 color: #777;
459 margin-top: .5em;
460 }
461 #frm-admin-smtp .screenshot ul {
462 display: inline-block;
463 margin: 0 0 0 30px;
464 list-style-type: none;
465 max-width: calc(100% - 350px);
466 }
467 #frm-admin-smtp .screenshot li {
468 margin: 16px 0;
469 padding: 0;
470 font-size: 15px;
471 color: #777;
472 }
473 #frm-admin-smtp .screenshot .cont img {
474 max-width: 100%;
475 display: block;
476 }
477 #frm-admin-smtp .screenshot .cont {
478 display: inline-block;
479 position: relative;
480 width: 315px;
481 padding: 5px;
482 background-color: #fff;
483 border-radius: 3px;
484 }
485 #frm-admin-smtp .step,
486 #frm-admin-smtp .screenshot .cont {
487 -webkit-box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.05);
488 -moz-box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.05);
489 box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.05);
490 }
491 #frm-admin-smtp .step {
492 background-color: #F9F9F9;
493 border: 1px solid #E5E5E5;
494 margin: 0 0 25px;
495 }
496 #frm-admin-smtp .screenshot > *,
497 #frm-admin-smtp .step > * {
498 vertical-align: middle;
499 }
500 #frm-admin-smtp .step p {
501 font-size: 16px;
502 color: #777777;
503 }
504 #frm-admin-smtp .step .num {
505 display: inline-block;
506 position: relative;
507 width: 100px;
508 height: 50px;
509 text-align: center;
510 }
511 #frm-admin-smtp .step div {
512 display: inline-block;
513 width: calc(100% - 104px);
514 background-color: #fff;
515 padding: 30px;
516 border-left: 1px solid #eee;
517 }
518 #frm-admin-smtp .grey {
519 opacity: 0.5;
520 background: #F6F6F6 !important;
521 border-color: #ddd !important;
522 color: #9FA5AA !important;
523 }
524 #frm-admin-smtp .step h2 {
525 font-size: 24px;
526 line-height: 22px;
527 margin-top: 0;
528 margin-bottom: 15px;
529 }
530 #frm-admin-smtp .button.disabled {
531 cursor: default;
532 }
533 </style>
534 <?php
535 }
536 }
537