PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7
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 +63 -184 6.256.7 View file →
@@ -12,43 +12,15 @@
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 - /**
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 - * 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.
37 - *
38 - * @since 6.8.3
39 - *
40 - * @var string
41 - */
42 - private $transient_lock_key = 'frm_activate_request_lock';
43 -
44 - /**
45 - * @since 6.8.3
46 - *
47 - * @var bool
48 - */
49 - protected $should_clear_cache = true;
50 -
51 23 public function __construct() {
52 24
53 25 if ( empty( $this->plugin_slug ) ) {
54 26 $this->plugin_slug = preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->plugin_name ) ) );
@@ -102,13 +74,13 @@
102 74 }
103 75 }
104 76
105 77 /**
106 - * Updates information on the "View version 6.15 details" page with custom data.
78 + * Updates information on the "View version x.x details" page with custom data.
107 79 *
108 80 * @uses api_request()
109 81 *
110 - * @param mixed $_data
82 + * @param mixed $_data
111 83 * @param string $_action
112 84 * @param object $_args
113 85 *
114 86 * @return object $_data
@@ -198,10 +170,11 @@
198 170 * @since 2.04
199 171 */
200 172 public function activate_defined_license() {
201 173 $license = $this->get_defined_license();
202 - if ( ! empty( $license ) && ! $this->is_active() && ! $this->checked_recently( '1 day' ) ) {
174 + if ( ! empty( $license ) && ! $this->is_active() && $this->is_time_to_auto_activate() ) {
203 175 $response = $this->activate_license( $license );
176 + $this->set_auto_activate_time();
204 177 if ( ! $response['success'] ) {
205 178 $license = '';
206 179 }
207 180 }
@@ -214,11 +187,11 @@
214 187 *
215 188 * @since 2.04
216 189 */
217 190 public function get_defined_license() {
218 - $constant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE';
191 + $consant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE';
219 192
220 - return defined( $constant_name ) ? constant( $constant_name ) : false;
193 + return defined( $consant_name ) ? constant( $consant_name ) : false;
221 194 }
222 195
223 196 public function set_license( $license ) {
224 197 update_option( $this->option_name . 'key', $license );
@@ -223,8 +196,24 @@
223 196 public function set_license( $license ) {
224 197 update_option( $this->option_name . 'key', $license );
225 198 }
226 199
200 + /**
201 + * If the license is in the config, limit the frequency of checks.
202 + * The license may be entered incorrectly, so we don't want to check on every page load.
203 + *
204 + * @since 2.04
205 + */
206 + private function is_time_to_auto_activate() {
207 + $last_try = get_option( $this->option_name . 'last_activate' );
208 +
209 + return ( ! $last_try || $last_try < strtotime( '-1 day' ) );
210 + }
211 +
212 + private function set_auto_activate_time() {
213 + update_option( $this->option_name . 'last_activate', time() );
214 + }
215 +
227 216 public function is_active() {
228 217 return get_option( $this->option_name . 'active' );
229 218 }
230 219
@@ -230,12 +219,12 @@
230 219
231 220 /**
232 221 * @since 3.04.03
233 222 *
234 - * @param array|string $error
223 + * @param array error
235 224 */
236 225 public function maybe_clear_license( $error ) {
237 - if ( is_array( $error ) && $error['code'] === 'disabled' && $error['license'] === $this->license ) {
226 + if ( $error['code'] === 'disabled' && $error['license'] === $this->license ) {
238 227 $this->clear_license();
239 228 }
240 229 }
241 230
@@ -241,41 +230,15 @@
241 230
242 231 public function clear_license() {
243 232 delete_option( $this->option_name . 'active' );
244 233 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 - }
234 + delete_site_option( $this->transient_key() );
235 + delete_option( $this->transient_key() );
236 + $this->delete_cache();
252 237 }
253 238
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 239 public function set_active( $is_active ) {
240 + update_option( $this->option_name . 'active', $is_active );
278 241 $this->delete_cache();
279 242 FrmAppHelper::save_combined_js();
280 243 $this->update_pro_capabilities();
281 244 }
@@ -295,12 +258,12 @@
295 258 $caps = FrmAppHelper::frm_capabilities( 'pro_only' );
296 259 $roles = get_editable_roles();
297 260 $settings = new FrmSettings();
298 261 foreach ( $caps as $cap => $cap_desc ) {
299 - $cap_roles = (array) ( $settings->$cap ?? 'administrator' );
262 + $cap_roles = (array) ( isset( $settings->$cap ) ? $settings->$cap : 'administrator' );
300 263
301 264 // Make sure administrators always have permissions.
302 - if ( ! in_array( 'administrator', $cap_roles, true ) ) {
265 + if ( ! in_array( 'administrator', $cap_roles ) ) {
303 266 array_push( $cap_roles, 'administrator' );
304 267 }
305 268
306 269 foreach ( $roles as $role => $details ) {
@@ -318,11 +281,8 @@
318 281 */
319 282 protected function delete_cache() {
320 283 delete_transient( 'frm_api_licence' );
321 284
322 - // Cleanup option that has been removed.
323 - delete_option( $this->option_name . 'last_activate' );
324 -
325 285 $api = new FrmFormApi( $this->license );
326 286 $api->reset_cached();
327 287
328 288 $api = new FrmFormTemplateApi( $this->license );
@@ -329,11 +289,8 @@
329 289 $api->reset_cached();
330 290
331 291 $api = new FrmApplicationApi( $this->license );
332 292 $api->reset_cached();
333 -
334 - $api = new FrmSalesApi();
335 - $api->reset_cached();
336 293 }
337 294
338 295 /**
339 296 * The Pro version includes the show_license_message function.
@@ -370,9 +327,9 @@
370 327 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
371 328 $id = sanitize_title( $plugin['Name'] ) . '-next';
372 329
373 330 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' );
331 + echo FrmAppHelper::kses( $message, 'a' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
375 332 echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>';
376 333 echo '</p></div></td></tr>';
377 334 }
378 335
@@ -381,9 +338,9 @@
381 338 return $transient;
382 339 }
383 340
384 341 if ( $this->is_current_version( $transient ) ) {
385 - // Make sure it doesn't show there is an update if plugin is up-to-date.
342 + //make sure it doesn't show there is an update if plugin is up-to-date
386 343 if ( isset( $transient->response[ $this->plugin_folder ] ) ) {
387 344 unset( $transient->response[ $this->plugin_folder ] );
388 345 }
389 346 } elseif ( isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) ) {
@@ -406,21 +363,20 @@
406 363 * Check if the plugin information is correct to allow an update
407 364 *
408 365 * @since 3.04.03
409 366 *
410 - * @param object $transient The current plugin info saved for update.
367 + * @param object $transient - the current plugin info saved for update
411 368 */
412 369 private function prepare_update_details( &$transient ) {
413 370 $version_info = $transient;
414 - $has_beta_url = ! empty( $version_info->beta );
371 + $has_beta_url = isset( $version_info->beta ) && ! empty( $version_info->beta );
415 372 if ( $this->get_beta && ! $has_beta_url ) {
416 373 $version_info = (object) $this->get_api_info( $this->license );
417 374 }
418 375
419 - if ( ! empty( $version_info->new_version ) ) {
376 + if ( isset( $version_info->new_version ) && ! empty( $version_info->new_version ) ) {
420 377 $this->clear_old_plugin_version( $version_info );
421 - if ( $version_info === false ) {
422 - // Was cleared with timeout.
378 + if ( $version_info === false ) { // was cleared with timeout
423 379 $transient = false;
424 380 } else {
425 381 $this->maybe_use_beta_url( $version_info );
426 382
@@ -458,12 +414,11 @@
458 414 *
459 415 * @since 2.05.05
460 416 */
461 417 private function clear_old_plugin_version( &$version_info ) {
462 - $timeout = ! empty( $version_info->timeout ) ? $version_info->timeout : 0;
418 + $timeout = ( isset( $version_info->timeout ) && ! empty( $version_info->timeout ) ) ? $version_info->timeout : 0;
463 419 if ( ! empty( $timeout ) && time() > $timeout ) {
464 - // Cache is expired.
465 - $version_info = false;
420 + $version_info = false; // Cache is expired
466 421 $api = new FrmFormApi( $this->license );
467 422 $api->reset_cached();
468 423 }
469 424 }
@@ -474,12 +429,12 @@
474 429 *
475 430 * @since 3.04.03
476 431 */
477 432 private function maybe_use_beta_url( &$version_info ) {
478 - if ( $this->get_beta && ! empty( $version_info->beta ) ) {
433 + if ( $this->get_beta && isset( $version_info->beta ) && ! empty( $version_info->beta ) ) {
479 434 $version_info->new_version = $version_info->beta['version'];
480 435 $version_info->package = $version_info->beta['package'];
481 - if ( ! empty( $version_info->plugin ) ) {
436 + if ( isset( $version_info->plugin ) && ! empty( $version_info->plugin ) ) {
482 437 $version_info->plugin = $version_info->beta['plugin'];
483 438 }
484 439 }
485 440 }
@@ -488,9 +443,9 @@
488 443 if ( empty( $transient->checked ) || ! isset( $transient->checked[ $this->plugin_folder ] ) ) {
489 444 return false;
490 445 }
491 446
492 - $response = empty( $transient->response );
447 + $response = ! isset( $transient->response ) || empty( $transient->response );
493 448 if ( $response ) {
494 449 return true;
495 450 }
496 451
@@ -496,14 +451,12 @@
496 451
497 452 return isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) && $transient->checked[ $this->plugin_folder ] === $transient->response[ $this->plugin_folder ]->new_version;
498 453 }
499 454
500 - /**
501 - * @return bool
502 - */
503 455 private function has_been_cleared() {
504 456 $last_cleared = get_option( 'frm_last_cleared' );
505 - return $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) );
457 +
458 + return ( $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ) );
506 459 }
507 460
508 461 private function cleared_plugins() {
509 462 update_option( 'frm_last_cleared', gmdate( 'Y-m-d H:i:s' ) );
@@ -513,17 +466,14 @@
513 466 if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
514 467 return;
515 468 }
516 469
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.
470 + // Only check weekly.
471 + if ( $this->checked_recently( '7 days' ) ) {
519 472 return;
520 473 }
521 474
522 - // Only check weekly.
523 - if ( $this->checked_recently( '7 days', 'valid' ) || $this->is_running() ) {
524 - return;
525 - }
475 + $this->update_last_checked();
526 476
527 477 $response = $this->get_license_status();
528 478 if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] || 'missing' === $response['status'] ) {
529 479 $this->clear_license();
@@ -532,36 +482,19 @@
532 482
533 483 /**
534 484 * Has this been checked too recently?
535 485 *
536 - * @param string $time ie. '1 day'.
537 - * @param string $required_status Return false if the last check does not match. ie 'valid'.
538 - *
486 + * @param string $time ie. '1 day'
539 487 * @return bool
540 488 */
541 - private function checked_recently( $time, $required_status = '' ) {
489 + private function checked_recently( $time ) {
542 490 $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 491 $time_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-' . $time ) );
557 - return $checked_time && $checked_time > $time_ago;
492 + return $last_checked && $last_checked > $time_ago;
558 493 }
559 494
560 495 /**
561 - * @since 6.8.3 Switched to an array to store extra response info.
562 - *
563 - * @return array
496 + * @return bool|string
564 497 */
565 498 private function last_checked() {
566 499 if ( is_multisite() ) {
567 500 $last_checked = get_site_option( $this->transient_key() );
@@ -567,13 +500,9 @@
567 500 $last_checked = get_site_option( $this->transient_key() );
568 501 } else {
569 502 $last_checked = get_option( $this->transient_key() );
570 503 }
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();
504 + return $last_checked;
576 505 }
577 506
578 507 /**
579 508 * @return void
@@ -578,13 +507,12 @@
578 507 /**
579 508 * @return void
580 509 */
581 510 private function update_last_checked() {
582 - $this->save_response['time'] = gmdate( 'Y-m-d H:i:s' );
583 511 if ( is_multisite() ) {
584 - update_site_option( $this->transient_key(), $this->save_response );
512 + update_site_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
585 513 } else {
586 - update_option( $this->transient_key(), $this->save_response );
514 + update_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
587 515 }
588 516 }
589 517
590 518 /**
@@ -610,10 +538,8 @@
610 538
611 539 $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
612 540 $response = self::activate_license_for_plugin( $license, $plugin_slug );
613 541
614 - FrmInbox::clear_cache();
615 -
616 542 wp_send_json( $response );
617 543 }
618 544
619 545 /**
@@ -648,9 +574,9 @@
648 574 if ( 'valid' === $response['status'] ) {
649 575 $is_valid = 'valid';
650 576 $response['success'] = true;
651 577 }
652 - $this->maybe_set_active( $is_valid );
578 + $this->set_active( $is_valid );
653 579 }
654 580
655 581 $this->update_last_checked();
656 582
@@ -676,10 +602,8 @@
676 602 );
677 603 }
678 604
679 605 private function get_license_status() {
680 - $this->set_running();
681 -
682 606 $response = array(
683 607 'status' => 'missing',
684 608 'error' => true,
685 609 );
@@ -694,11 +618,10 @@
694 618 $license_data = $this->send_mothership_request( 'activate_license' );
695 619
696 620 // $license_data->license will be either "valid" or "invalid"
697 621 if ( is_array( $license_data ) ) {
698 - 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'];
622 + if ( isset( $license_data['license'] ) && in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) {
623 + $response['status'] = $license_data['license'];
701 624 }
702 625 } else {
703 626 $response['status'] = $license_data;
704 627 }
@@ -705,10 +628,8 @@
705 628 } catch ( Exception $e ) {
706 629 $response['status'] = $e->getMessage();
707 630 }
708 631
709 - $this->update_last_checked();
710 - $this->done_running();
711 632 return $response;
712 633 }
713 634
714 635 private function get_messages() {
@@ -764,9 +685,8 @@
764 685 $response['message'] = $e->getMessage();
765 686 }
766 687
767 688 $this_plugin->clear_license();
768 - FrmInbox::clear_cache();
769 689
770 690 wp_send_json( $response );
771 691 }
772 692
@@ -801,20 +721,19 @@
801 721 'timeout' => 25,
802 722 'user-agent' => $this->plugin_slug . '/' . $this->version . '; ' . get_bloginfo( 'url' ),
803 723 );
804 724
805 - $resp = wp_remote_post(
725 + $resp = wp_remote_post(
806 726 $this->store_url . '?l=' . urlencode( base64_encode( $this->license ) ),
807 727 $arg_array
808 728 );
809 - $body = wp_remote_retrieve_body( $resp );
810 - $this->save_status = array( 'response_code' => wp_remote_retrieve_response_code( $resp ) );
729 + $body = wp_remote_retrieve_body( $resp );
811 730
812 731 $message = __( 'Your License Key was invalid', 'formidable' );
813 732 if ( is_wp_error( $resp ) ) {
814 733 $link = FrmAppHelper::admin_upgrade_link( 'api', 'knowledgebase/why-cant-i-activate-formidable-pro/' );
815 734 /* 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>' );
735 + $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 736 $message .= ' ' . $resp->get_error_message();
818 737 } elseif ( 'error' === $body || is_wp_error( $body ) ) {
819 738 $message = __( 'You had an HTTP error connecting to the Formidable API', 'formidable' );
820 739 } else {
@@ -824,9 +743,9 @@
824 743 $message = $json_res['error'];
825 744 } else {
826 745 $message = $json_res;
827 746 }
828 - } elseif ( ! empty( $resp['response'] ) && ! empty( $resp['response']['code'] ) ) {
747 + } elseif ( isset( $resp['response'] ) && isset( $resp['response']['code'] ) ) {
829 748 $resp['body'] = wp_strip_all_tags( $resp['body'] );
830 749
831 750 $message = sprintf(
832 751 /* translators: %1$s: Error code, %2$s: Error message */
@@ -834,9 +753,9 @@
834 753 esc_html( $resp['response']['code'] ),
835 754 $resp['response']['message'] . ' ' . $resp['body']
836 755 );
837 756 }
838 - }//end if
757 + }
839 758
840 759 return $message;
841 760 }
842 761
@@ -847,46 +766,6 @@
847 766 $updates->translations = array();
848 767 $updates->no_update = array();
849 768 $updates->checked = array();
850 769 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 770 }
892 771 }