PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.14
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.14
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
← All changes | classes/models/FrmAddon.php +51 -253 6.276.14 View file →
@@ -4,82 +4,22 @@
4 4 }
5 5
6 6 /** @phpstan-consistent-constructor */
7 7 class FrmAddon {
8 -
9 - /**
10 - * @var string
11 - */
12 8 public $store_url = 'https://formidableforms.com';
13 -
14 - /**
15 - * @var int|string|null
16 - */
17 9 public $download_id;
18 -
19 - /**
20 - * @var string|null
21 - */
22 10 public $plugin_file;
23 -
24 - /**
25 - * @var string
26 - */
27 11 public $plugin_folder;
28 -
29 - /**
30 - * @var string
31 - */
32 12 public $plugin_name;
33 -
34 - /**
35 - * @var string
36 - */
37 13 public $plugin_slug;
38 -
39 - /**
40 - * @var string
41 - */
42 14 public $option_name;
43 -
44 - /**
45 - * @var string|null
46 - */
47 15 public $version;
48 -
49 - /**
50 - * @var string
51 - */
52 - public $author = 'Strategy11';
53 -
54 - /**
55 - * @var bool
56 - */
16 + public $author = 'Strategy11';
57 17 public $is_parent_licence = false;
58 -
59 - /**
60 - * @var bool
61 - */
62 - public $needs_license = true;
63 -
64 - /**
65 - * @var bool
66 - */
18 + public $needs_license = true;
67 19 private $is_expired_addon = false;
68 -
69 - /**
70 - * @var string|null
71 - */
72 20 public $license;
73 -
74 - /**
75 - * @var bool
76 - */
77 21 protected $get_beta = false;
78 -
79 - /**
80 - * @var array|null
81 - */
82 22 protected $save_status;
83 23
84 24 /**
85 25 * This is used to decide whether the license checks should continue.
@@ -108,12 +48,12 @@
108 48 */
109 49 protected $should_clear_cache = true;
110 50
111 51 public function __construct() {
52 +
112 53 if ( empty( $this->plugin_slug ) ) {
113 54 $this->plugin_slug = preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->plugin_name ) ) );
114 55 }
115 -
116 56 if ( empty( $this->option_name ) ) {
117 57 $this->option_name = 'edd_' . $this->plugin_slug . '_license_';
118 58 }
119 59
@@ -123,46 +63,38 @@
123 63 add_filter( 'frm_installed_addons', array( &$this, 'insert_installed_addon' ) );
124 64 $this->edd_plugin_updater();
125 65 }
126 66
127 - /**
128 - * @return void
129 - */
130 67 public static function load_hooks() {
131 68 add_filter( 'frm_include_addon_page', '__return_true' );
132 69 new static();
133 70 }
134 71
135 - /**
136 - * @param array $plugins
137 - *
138 - * @return array
139 - */
140 72 public function insert_installed_addon( $plugins ) {
141 73 $plugins[ $this->plugin_slug ] = $this;
74 +
142 75 return $plugins;
143 76 }
144 77
145 - /**
146 - * @param string $plugin_slug
147 - *
148 - * @return false|FrmAddon
149 - */
150 78 public static function get_addon( $plugin_slug ) {
151 79 $plugins = apply_filters( 'frm_installed_addons', array() );
152 - return $plugins[ $plugin_slug ] ?? false;
80 + $plugin = false;
81 + if ( isset( $plugins[ $plugin_slug ] ) ) {
82 + $plugin = $plugins[ $plugin_slug ];
83 + }
84 +
85 + return $plugin;
153 86 }
154 87
155 - /**
156 - * @return void
157 - */
158 88 public function edd_plugin_updater() {
89 +
159 90 $this->is_license_revoked();
160 91 $license = $this->license;
161 92
162 93 add_action( 'after_plugin_row_' . plugin_basename( $this->plugin_file ), array( $this, 'maybe_show_license_message' ), 10, 2 );
163 94
164 - if ( $license ) {
95 + if ( ! empty( $license ) ) {
96 +
165 97 if ( 'formidable/formidable.php' !== $this->plugin_folder ) {
166 98 add_filter( 'plugins_api', array( &$this, 'plugins_api_filter' ), 10, 3 );
167 99 }
168 100
@@ -170,9 +102,9 @@
170 102 }
171 103 }
172 104
173 105 /**
174 - * Updates information on the "View version 6.15 details" page with custom data.
106 + * Updates information on the "View version x.x details" page with custom data.
175 107 *
176 108 * @uses api_request()
177 109 *
178 110 * @param mixed $_data
@@ -181,22 +113,21 @@
181 113 *
182 114 * @return object $_data
183 115 */
184 116 public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
185 - if ( $_action !== 'plugin_information' ) {
117 +
118 + if ( $_action != 'plugin_information' ) {
186 119 return $_data;
187 120 }
188 121
189 122 $slug = basename( $this->plugin_file, '.php' );
190 123 $slug2 = str_replace( '/' . $slug . '.php', '', $this->plugin_folder );
191 -
192 - if ( empty( $_args->slug ) || ( $_args->slug !== $slug && $_args->slug !== $slug2 ) ) {
124 + if ( empty( $_args->slug ) || ( $_args->slug != $slug && $_args->slug !== $slug2 ) ) {
193 125 return $_data;
194 126 }
195 127
196 128 $item_id = $this->download_id;
197 -
198 - if ( ! $item_id ) {
129 + if ( empty( $item_id ) ) {
199 130 $_data = array(
200 131 'name' => $this->plugin_name,
201 132 'excerpt' => '',
202 133 'changelog' => 'See the full changelog at <a href="' . esc_url( $this->store_url . '/changelog/' ) . '"></a>',
@@ -220,21 +151,16 @@
220 151
221 152 return (object) $_data;
222 153 }
223 154
224 - /**
225 - * @return string
226 - */
227 155 public function get_license() {
228 156 $license = $this->maybe_get_pro_license();
229 -
230 - if ( $license ) {
157 + if ( ! empty( $license ) ) {
231 158 return $license;
232 159 }
233 160
234 161 $license = trim( get_option( $this->option_name . 'key' ) );
235 -
236 - if ( ! $license ) {
162 + if ( empty( $license ) ) {
237 163 $license = $this->activate_defined_license();
238 164 }
239 165
240 166 return $license;
@@ -241,14 +167,12 @@
241 167 }
242 168
243 169 /**
244 170 * @since 3.04.03
245 - *
246 - * @return false|string
247 171 */
248 172 protected function maybe_get_pro_license() {
249 173 // prevent a loop if $this is the pro plugin
250 - $get_license = FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::get_updater' ) && $this->plugin_name !== 'Formidable Pro';
174 + $get_license = FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::get_updater' ) && $this->plugin_name != 'Formidable Pro';
251 175
252 176 if ( ! $get_license ) {
253 177 return false;
254 178 }
@@ -255,15 +179,13 @@
255 179
256 180 $api = new FrmFormApi();
257 181 $api->get_pro_updater();
258 182 $license = $api->get_license();
259 -
260 - if ( ! $license ) {
183 + if ( empty( $license ) ) {
261 184 return false;
262 185 }
263 186
264 187 $this->get_api_info( $license );
265 -
266 188 if ( ! $this->is_parent_licence ) {
267 189 $license = false;
268 190 }
269 191
@@ -273,17 +195,13 @@
273 195 /**
274 196 * Activate the license in wp-config.php
275 197 *
276 198 * @since 2.04
277 - *
278 - * @return string
279 199 */
280 200 public function activate_defined_license() {
281 201 $license = $this->get_defined_license();
282 -
283 - if ( $license && ! $this->is_active() && ! $this->checked_recently( '1 day' ) ) {
202 + if ( ! empty( $license ) && ! $this->is_active() && ! $this->checked_recently( '1 day' ) ) {
284 203 $response = $this->activate_license( $license );
285 -
286 204 if ( ! $response['success'] ) {
287 205 $license = '';
288 206 }
289 207 }
@@ -294,28 +212,19 @@
294 212 /**
295 213 * Check the wp-config.php for the license key
296 214 *
297 215 * @since 2.04
298 - *
299 - * @return false|string
300 216 */
301 217 public function get_defined_license() {
302 - $constant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE';
303 - return defined( $constant_name ) ? constant( $constant_name ) : false;
218 + $consant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE';
219 +
220 + return defined( $consant_name ) ? constant( $consant_name ) : false;
304 221 }
305 222
306 - /**
307 - * @param string $license
308 - *
309 - * @return void
310 - */
311 223 public function set_license( $license ) {
312 224 update_option( $this->option_name . 'key', $license );
313 225 }
314 226
315 - /**
316 - * @return mixed
317 - */
318 227 public function is_active() {
319 228 return get_option( $this->option_name . 'active' );
320 229 }
321 230
@@ -322,10 +231,8 @@
322 231 /**
323 232 * @since 3.04.03
324 233 *
325 234 * @param array|string $error
326 - *
327 - * @return void
328 235 */
329 236 public function maybe_clear_license( $error ) {
330 237 if ( is_array( $error ) && $error['code'] === 'disabled' && $error['license'] === $this->license ) {
331 238 $this->clear_license();
@@ -331,11 +238,8 @@
331 238 $this->clear_license();
332 239 }
333 240 }
334 241
335 - /**
336 - * @return void
337 - */
338 242 public function clear_license() {
339 243 delete_option( $this->option_name . 'active' );
340 244 delete_option( $this->option_name . 'key' );
341 245
@@ -357,9 +261,8 @@
357 261 * @return void
358 262 */
359 263 protected function maybe_set_active( $is_valid ) {
360 264 update_option( $this->option_name . 'active', $is_valid );
361 -
362 265 if ( $is_valid ) {
363 266 $this->set_active( $is_valid );
364 267 return;
365 268 }
@@ -370,13 +273,8 @@
370 273 delete_option( $this->option_name . 'key' );
371 274 $this->license = '';
372 275 }
373 276
374 - /**
375 - * @param bool $is_active
376 - *
377 - * @return void
378 - */
379 277 public function set_active( $is_active ) {
380 278 $this->delete_cache();
381 279 FrmAppHelper::save_combined_js();
382 280 $this->update_pro_capabilities();
@@ -385,10 +283,8 @@
385 283 /**
386 284 * Updates roles capabilities after pro license is active.
387 285 *
388 286 * @since 5.0
389 - *
390 - * @return void
391 287 */
392 288 protected function update_pro_capabilities() {
393 289 global $wp_roles;
394 290
@@ -398,11 +294,10 @@
398 294
399 295 $caps = FrmAppHelper::frm_capabilities( 'pro_only' );
400 296 $roles = get_editable_roles();
401 297 $settings = new FrmSettings();
402 -
403 298 foreach ( $caps as $cap => $cap_desc ) {
404 - $cap_roles = (array) ( $settings->$cap ?? 'administrator' );
299 + $cap_roles = (array) ( isset( $settings->$cap ) ? $settings->$cap : 'administrator' );
405 300
406 301 // Make sure administrators always have permissions.
407 302 if ( ! in_array( 'administrator', $cap_roles, true ) ) {
408 303 array_push( $cap_roles, 'administrator' );
@@ -408,9 +303,9 @@
408 303 array_push( $cap_roles, 'administrator' );
409 304 }
410 305
411 306 foreach ( $roles as $role => $details ) {
412 - if ( in_array( $role, $cap_roles, true ) ) {
307 + if ( in_array( $role, $cap_roles ) ) {
413 308 $wp_roles->add_cap( $role, $cap );
414 309 } else {
415 310 $wp_roles->remove_cap( $role, $cap );
416 311 }
@@ -419,10 +314,8 @@
419 314 }
420 315
421 316 /**
422 317 * @since 3.04.03
423 - *
424 - * @return void
425 318 */
426 319 protected function delete_cache() {
427 320 delete_transient( 'frm_api_licence' );
428 321
@@ -436,14 +329,8 @@
436 329 $api->reset_cached();
437 330
438 331 $api = new FrmApplicationApi( $this->license );
439 332 $api->reset_cached();
440 -
441 - $api = new FrmSalesApi();
442 - $api->reset_cached();
443 -
444 - $api = new FrmStyleApi();
445 - $api->reset_cached();
446 333 }
447 334
448 335 /**
449 336 * The Pro version includes the show_license_message function.
@@ -449,13 +336,8 @@
449 336 * The Pro version includes the show_license_message function.
450 337 * We need an extra check before we allow it to show a message.
451 338 *
452 339 * @since 3.04.03
453 - *
454 - * @param string $file File path of the plugin.
455 - * @param array $plugin Plugin data.
456 - *
457 - * @return void
458 340 */
459 341 public function maybe_show_license_message( $file, $plugin ) {
460 342 if ( $this->is_expired_addon || isset( $plugin['package'] ) ) {
461 343 // let's not show a ton of duplicate messages
@@ -464,30 +346,22 @@
464 346
465 347 $this->show_license_message( $file, $plugin );
466 348 }
467 349
468 - /**
469 - * @param string $file File path of the plugin.
470 - * @param array $plugin Plugin data.
471 - *
472 - * @return void
473 - */
474 350 public function show_license_message( $file, $plugin ) {
475 351 $message = '';
476 -
477 352 if ( empty( $this->license ) ) {
478 353 /* translators: %1$s: Plugin name, %2$s: Start link HTML, %3$s: end link HTML */
479 - $message = sprintf( esc_html__( 'Your %1$s license key is missing. Please add it on the %2$slicenses page%3$s.', 'formidable' ), esc_html( $this->plugin_name ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings' ) ) . '">', '</a>' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
354 + $message = sprintf( esc_html__( 'Your %1$s license key is missing. Please add it on the %2$slicenses page%3$s.', 'formidable' ), esc_html( $this->plugin_name ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings' ) ) . '">', '</a>' );
480 355 } else {
481 356 $api = new FrmFormApi( $this->license );
482 357 $errors = $api->error_for_license();
483 -
484 - if ( $errors ) {
358 + if ( ! empty( $errors ) ) {
485 359 $message = reset( $errors );
486 360 }
487 361 }
488 362
489 - if ( ! $message ) {
363 + if ( empty( $message ) ) {
490 364 return;
491 365 }
492 366
493 367 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
@@ -492,19 +366,14 @@
492 366
493 367 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
494 368 $id = sanitize_title( $plugin['Name'] ) . '-next';
495 369
496 - echo '<tr class="plugin-update-tr active" id="' . esc_attr( $id ) . '"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="update-message notice error inline notice-error notice-alt"><p>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
497 - FrmAppHelper::kses_echo( $message, 'a' );
498 - echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
370 + echo '<tr class="plugin-update-tr active" id="' . esc_attr( $id ) . '"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="update-message notice error inline notice-error notice-alt"><p>';
371 + echo FrmAppHelper::kses( $message, 'a' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
372 + echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>';
499 373 echo '</p></div></td></tr>';
500 374 }
501 375
502 - /**
503 - * @param mixed $transient
504 - *
505 - * @return mixed
506 - */
507 376 public function clear_expired_download( $transient ) {
508 377 if ( ! is_object( $transient ) ) {
509 378 return $transient;
510 379 }
@@ -535,15 +404,12 @@
535 404 *
536 405 * @since 3.04.03
537 406 *
538 407 * @param object $transient The current plugin info saved for update.
539 - *
540 - * @return void
541 408 */
542 409 private function prepare_update_details( &$transient ) {
543 410 $version_info = $transient;
544 411 $has_beta_url = ! empty( $version_info->beta );
545 -
546 412 if ( $this->get_beta && ! $has_beta_url ) {
547 413 $version_info = (object) $this->get_api_info( $this->license );
548 414 }
549 415
@@ -548,9 +414,8 @@
548 414 }
549 415
550 416 if ( ! empty( $version_info->new_version ) ) {
551 417 $this->clear_old_plugin_version( $version_info );
552 -
553 418 if ( $version_info === false ) {
554 419 // Was cleared with timeout.
555 420 $transient = false;
556 421 } else {
@@ -566,12 +431,8 @@
566 431 /**
567 432 * Get the API info for this plugin
568 433 *
569 434 * @since 3.04.03
570 - *
571 - * @param string $license The license key.
572 - *
573 - * @return array The API info for the plugin.
574 435 */
575 436 protected function get_api_info( $license ) {
576 437 $api = new FrmFormApi( $license );
577 438 $addon = $api->get_addon_for_license( $this );
@@ -592,17 +453,12 @@
592 453 * Make sure transients don't stick around on sites that
593 454 * don't save the transient expiration
594 455 *
595 456 * @since 2.05.05
596 - *
597 - * @param object $version_info The version info for the plugin.
598 - *
599 - * @return void
600 457 */
601 458 private function clear_old_plugin_version( &$version_info ) {
602 459 $timeout = ! empty( $version_info->timeout ) ? $version_info->timeout : 0;
603 -
604 - if ( $timeout && time() > $timeout ) {
460 + if ( ! empty( $timeout ) && time() > $timeout ) {
605 461 // Cache is expired.
606 462 $version_info = false;
607 463 $api = new FrmFormApi( $this->license );
608 464 $api->reset_cached();
@@ -613,18 +469,13 @@
613 469 * The beta url is always included if the download has a beta.
614 470 * Check if the beta should be downloaded.
615 471 *
616 472 * @since 3.04.03
617 - *
618 - * @param object $version_info The version info for the plugin.
619 - *
620 - * @return void
621 473 */
622 474 private function maybe_use_beta_url( &$version_info ) {
623 475 if ( $this->get_beta && ! empty( $version_info->beta ) ) {
624 476 $version_info->new_version = $version_info->beta['version'];
625 477 $version_info->package = $version_info->beta['package'];
626 -
627 478 if ( ! empty( $version_info->plugin ) ) {
628 479 $version_info->plugin = $version_info->beta['plugin'];
629 480 }
630 481 }
@@ -629,13 +480,8 @@
629 480 }
630 481 }
631 482 }
632 483
633 - /**
634 - * @param object $transient
635 - *
636 - * @return bool
637 - */
638 484 private function is_current_version( $transient ) {
639 485 if ( empty( $transient->checked ) || ! isset( $transient->checked[ $this->plugin_folder ] ) ) {
640 486 return false;
641 487 }
@@ -640,14 +486,13 @@
640 486 return false;
641 487 }
642 488
643 489 $response = empty( $transient->response );
644 -
645 490 if ( $response ) {
646 491 return true;
647 492 }
648 493
649 - return isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) && $transient->checked[ $this->plugin_folder ] === $transient->response[ $this->plugin_folder ]->new_version; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
494 + return isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) && $transient->checked[ $this->plugin_folder ] === $transient->response[ $this->plugin_folder ]->new_version;
650 495 }
651 496
652 497 /**
653 498 * @return bool
@@ -656,18 +501,12 @@
656 501 $last_cleared = get_option( 'frm_last_cleared' );
657 502 return $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) );
658 503 }
659 504
660 - /**
661 - * @return void
662 - */
663 505 private function cleared_plugins() {
664 506 update_option( 'frm_last_cleared', gmdate( 'Y-m-d H:i:s' ) );
665 507 }
666 508
667 - /**
668 - * @return void
669 - */
670 509 private function is_license_revoked() {
671 510 if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
672 511 return;
673 512 }
@@ -682,9 +521,8 @@
682 521 return;
683 522 }
684 523
685 524 $response = $this->get_license_status();
686 -
687 525 if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] || 'missing' === $response['status'] ) {
688 526 $this->clear_license();
689 527 }
690 528 }
@@ -699,9 +537,8 @@
699 537 */
700 538 private function checked_recently( $time, $required_status = '' ) {
701 539 $last_checked = $this->last_checked();
702 540 $is_429 = isset( $last_checked['response_code'] ) && 429 === $last_checked['response_code'];
703 -
704 541 if ( $is_429 ) {
705 542 // If the last check was a a rate limit, we'll need to check again sooner.
706 543 $time = '5 minutes';
707 544 $required_status = '';
@@ -711,9 +548,9 @@
711 548 // If the last check was invalid, we don't need to check again.
712 549 return true;
713 550 }
714 551
715 - $checked_time = $last_checked['time'] ?? false;
552 + $checked_time = isset( $last_checked['time'] ) ? $last_checked['time'] : false;
716 553 $time_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-' . $time ) );
717 554 return $checked_time && $checked_time > $time_ago;
718 555 }
719 556
@@ -722,16 +559,18 @@
722 559 *
723 560 * @return array
724 561 */
725 562 private function last_checked() {
726 - $last_checked = is_multisite() ? get_site_option( $this->transient_key() ) : get_option( $this->transient_key() );
727 -
563 + if ( is_multisite() ) {
564 + $last_checked = get_site_option( $this->transient_key() );
565 + } else {
566 + $last_checked = get_option( $this->transient_key() );
567 + }
728 568 if ( $last_checked && ! is_array( $last_checked ) ) {
729 569 // Get string into array for existing values.
730 570 $last_checked = array( 'time' => $last_checked );
731 571 }
732 -
733 - return $last_checked ? $last_checked : array();
572 + return $last_checked ? (array) $last_checked : array();
734 573 }
735 574
736 575 /**
737 576 * @return void
@@ -737,9 +576,8 @@
737 576 * @return void
738 577 */
739 578 private function update_last_checked() {
740 579 $this->save_response['time'] = gmdate( 'Y-m-d H:i:s' );
741 -
742 580 if ( is_multisite() ) {
743 581 update_site_option( $this->transient_key(), $this->save_response );
744 582 } else {
745 583 update_option( $this->transient_key(), $this->save_response );
@@ -747,25 +585,19 @@
747 585 }
748 586
749 587 /**
750 588 * Use a new cache after the license is changed, or Formidable is updated.
751 - *
752 - * @return string
753 589 */
754 590 private function transient_key() {
755 591 return 'frm_' . md5( sanitize_key( $this->license . '_' . $this->plugin_slug ) );
756 592 }
757 593
758 - /**
759 - * @return void
760 - */
761 594 public static function activate() {
762 595 FrmAppHelper::permission_check( 'frm_change_settings' );
763 596 check_ajax_referer( 'frm_ajax', 'nonce' );
764 597
765 598 $license = stripslashes( FrmAppHelper::get_param( 'license', '', 'post', 'sanitize_text_field' ) );
766 -
767 - if ( ! $license ) {
599 + if ( empty( $license ) ) {
768 600 wp_send_json(
769 601 array(
770 602 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ),
771 603 'success' => false,
@@ -775,20 +607,13 @@
775 607
776 608 $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
777 609 $response = self::activate_license_for_plugin( $license, $plugin_slug );
778 610
779 - FrmInbox::clear_cache();
780 -
781 611 wp_send_json( $response );
782 612 }
783 613
784 614 /**
785 615 * @since 4.08
786 - *
787 - * @param string $license The license key.
788 - * @param string $plugin_slug The plugin slug.
789 - *
790 - * @return array The response from the license activation.
791 616 */
792 617 public static function activate_license_for_plugin( $license, $plugin_slug ) {
793 618 $this_plugin = self::get_addon( $plugin_slug );
794 619 return $this_plugin->activate_license( $license );
@@ -793,13 +618,8 @@
793 618 $this_plugin = self::get_addon( $plugin_slug );
794 619 return $this_plugin->activate_license( $license );
795 620 }
796 621
797 - /**
798 - * @param string $license The license key.
799 - *
800 - * @return array The response from the license activation.
801 - */
802 622 private function activate_license( $license ) {
803 623 $this->set_license( $license );
804 624 $this->license = $license;
805 625
@@ -812,9 +632,8 @@
812 632 if ( $response['error'] ) {
813 633 $response['message'] = $response['status'];
814 634 } else {
815 635 $messages = $this->get_messages();
816 -
817 636 if ( is_string( $response['status'] ) && isset( $messages[ $response['status'] ] ) ) {
818 637 $response['message'] = $messages[ $response['status'] ];
819 638 } else {
820 639 $response['message'] = FrmAppHelper::kses( $response['status'], array( 'a' ) );
@@ -820,9 +639,8 @@
820 639 $response['message'] = FrmAppHelper::kses( $response['status'], array( 'a' ) );
821 640 }
822 641
823 642 $is_valid = false;
824 -
825 643 if ( 'valid' === $response['status'] ) {
826 644 $is_valid = 'valid';
827 645 $response['success'] = true;
828 646 }
@@ -852,11 +670,8 @@
852 670 )
853 671 );
854 672 }
855 673
856 - /**
857 - * @return array
858 - */
859 674 private function get_license_status() {
860 675 $this->set_running();
861 676
862 677 $response = array(
@@ -862,11 +677,11 @@
862 677 $response = array(
863 678 'status' => 'missing',
864 679 'error' => true,
865 680 );
866 -
867 681 if ( empty( $this->license ) ) {
868 682 $response['error'] = false;
683 +
869 684 return $response;
870 685 }
871 686
872 687 try {
@@ -890,11 +705,8 @@
890 705 $this->done_running();
891 706 return $response;
892 707 }
893 708
894 - /**
895 - * @return array
896 - */
897 709 private function get_messages() {
898 710 return array(
899 711 'valid' => __( 'Your license has been activated. Enjoy!', 'formidable' ),
900 712 'invalid' => __( 'That license key is invalid', 'formidable' ),
@@ -907,10 +719,8 @@
907 719 }
908 720
909 721 /**
910 722 * @since 4.03
911 - *
912 - * @return void
913 723 */
914 724 public static function reset_cache() {
915 725 FrmAppHelper::permission_check( 'frm_change_settings' );
916 726 check_ajax_referer( 'frm_ajax', 'nonce' );
@@ -925,11 +735,8 @@
925 735
926 736 wp_send_json( $response );
927 737 }
928 738
929 - /**
930 - * @return void
931 - */
932 739 public static function deactivate() {
933 740 FrmAppHelper::permission_check( 'frm_change_settings' );
934 741 check_ajax_referer( 'frm_ajax', 'nonce' );
935 742
@@ -938,13 +745,11 @@
938 745 $response = array(
939 746 'success' => false,
940 747 'message' => '',
941 748 );
942 -
943 749 try {
944 750 // $license_data->license will be either "deactivated" or "failed"
945 751 $license_data = $this_plugin->send_mothership_request( 'deactivate_license' );
946 -
947 752 if ( is_array( $license_data ) && 'deactivated' === $license_data['license'] ) {
948 753 $response['success'] = true;
949 754 $response['message'] = __( 'That license was removed successfully', 'formidable' );
950 755 } else {
@@ -954,9 +759,8 @@
954 759 $response['message'] = $e->getMessage();
955 760 }
956 761
957 762 $this_plugin->clear_license();
958 - FrmInbox::clear_cache();
959 763
960 764 wp_send_json( $response );
961 765 }
962 766
@@ -961,10 +765,8 @@
961 765 }
962 766
963 767 /**
964 768 * @since 4.03
965 - *
966 - * @return FrmAddon
967 769 */
968 770 private static function set_license_from_post() {
969 771 $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
970 772 $this_plugin = self::get_addon( $plugin_slug );
@@ -973,10 +775,8 @@
973 775 return $this_plugin;
974 776 }
975 777
976 778 /**
977 - * @param string $action
978 - *
979 779 * @return string
980 780 */
981 781 public function send_mothership_request( $action ) {
982 782 $api_params = array(
@@ -983,9 +783,8 @@
983 783 'edd_action' => $action,
984 784 'license' => $this->license,
985 785 'url' => home_url(),
986 786 );
987 -
988 787 if ( is_numeric( $this->download_id ) ) {
989 788 $api_params['item_id'] = absint( $this->download_id );
990 789 } else {
991 790 $api_params['item_name'] = rawurlencode( $this->plugin_name );
@@ -1004,21 +803,23 @@
1004 803 $body = wp_remote_retrieve_body( $resp );
1005 804 $this->save_status = array( 'response_code' => wp_remote_retrieve_response_code( $resp ) );
1006 805
1007 806 $message = __( 'Your License Key was invalid', 'formidable' );
1008 -
1009 807 if ( is_wp_error( $resp ) ) {
1010 808 $link = FrmAppHelper::admin_upgrade_link( 'api', 'knowledgebase/why-cant-i-activate-formidable-pro/' );
1011 809 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1012 - $message = sprintf( __( 'You had an error communicating with the Formidable API. %1$sClick here%2$s for more information.', 'formidable' ), '<a href="' . esc_url( $link ) . '" target="_blank">', '</a>' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
810 + $message = sprintf( __( 'You had an error communicating with the Formidable API. %1$sClick here%2$s for more information.', 'formidable' ), '<a href="' . esc_url( $link ) . '" target="_blank">', '</a>' );
1013 811 $message .= ' ' . $resp->get_error_message();
1014 812 } elseif ( 'error' === $body || is_wp_error( $body ) ) {
1015 813 $message = __( 'You had an HTTP error connecting to the Formidable API', 'formidable' );
1016 814 } else {
1017 815 $json_res = json_decode( $body, true );
1018 -
1019 816 if ( null !== $json_res ) {
1020 - $message = is_array( $json_res ) && isset( $json_res['error'] ) ? $json_res['error'] : $json_res;
817 + if ( is_array( $json_res ) && isset( $json_res['error'] ) ) {
818 + $message = $json_res['error'];
819 + } else {
820 + $message = $json_res;
821 + }
1021 822 } elseif ( ! empty( $resp['response'] ) && ! empty( $resp['response']['code'] ) ) {
1022 823 $resp['body'] = wp_strip_all_tags( $resp['body'] );
1023 824
1024 825 $message = sprintf(
@@ -1032,11 +833,8 @@
1032 833
1033 834 return $message;
1034 835 }
1035 836
1036 - /**
1037 - * @return void
1038 - */
1039 837 public function manually_queue_update() {
1040 838 $updates = new stdClass();
1041 839 $updates->last_checked = 0;
1042 840 $updates->response = array();