PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.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 +36 -106 6.45.0 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;
@@ -90,11 +89,10 @@
90 89 if ( $_action != 'plugin_information' ) {
91 90 return $_data;
92 91 }
93 92
94 - $slug = basename( $this->plugin_file, '.php' );
95 - $slug2 = str_replace( '/' . $slug . '.php', '', $this->plugin_folder );
96 - if ( empty( $_args->slug ) || ( $_args->slug != $slug && $_args->slug !== $slug2 ) ) {
93 + $slug = basename( $this->plugin_file, '.php' );
94 + if ( ! isset( $_args->slug ) || $_args->slug != $slug ) {
97 95 return $_data;
98 96 }
99 97
100 98 $item_id = $this->download_id;
@@ -250,12 +248,8 @@
250 248 */
251 249 protected function update_pro_capabilities() {
252 250 global $wp_roles;
253 251
254 - if ( ! function_exists( 'get_editable_roles' ) ) {
255 - require_once ABSPATH . 'wp-admin/includes/user.php';
256 - }
257 -
258 252 $caps = FrmAppHelper::frm_capabilities( 'pro_only' );
259 253 $roles = get_editable_roles();
260 254 $settings = new FrmSettings();
261 255 foreach ( $caps as $cap => $cap_desc ) {
@@ -286,11 +280,8 @@
286 280 $api->reset_cached();
287 281
288 282 $api = new FrmFormTemplateApi( $this->license );
289 283 $api->reset_cached();
290 -
291 - $api = new FrmApplicationApi( $this->license );
292 - $api->reset_cached();
293 284 }
294 285
295 286 /**
296 287 * The Pro version includes the show_license_message function.
@@ -327,9 +318,9 @@
327 318 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
328 319 $id = sanitize_title( $plugin['Name'] ) . '-next';
329 320
330 321 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>';
331 - echo FrmAppHelper::kses( $message, 'a' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
322 + echo FrmAppHelper::kses( $message, 'a' ); // WPCS: XSS ok.
332 323 echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>';
333 324 echo '</p></div></td></tr>';
334 325 }
335 326
@@ -462,57 +453,32 @@
462 453 update_option( 'frm_last_cleared', gmdate( 'Y-m-d H:i:s' ) );
463 454 }
464 455
465 456 private function is_license_revoked() {
466 - if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
457 + if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // WPCS: CSRF ok.
467 458 return;
468 459 }
469 460
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 461 if ( is_multisite() ) {
500 462 $last_checked = get_site_option( $this->transient_key() );
501 463 } else {
502 464 $last_checked = get_option( $this->transient_key() );
503 465 }
504 - return $last_checked;
505 - }
506 466
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' ) );
467 + $seven_days_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-7 days' ) );
468 +
469 + if ( ! $last_checked || $last_checked < $seven_days_ago ) {
470 + // check weekly
471 + if ( is_multisite() ) {
472 + update_site_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
473 + } else {
474 + update_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
475 + }
476 +
477 + $response = $this->get_license_status();
478 + if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] ) {
479 + $this->clear_license();
480 + }
515 481 }
516 482 }
517 483
518 484 /**
@@ -527,12 +493,14 @@
527 493 check_ajax_referer( 'frm_ajax', 'nonce' );
528 494
529 495 $license = stripslashes( FrmAppHelper::get_param( 'license', '', 'post', 'sanitize_text_field' ) );
530 496 if ( empty( $license ) ) {
531 - wp_send_json(
532 - array(
533 - 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ),
534 - 'success' => false,
497 + wp_die(
498 + json_encode(
499 + array(
500 + 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ),
501 + 'success' => false,
502 + )
535 503 )
536 504 );
537 505 }
538 506
@@ -538,9 +506,10 @@
538 506
539 507 $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
540 508 $response = self::activate_license_for_plugin( $license, $plugin_slug );
541 509
542 - wp_send_json( $response );
510 + echo json_encode( $response );
511 + wp_die();
543 512 }
544 513
545 514 /**
546 515 * @since 4.08
@@ -553,10 +522,8 @@
553 522 private function activate_license( $license ) {
554 523 $this->set_license( $license );
555 524 $this->license = $license;
556 525
557 - $this->die_if_not_allowed();
558 -
559 526 $response = $this->get_license_status();
560 527 $response['message'] = '';
561 528 $response['success'] = false;
562 529
@@ -577,32 +544,11 @@
577 544 }
578 545 $this->set_active( $is_valid );
579 546 }
580 547
581 - $this->update_last_checked();
582 -
583 548 return $response;
584 549 }
585 550
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 551 private function get_license_status() {
606 552 $response = array(
607 553 'status' => 'missing',
608 554 'error' => true,
@@ -618,9 +564,9 @@
618 564 $license_data = $this->send_mothership_request( 'activate_license' );
619 565
620 566 // $license_data->license will be either "valid" or "invalid"
621 567 if ( is_array( $license_data ) ) {
622 - if ( isset( $license_data['license'] ) && in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) {
568 + if ( in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) {
623 569 $response['status'] = $license_data['license'];
624 570 }
625 571 } else {
626 572 $response['status'] = $license_data;
@@ -658,9 +604,10 @@
658 604 'success' => true,
659 605 'message' => __( 'Cache cleared', 'formidable' ),
660 606 );
661 607
662 - wp_send_json( $response );
608 + echo json_encode( $response );
609 + wp_die();
663 610 }
664 611
665 612 public static function deactivate() {
666 613 FrmAppHelper::permission_check( 'frm_change_settings' );
@@ -686,9 +633,10 @@
686 633 }
687 634
688 635 $this_plugin->clear_license();
689 636
690 - wp_send_json( $response );
637 + echo json_encode( $response );
638 + wp_die();
691 639 }
692 640
693 641 /**
694 642 * @since 4.03
@@ -700,11 +648,8 @@
700 648 $this_plugin->license = $license;
701 649 return $this_plugin;
702 650 }
703 651
704 - /**
705 - * @return string
706 - */
707 652 public function send_mothership_request( $action ) {
708 653 $api_params = array(
709 654 'edd_action' => $action,
710 655 'license' => $this->license,
@@ -721,12 +666,9 @@
721 666 'timeout' => 25,
722 667 'user-agent' => $this->plugin_slug . '/' . $this->version . '; ' . get_bloginfo( 'url' ),
723 668 );
724 669
725 - $resp = wp_remote_post(
726 - $this->store_url . '?l=' . urlencode( base64_encode( $this->license ) ),
727 - $arg_array
728 - );
670 + $resp = wp_remote_post( $this->store_url, $arg_array );
729 671 $body = wp_remote_retrieve_body( $resp );
730 672
731 673 $message = __( 'Your License Key was invalid', 'formidable' );
732 674 if ( is_wp_error( $resp ) ) {
@@ -744,16 +686,10 @@
744 686 } else {
745 687 $message = $json_res;
746 688 }
747 689 } 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 - );
690 + /* translators: %1$s: Error code, %2$s: Error message */
691 + $message = sprintf( __( 'There was a %1$s error: %2$s', 'formidable' ), $resp['response']['code'], $resp['response']['message'] . ' ' . $resp['body'] );
756 692 }
757 693 }
758 694
759 695 return $message;
@@ -759,13 +695,7 @@
759 695 return $message;
760 696 }
761 697
762 698 public function manually_queue_update() {
763 - $updates = new stdClass();
764 - $updates->last_checked = 0;
765 - $updates->response = array();
766 - $updates->translations = array();
767 - $updates->no_update = array();
768 - $updates->checked = array();
769 - set_site_transient( 'update_plugins', $updates );
699 + set_site_transient( 'update_plugins', null );
770 700 }
771 701 }