PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.04
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.04
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 +31 -94 6.55.2.04 View file →
@@ -2,9 +2,8 @@
2 2 if ( ! defined( 'ABSPATH' ) ) {
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 -/** @phpstan-consistent-constructor */
7 6 class FrmAddon {
8 7 public $store_url = 'https://formidableforms.com';
9 8 public $download_id;
10 9 public $plugin_file;
@@ -37,9 +36,9 @@
37 36 }
38 37
39 38 public static function load_hooks() {
40 39 add_filter( 'frm_include_addon_page', '__return_true' );
41 - new static();
40 + //new static();
42 41 }
43 42
44 43 public function insert_installed_addon( $plugins ) {
45 44 $plugins[ $this->plugin_slug ] = $this;
@@ -250,12 +249,8 @@
250 249 */
251 250 protected function update_pro_capabilities() {
252 251 global $wp_roles;
253 252
254 - if ( ! function_exists( 'get_editable_roles' ) ) {
255 - require_once ABSPATH . 'wp-admin/includes/user.php';
256 - }
257 -
258 253 $caps = FrmAppHelper::frm_capabilities( 'pro_only' );
259 254 $roles = get_editable_roles();
260 255 $settings = new FrmSettings();
261 256 foreach ( $caps as $cap => $cap_desc ) {
@@ -286,11 +281,8 @@
286 281 $api->reset_cached();
287 282
288 283 $api = new FrmFormTemplateApi( $this->license );
289 284 $api->reset_cached();
290 -
291 - $api = new FrmApplicationApi( $this->license );
292 - $api->reset_cached();
293 285 }
294 286
295 287 /**
296 288 * The Pro version includes the show_license_message function.
@@ -466,53 +458,28 @@
466 458 if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
467 459 return;
468 460 }
469 461
470 - // Only check weekly.
471 - if ( $this->checked_recently( '7 days' ) ) {
472 - return;
473 - }
474 -
475 - $this->update_last_checked();
476 -
477 - $response = $this->get_license_status();
478 - if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] || 'missing' === $response['status'] ) {
479 - $this->clear_license();
480 - }
481 - }
482 -
483 - /**
484 - * Has this been checked too recently?
485 - *
486 - * @param string $time ie. '1 day'
487 - * @return bool
488 - */
489 - private function checked_recently( $time ) {
490 - $last_checked = $this->last_checked();
491 - $time_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-' . $time ) );
492 - return $last_checked && $last_checked > $time_ago;
493 - }
494 -
495 - /**
496 - * @return bool|string
497 - */
498 - private function last_checked() {
499 462 if ( is_multisite() ) {
500 463 $last_checked = get_site_option( $this->transient_key() );
501 464 } else {
502 465 $last_checked = get_option( $this->transient_key() );
503 466 }
504 - return $last_checked;
505 - }
506 467
507 - /**
508 - * @return void
509 - */
510 - private function update_last_checked() {
511 - if ( is_multisite() ) {
512 - update_site_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
513 - } else {
514 - update_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
468 + $seven_days_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-7 days' ) );
469 +
470 + if ( ! $last_checked || $last_checked < $seven_days_ago ) {
471 + // check weekly
472 + if ( is_multisite() ) {
473 + update_site_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
474 + } else {
475 + update_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
476 + }
477 +
478 + $response = $this->get_license_status();
479 + if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] ) {
480 + $this->clear_license();
481 + }
515 482 }
516 483 }
517 484
518 485 /**
@@ -527,12 +494,14 @@
527 494 check_ajax_referer( 'frm_ajax', 'nonce' );
528 495
529 496 $license = stripslashes( FrmAppHelper::get_param( 'license', '', 'post', 'sanitize_text_field' ) );
530 497 if ( empty( $license ) ) {
531 - wp_send_json(
532 - array(
533 - 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ),
534 - 'success' => false,
498 + wp_die(
499 + json_encode(
500 + array(
501 + 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ),
502 + 'success' => false,
503 + )
535 504 )
536 505 );
537 506 }
538 507
@@ -538,9 +507,10 @@
538 507
539 508 $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
540 509 $response = self::activate_license_for_plugin( $license, $plugin_slug );
541 510
542 - wp_send_json( $response );
511 + echo json_encode( $response );
512 + wp_die();
543 513 }
544 514
545 515 /**
546 516 * @since 4.08
@@ -553,10 +523,8 @@
553 523 private function activate_license( $license ) {
554 524 $this->set_license( $license );
555 525 $this->license = $license;
556 526
557 - $this->die_if_not_allowed();
558 -
559 527 $response = $this->get_license_status();
560 528 $response['message'] = '';
561 529 $response['success'] = false;
562 530
@@ -577,32 +545,11 @@
577 545 }
578 546 $this->set_active( $is_valid );
579 547 }
580 548
581 - $this->update_last_checked();
582 -
583 549 return $response;
584 550 }
585 551
586 - /**
587 - * Prevent this check from happening more than once per minute with the same license.
588 - *
589 - * @return void
590 - */
591 - private function die_if_not_allowed() {
592 - if ( ! $this->checked_recently( '2 minutes' ) ) {
593 - return;
594 - }
595 -
596 - // Don't check more than once per minute.
597 - wp_send_json(
598 - array(
599 - 'message' => __( 'Please wait two minutes before trying again.', 'formidable' ),
600 - 'success' => false,
601 - )
602 - );
603 - }
604 -
605 552 private function get_license_status() {
606 553 $response = array(
607 554 'status' => 'missing',
608 555 'error' => true,
@@ -618,9 +565,9 @@
618 565 $license_data = $this->send_mothership_request( 'activate_license' );
619 566
620 567 // $license_data->license will be either "valid" or "invalid"
621 568 if ( is_array( $license_data ) ) {
622 - if ( isset( $license_data['license'] ) && in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) {
569 + if ( in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) {
623 570 $response['status'] = $license_data['license'];
624 571 }
625 572 } else {
626 573 $response['status'] = $license_data;
@@ -658,9 +605,10 @@
658 605 'success' => true,
659 606 'message' => __( 'Cache cleared', 'formidable' ),
660 607 );
661 608
662 - wp_send_json( $response );
609 + echo json_encode( $response );
610 + wp_die();
663 611 }
664 612
665 613 public static function deactivate() {
666 614 FrmAppHelper::permission_check( 'frm_change_settings' );
@@ -686,9 +634,10 @@
686 634 }
687 635
688 636 $this_plugin->clear_license();
689 637
690 - wp_send_json( $response );
638 + echo json_encode( $response );
639 + wp_die();
691 640 }
692 641
693 642 /**
694 643 * @since 4.03
@@ -700,11 +649,8 @@
700 649 $this_plugin->license = $license;
701 650 return $this_plugin;
702 651 }
703 652
704 - /**
705 - * @return string
706 - */
707 653 public function send_mothership_request( $action ) {
708 654 $api_params = array(
709 655 'edd_action' => $action,
710 656 'license' => $this->license,
@@ -721,12 +667,9 @@
721 667 'timeout' => 25,
722 668 'user-agent' => $this->plugin_slug . '/' . $this->version . '; ' . get_bloginfo( 'url' ),
723 669 );
724 670
725 - $resp = wp_remote_post(
726 - $this->store_url . '?l=' . urlencode( base64_encode( $this->license ) ),
727 - $arg_array
728 - );
671 + $resp = wp_remote_post( $this->store_url, $arg_array );
729 672 $body = wp_remote_retrieve_body( $resp );
730 673
731 674 $message = __( 'Your License Key was invalid', 'formidable' );
732 675 if ( is_wp_error( $resp ) ) {
@@ -744,16 +687,10 @@
744 687 } else {
745 688 $message = $json_res;
746 689 }
747 690 } elseif ( isset( $resp['response'] ) && isset( $resp['response']['code'] ) ) {
748 - $resp['body'] = wp_strip_all_tags( $resp['body'] );
749 -
750 - $message = sprintf(
751 - /* translators: %1$s: Error code, %2$s: Error message */
752 - esc_html__( 'There was a %1$s error: %2$s', 'formidable' ),
753 - esc_html( $resp['response']['code'] ),
754 - $resp['response']['message'] . ' ' . $resp['body']
755 - );
691 + /* translators: %1$s: Error code, %2$s: Error message */
692 + $message = sprintf( __( 'There was a %1$s error: %2$s', 'formidable' ), $resp['response']['code'], $resp['response']['message'] . ' ' . $resp['body'] );
756 693 }
757 694 }
758 695
759 696 return $message;