PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.4
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 -91 6.35.4 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 ) {
@@ -466,53 +461,28 @@
466 461 if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
467 462 return;
468 463 }
469 464
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 465 if ( is_multisite() ) {
500 466 $last_checked = get_site_option( $this->transient_key() );
501 467 } else {
502 468 $last_checked = get_option( $this->transient_key() );
503 469 }
504 - return $last_checked;
505 - }
506 470
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' ) );
471 + $seven_days_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-7 days' ) );
472 +
473 + if ( ! $last_checked || $last_checked < $seven_days_ago ) {
474 + // check weekly
475 + if ( is_multisite() ) {
476 + update_site_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
477 + } else {
478 + update_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
479 + }
480 +
481 + $response = $this->get_license_status();
482 + if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] ) {
483 + $this->clear_license();
484 + }
515 485 }
516 486 }
517 487
518 488 /**
@@ -527,12 +497,14 @@
527 497 check_ajax_referer( 'frm_ajax', 'nonce' );
528 498
529 499 $license = stripslashes( FrmAppHelper::get_param( 'license', '', 'post', 'sanitize_text_field' ) );
530 500 if ( empty( $license ) ) {
531 - wp_send_json(
532 - array(
533 - 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ),
534 - 'success' => false,
501 + wp_die(
502 + json_encode(
503 + array(
504 + 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ),
505 + 'success' => false,
506 + )
535 507 )
536 508 );
537 509 }
538 510
@@ -538,9 +510,10 @@
538 510
539 511 $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
540 512 $response = self::activate_license_for_plugin( $license, $plugin_slug );
541 513
542 - wp_send_json( $response );
514 + echo json_encode( $response );
515 + wp_die();
543 516 }
544 517
545 518 /**
546 519 * @since 4.08
@@ -553,10 +526,8 @@
553 526 private function activate_license( $license ) {
554 527 $this->set_license( $license );
555 528 $this->license = $license;
556 529
557 - $this->die_if_not_allowed();
558 -
559 530 $response = $this->get_license_status();
560 531 $response['message'] = '';
561 532 $response['success'] = false;
562 533
@@ -577,32 +548,11 @@
577 548 }
578 549 $this->set_active( $is_valid );
579 550 }
580 551
581 - $this->update_last_checked();
582 -
583 552 return $response;
584 553 }
585 554
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 555 private function get_license_status() {
606 556 $response = array(
607 557 'status' => 'missing',
608 558 'error' => true,
@@ -618,9 +568,9 @@
618 568 $license_data = $this->send_mothership_request( 'activate_license' );
619 569
620 570 // $license_data->license will be either "valid" or "invalid"
621 571 if ( is_array( $license_data ) ) {
622 - if ( isset( $license_data['license'] ) && in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) {
572 + if ( in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) {
623 573 $response['status'] = $license_data['license'];
624 574 }
625 575 } else {
626 576 $response['status'] = $license_data;
@@ -658,9 +608,10 @@
658 608 'success' => true,
659 609 'message' => __( 'Cache cleared', 'formidable' ),
660 610 );
661 611
662 - wp_send_json( $response );
612 + echo json_encode( $response );
613 + wp_die();
663 614 }
664 615
665 616 public static function deactivate() {
666 617 FrmAppHelper::permission_check( 'frm_change_settings' );
@@ -686,9 +637,10 @@
686 637 }
687 638
688 639 $this_plugin->clear_license();
689 640
690 - wp_send_json( $response );
641 + echo json_encode( $response );
642 + wp_die();
691 643 }
692 644
693 645 /**
694 646 * @since 4.03
@@ -700,11 +652,8 @@
700 652 $this_plugin->license = $license;
701 653 return $this_plugin;
702 654 }
703 655
704 - /**
705 - * @return string
706 - */
707 656 public function send_mothership_request( $action ) {
708 657 $api_params = array(
709 658 'edd_action' => $action,
710 659 'license' => $this->license,
@@ -721,12 +670,9 @@
721 670 'timeout' => 25,
722 671 'user-agent' => $this->plugin_slug . '/' . $this->version . '; ' . get_bloginfo( 'url' ),
723 672 );
724 673
725 - $resp = wp_remote_post(
726 - $this->store_url . '?l=' . urlencode( base64_encode( $this->license ) ),
727 - $arg_array
728 - );
674 + $resp = wp_remote_post( $this->store_url, $arg_array );
729 675 $body = wp_remote_retrieve_body( $resp );
730 676
731 677 $message = __( 'Your License Key was invalid', 'formidable' );
732 678 if ( is_wp_error( $resp ) ) {
@@ -744,16 +690,10 @@
744 690 } else {
745 691 $message = $json_res;
746 692 }
747 693 } 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 - );
694 + /* translators: %1$s: Error code, %2$s: Error message */
695 + $message = sprintf( __( 'There was a %1$s error: %2$s', 'formidable' ), $resp['response']['code'], $resp['response']['message'] . ' ' . $resp['body'] );
756 696 }
757 697 }
758 698
759 699 return $message;