PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
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 +61 -165 6.256.8 View file →
@@ -12,42 +12,24 @@
12 12 public $plugin_name;
13 13 public $plugin_slug;
14 14 public $option_name;
15 15 public $version;
16 - public $author = 'Strategy11';
16 + public $author = 'Strategy11';
17 17 public $is_parent_licence = false;
18 - public $needs_license = true;
18 + public $needs_license = true;
19 19 private $is_expired_addon = false;
20 20 public $license;
21 21 protected $get_beta = false;
22 - protected $save_status;
23 22
24 23 /**
25 - * This is used to decide whether the license checks should continue.
26 - * The point is to avoid license issues when a site url changes.
27 - *
28 - * @since 6.8.3
29 - *
30 - * @var array
31 - */
32 - private $save_response = array();
33 -
34 - /**
35 24 * This is used to flag other add ons not to send a request.
36 - * We only want to send a single API request per page load.
25 + * We only want to send a single API request per HTTP request.
37 26 *
38 - * @since 6.8.3
27 + * @since 6.7.1
39 28 *
40 - * @var string
41 - */
42 - private $transient_lock_key = 'frm_activate_request_lock';
43 -
44 - /**
45 - * @since 6.8.3
46 - *
47 29 * @var bool
48 30 */
49 - protected $should_clear_cache = true;
31 + private static $sent_mothership_request = false;
50 32
51 33 public function __construct() {
52 34
53 35 if ( empty( $this->plugin_slug ) ) {
@@ -102,9 +84,9 @@
102 84 }
103 85 }
104 86
105 87 /**
106 - * Updates information on the "View version 6.15 details" page with custom data.
88 + * Updates information on the "View version x.x details" page with custom data.
107 89 *
108 90 * @uses api_request()
109 91 *
110 92 * @param mixed $_data
@@ -198,10 +180,11 @@
198 180 * @since 2.04
199 181 */
200 182 public function activate_defined_license() {
201 183 $license = $this->get_defined_license();
202 - if ( ! empty( $license ) && ! $this->is_active() && ! $this->checked_recently( '1 day' ) ) {
184 + if ( ! empty( $license ) && ! $this->is_active() && $this->is_time_to_auto_activate() ) {
203 185 $response = $this->activate_license( $license );
186 + $this->set_auto_activate_time();
204 187 if ( ! $response['success'] ) {
205 188 $license = '';
206 189 }
207 190 }
@@ -214,11 +197,11 @@
214 197 *
215 198 * @since 2.04
216 199 */
217 200 public function get_defined_license() {
218 - $constant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE';
201 + $consant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE';
219 202
220 - return defined( $constant_name ) ? constant( $constant_name ) : false;
203 + return defined( $consant_name ) ? constant( $consant_name ) : false;
221 204 }
222 205
223 206 public function set_license( $license ) {
224 207 update_option( $this->option_name . 'key', $license );
@@ -223,8 +206,24 @@
223 206 public function set_license( $license ) {
224 207 update_option( $this->option_name . 'key', $license );
225 208 }
226 209
210 + /**
211 + * If the license is in the config, limit the frequency of checks.
212 + * The license may be entered incorrectly, so we don't want to check on every page load.
213 + *
214 + * @since 2.04
215 + */
216 + private function is_time_to_auto_activate() {
217 + $last_try = get_option( $this->option_name . 'last_activate' );
218 +
219 + return ( ! $last_try || $last_try < strtotime( '-1 day' ) );
220 + }
221 +
222 + private function set_auto_activate_time() {
223 + update_option( $this->option_name . 'last_activate', time() );
224 + }
225 +
227 226 public function is_active() {
228 227 return get_option( $this->option_name . 'active' );
229 228 }
230 229
@@ -230,12 +229,12 @@
230 229
231 230 /**
232 231 * @since 3.04.03
233 232 *
234 - * @param array|string $error
233 + * @param array $error
235 234 */
236 235 public function maybe_clear_license( $error ) {
237 - if ( is_array( $error ) && $error['code'] === 'disabled' && $error['license'] === $this->license ) {
236 + if ( $error['code'] === 'disabled' && $error['license'] === $this->license ) {
238 237 $this->clear_license();
239 238 }
240 239 }
241 240
@@ -241,41 +240,15 @@
241 240
242 241 public function clear_license() {
243 242 delete_option( $this->option_name . 'active' );
244 243 delete_option( $this->option_name . 'key' );
245 -
246 - if ( $this->should_clear_cache ) {
247 - delete_site_option( $this->transient_key() );
248 - delete_option( $this->transient_key() );
249 - $this->delete_cache();
250 - $this->should_clear_cache = true;
251 - }
244 + delete_site_option( $this->transient_key() );
245 + delete_option( $this->transient_key() );
246 + $this->delete_cache();
252 247 }
253 248
254 - /**
255 - * Don't save an invalid license.
256 - *
257 - * @since 6.8.3
258 - *
259 - * @param bool $is_valid If license activation was successful.
260 - *
261 - * @return void
262 - */
263 - protected function maybe_set_active( $is_valid ) {
264 - update_option( $this->option_name . 'active', $is_valid );
265 - if ( $is_valid ) {
266 - $this->set_active( $is_valid );
267 - return;
268 - }
269 -
270 - // Don't save the license if it's invalid.
271 - $this->should_clear_cache = false;
272 - $this->clear_license();
273 - delete_option( $this->option_name . 'key' );
274 - $this->license = '';
275 - }
276 -
277 249 public function set_active( $is_active ) {
250 + update_option( $this->option_name . 'active', $is_active );
278 251 $this->delete_cache();
279 252 FrmAppHelper::save_combined_js();
280 253 $this->update_pro_capabilities();
281 254 }
@@ -295,12 +268,12 @@
295 268 $caps = FrmAppHelper::frm_capabilities( 'pro_only' );
296 269 $roles = get_editable_roles();
297 270 $settings = new FrmSettings();
298 271 foreach ( $caps as $cap => $cap_desc ) {
299 - $cap_roles = (array) ( $settings->$cap ?? 'administrator' );
272 + $cap_roles = (array) ( isset( $settings->$cap ) ? $settings->$cap : 'administrator' );
300 273
301 274 // Make sure administrators always have permissions.
302 - if ( ! in_array( 'administrator', $cap_roles, true ) ) {
275 + if ( ! in_array( 'administrator', $cap_roles ) ) {
303 276 array_push( $cap_roles, 'administrator' );
304 277 }
305 278
306 279 foreach ( $roles as $role => $details ) {
@@ -318,11 +291,8 @@
318 291 */
319 292 protected function delete_cache() {
320 293 delete_transient( 'frm_api_licence' );
321 294
322 - // Cleanup option that has been removed.
323 - delete_option( $this->option_name . 'last_activate' );
324 -
325 295 $api = new FrmFormApi( $this->license );
326 296 $api->reset_cached();
327 297
328 298 $api = new FrmFormTemplateApi( $this->license );
@@ -329,11 +299,8 @@
329 299 $api->reset_cached();
330 300
331 301 $api = new FrmApplicationApi( $this->license );
332 302 $api->reset_cached();
333 -
334 - $api = new FrmSalesApi();
335 - $api->reset_cached();
336 303 }
337 304
338 305 /**
339 306 * The Pro version includes the show_license_message function.
@@ -370,9 +337,9 @@
370 337 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
371 338 $id = sanitize_title( $plugin['Name'] ) . '-next';
372 339
373 340 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>';
374 - FrmAppHelper::kses_echo( $message, 'a' );
341 + echo FrmAppHelper::kses( $message, 'a' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
375 342 echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>';
376 343 echo '</p></div></td></tr>';
377 344 }
378 345
@@ -410,14 +377,14 @@
410 377 * @param object $transient The current plugin info saved for update.
411 378 */
412 379 private function prepare_update_details( &$transient ) {
413 380 $version_info = $transient;
414 - $has_beta_url = ! empty( $version_info->beta );
381 + $has_beta_url = isset( $version_info->beta ) && ! empty( $version_info->beta );
415 382 if ( $this->get_beta && ! $has_beta_url ) {
416 383 $version_info = (object) $this->get_api_info( $this->license );
417 384 }
418 385
419 - if ( ! empty( $version_info->new_version ) ) {
386 + if ( isset( $version_info->new_version ) && ! empty( $version_info->new_version ) ) {
420 387 $this->clear_old_plugin_version( $version_info );
421 388 if ( $version_info === false ) {
422 389 // Was cleared with timeout.
423 390 $transient = false;
@@ -458,9 +425,9 @@
458 425 *
459 426 * @since 2.05.05
460 427 */
461 428 private function clear_old_plugin_version( &$version_info ) {
462 - $timeout = ! empty( $version_info->timeout ) ? $version_info->timeout : 0;
429 + $timeout = ( isset( $version_info->timeout ) && ! empty( $version_info->timeout ) ) ? $version_info->timeout : 0;
463 430 if ( ! empty( $timeout ) && time() > $timeout ) {
464 431 // Cache is expired.
465 432 $version_info = false;
466 433 $api = new FrmFormApi( $this->license );
@@ -474,12 +441,12 @@
474 441 *
475 442 * @since 3.04.03
476 443 */
477 444 private function maybe_use_beta_url( &$version_info ) {
478 - if ( $this->get_beta && ! empty( $version_info->beta ) ) {
445 + if ( $this->get_beta && isset( $version_info->beta ) && ! empty( $version_info->beta ) ) {
479 446 $version_info->new_version = $version_info->beta['version'];
480 447 $version_info->package = $version_info->beta['package'];
481 - if ( ! empty( $version_info->plugin ) ) {
448 + if ( isset( $version_info->plugin ) && ! empty( $version_info->plugin ) ) {
482 449 $version_info->plugin = $version_info->beta['plugin'];
483 450 }
484 451 }
485 452 }
@@ -488,9 +455,9 @@
488 455 if ( empty( $transient->checked ) || ! isset( $transient->checked[ $this->plugin_folder ] ) ) {
489 456 return false;
490 457 }
491 458
492 - $response = empty( $transient->response );
459 + $response = ! isset( $transient->response ) || empty( $transient->response );
493 460 if ( $response ) {
494 461 return true;
495 462 }
496 463
@@ -496,14 +463,12 @@
496 463
497 464 return isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) && $transient->checked[ $this->plugin_folder ] === $transient->response[ $this->plugin_folder ]->new_version;
498 465 }
499 466
500 - /**
501 - * @return bool
502 - */
503 467 private function has_been_cleared() {
504 468 $last_cleared = get_option( 'frm_last_cleared' );
505 - return $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) );
469 +
470 + return ( $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ) );
506 471 }
507 472
508 473 private function cleared_plugins() {
509 474 update_option( 'frm_last_cleared', gmdate( 'Y-m-d H:i:s' ) );
@@ -509,22 +474,24 @@
509 474 update_option( 'frm_last_cleared', gmdate( 'Y-m-d H:i:s' ) );
510 475 }
511 476
512 477 private function is_license_revoked() {
513 - if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
478 + if ( self::$sent_mothership_request ) {
514 479 return;
515 480 }
516 481
517 - if ( $this->get_defined_license() ) {
518 - // Don't check if the license is defined in wp-config.php since we can't remove it.
482 + if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
519 483 return;
520 484 }
521 485
522 486 // Only check weekly.
523 - if ( $this->checked_recently( '7 days', 'valid' ) || $this->is_running() ) {
487 + if ( $this->checked_recently( '7 days' ) ) {
524 488 return;
525 489 }
526 490
491 + self::$sent_mothership_request = true;
492 + $this->update_last_checked();
493 +
527 494 $response = $this->get_license_status();
528 495 if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] || 'missing' === $response['status'] ) {
529 496 $this->clear_license();
530 497 }
@@ -532,36 +499,19 @@
532 499
533 500 /**
534 501 * Has this been checked too recently?
535 502 *
536 - * @param string $time ie. '1 day'.
537 - * @param string $required_status Return false if the last check does not match. ie 'valid'.
538 - *
503 + * @param string $time ie. '1 day'.
539 504 * @return bool
540 505 */
541 - private function checked_recently( $time, $required_status = '' ) {
506 + private function checked_recently( $time ) {
542 507 $last_checked = $this->last_checked();
543 - $is_429 = isset( $last_checked['response_code'] ) && 429 === $last_checked['response_code'];
544 - if ( $is_429 ) {
545 - // If the last check was a a rate limit, we'll need to check again sooner.
546 - $time = '5 minutes';
547 - $required_status = '';
548 - }
549 -
550 - if ( $required_status && ( ! isset( $last_checked['status'] ) || $last_checked['status'] !== $required_status ) ) {
551 - // If the last check was invalid, we don't need to check again.
552 - return true;
553 - }
554 -
555 - $checked_time = $last_checked['time'] ?? false;
556 508 $time_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-' . $time ) );
557 - return $checked_time && $checked_time > $time_ago;
509 + return $last_checked && $last_checked > $time_ago;
558 510 }
559 511
560 512 /**
561 - * @since 6.8.3 Switched to an array to store extra response info.
562 - *
563 - * @return array
513 + * @return bool|string
564 514 */
565 515 private function last_checked() {
566 516 if ( is_multisite() ) {
567 517 $last_checked = get_site_option( $this->transient_key() );
@@ -567,13 +517,9 @@
567 517 $last_checked = get_site_option( $this->transient_key() );
568 518 } else {
569 519 $last_checked = get_option( $this->transient_key() );
570 520 }
571 - if ( $last_checked && ! is_array( $last_checked ) ) {
572 - // Get string into array for existing values.
573 - $last_checked = array( 'time' => $last_checked );
574 - }
575 - return $last_checked ? (array) $last_checked : array();
521 + return $last_checked;
576 522 }
577 523
578 524 /**
579 525 * @return void
@@ -578,13 +524,12 @@
578 524 /**
579 525 * @return void
580 526 */
581 527 private function update_last_checked() {
582 - $this->save_response['time'] = gmdate( 'Y-m-d H:i:s' );
583 528 if ( is_multisite() ) {
584 - update_site_option( $this->transient_key(), $this->save_response );
529 + update_site_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
585 530 } else {
586 - update_option( $this->transient_key(), $this->save_response );
531 + update_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
587 532 }
588 533 }
589 534
590 535 /**
@@ -610,10 +555,8 @@
610 555
611 556 $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
612 557 $response = self::activate_license_for_plugin( $license, $plugin_slug );
613 558
614 - FrmInbox::clear_cache();
615 -
616 559 wp_send_json( $response );
617 560 }
618 561
619 562 /**
@@ -648,9 +591,9 @@
648 591 if ( 'valid' === $response['status'] ) {
649 592 $is_valid = 'valid';
650 593 $response['success'] = true;
651 594 }
652 - $this->maybe_set_active( $is_valid );
595 + $this->set_active( $is_valid );
653 596 }
654 597
655 598 $this->update_last_checked();
656 599
@@ -676,10 +619,8 @@
676 619 );
677 620 }
678 621
679 622 private function get_license_status() {
680 - $this->set_running();
681 -
682 623 $response = array(
683 624 'status' => 'missing',
684 625 'error' => true,
685 626 );
@@ -695,10 +636,9 @@
695 636
696 637 // $license_data->license will be either "valid" or "invalid"
697 638 if ( is_array( $license_data ) ) {
698 639 if ( ! empty( $license_data['license'] ) && in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) {
699 - $response['status'] = $license_data['license'];
700 - $this->save_status['status'] = $license_data['license'];
640 + $response['status'] = $license_data['license'];
701 641 }
702 642 } else {
703 643 $response['status'] = $license_data;
704 644 }
@@ -705,10 +645,8 @@
705 645 } catch ( Exception $e ) {
706 646 $response['status'] = $e->getMessage();
707 647 }
708 648
709 - $this->update_last_checked();
710 - $this->done_running();
711 649 return $response;
712 650 }
713 651
714 652 private function get_messages() {
@@ -764,9 +702,8 @@
764 702 $response['message'] = $e->getMessage();
765 703 }
766 704
767 705 $this_plugin->clear_license();
768 - FrmInbox::clear_cache();
769 706
770 707 wp_send_json( $response );
771 708 }
772 709
@@ -801,20 +738,19 @@
801 738 'timeout' => 25,
802 739 'user-agent' => $this->plugin_slug . '/' . $this->version . '; ' . get_bloginfo( 'url' ),
803 740 );
804 741
805 - $resp = wp_remote_post(
742 + $resp = wp_remote_post(
806 743 $this->store_url . '?l=' . urlencode( base64_encode( $this->license ) ),
807 744 $arg_array
808 745 );
809 - $body = wp_remote_retrieve_body( $resp );
810 - $this->save_status = array( 'response_code' => wp_remote_retrieve_response_code( $resp ) );
746 + $body = wp_remote_retrieve_body( $resp );
811 747
812 748 $message = __( 'Your License Key was invalid', 'formidable' );
813 749 if ( is_wp_error( $resp ) ) {
814 750 $link = FrmAppHelper::admin_upgrade_link( 'api', 'knowledgebase/why-cant-i-activate-formidable-pro/' );
815 751 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
816 - $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>' );
752 + $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>' );
817 753 $message .= ' ' . $resp->get_error_message();
818 754 } elseif ( 'error' === $body || is_wp_error( $body ) ) {
819 755 $message = __( 'You had an HTTP error connecting to the Formidable API', 'formidable' );
820 756 } else {
@@ -847,46 +783,6 @@
847 783 $updates->translations = array();
848 784 $updates->no_update = array();
849 785 $updates->checked = array();
850 786 set_site_transient( 'update_plugins', $updates );
851 - }
852 -
853 - /**
854 - * Set the transient key for the lock. It should be unique to the license.
855 - *
856 - * @since 6.8.3
857 - *
858 - * @return bool
859 - */
860 - protected function lock_key() {
861 - return $this->transient_lock_key . '_' . $this->license;
862 - }
863 -
864 - /**
865 - * Prevent multiple requests from running at the same time.
866 - *
867 - * @since 6.8.3
868 - *
869 - * @return bool
870 - */
871 - protected function is_running() {
872 - return get_transient( $this->lock_key() );
873 - }
874 -
875 - /**
876 - * @since 6.8.3
877 - *
878 - * @return void
879 - */
880 - protected function set_running() {
881 - set_transient( $this->lock_key(), true, 2 * MINUTE_IN_SECONDS );
882 - }
883 -
884 - /**
885 - * @since 6.8.3
886 - *
887 - * @return void
888 - */
889 - protected function done_running() {
890 - delete_transient( $this->lock_key() );
891 787 }
892 788 }