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