PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.01.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.01.02
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 +47 -181 6.44.01.02 View file →
@@ -1,10 +1,10 @@
1 1 <?php
2 +
2 3 if ( ! defined( 'ABSPATH' ) ) {
3 4 die( 'You are not allowed to call this page directly.' );
4 5 }
5 6
6 -/** @phpstan-consistent-constructor */
7 7 class FrmAddon {
8 8 public $store_url = 'https://formidableforms.com';
9 9 public $download_id;
10 10 public $plugin_file;
@@ -14,9 +14,8 @@
14 14 public $option_name;
15 15 public $version;
16 16 public $author = 'Strategy11';
17 17 public $is_parent_licence = false;
18 - public $needs_license = true;
19 18 private $is_expired_addon = false;
20 19 public $license;
21 20 protected $get_beta = false;
22 21
@@ -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;
@@ -239,45 +237,11 @@
239 237 public function set_active( $is_active ) {
240 238 update_option( $this->option_name . 'active', $is_active );
241 239 $this->delete_cache();
242 240 FrmAppHelper::save_combined_js();
243 - $this->update_pro_capabilities();
244 241 }
245 242
246 243 /**
247 - * Updates roles capabilities after pro license is active.
248 - *
249 - * @since 5.0
250 - */
251 - protected function update_pro_capabilities() {
252 - global $wp_roles;
253 -
254 - if ( ! function_exists( 'get_editable_roles' ) ) {
255 - require_once ABSPATH . 'wp-admin/includes/user.php';
256 - }
257 -
258 - $caps = FrmAppHelper::frm_capabilities( 'pro_only' );
259 - $roles = get_editable_roles();
260 - $settings = new FrmSettings();
261 - foreach ( $caps as $cap => $cap_desc ) {
262 - $cap_roles = (array) ( isset( $settings->$cap ) ? $settings->$cap : 'administrator' );
263 -
264 - // Make sure administrators always have permissions.
265 - if ( ! in_array( 'administrator', $cap_roles ) ) {
266 - array_push( $cap_roles, 'administrator' );
267 - }
268 -
269 - foreach ( $roles as $role => $details ) {
270 - if ( in_array( $role, $cap_roles ) ) {
271 - $wp_roles->add_cap( $role, $cap );
272 - } else {
273 - $wp_roles->remove_cap( $role, $cap );
274 - }
275 - }
276 - }
277 - }
278 -
279 - /**
280 244 * @since 3.04.03
281 245 */
282 246 protected function delete_cache() {
283 247 delete_transient( 'frm_api_licence' );
@@ -286,11 +250,8 @@
286 250 $api->reset_cached();
287 251
288 252 $api = new FrmFormTemplateApi( $this->license );
289 253 $api->reset_cached();
290 -
291 - $api = new FrmApplicationApi( $this->license );
292 - $api->reset_cached();
293 254 }
294 255
295 256 /**
296 257 * The Pro version includes the show_license_message function.
@@ -310,9 +271,9 @@
310 271 public function show_license_message( $file, $plugin ) {
311 272 $message = '';
312 273 if ( empty( $this->license ) ) {
313 274 /* translators: %1$s: Plugin name, %2$s: Start link HTML, %3$s: end link HTML */
314 - $message = sprintf( esc_html__( 'Your %1$s license key is missing. Please add it on the %2$slicenses page%3$s.', 'formidable' ), esc_html( $this->plugin_name ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings' ) ) . '">', '</a>' );
275 + $message = sprintf( esc_html__( 'Your %1$s license key is missing. Please add it on the %2$slicenses page%3$s.', 'formidable' ), esc_html( $this->plugin_name ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings&t=licenses_settings' ) ) . '">', '</a>' );
315 276 } else {
316 277 $api = new FrmFormApi( $this->license );
317 278 $errors = $api->error_for_license();
318 279 if ( ! empty( $errors ) ) {
@@ -327,9 +288,9 @@
327 288 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
328 289 $id = sanitize_title( $plugin['Name'] ) . '-next';
329 290
330 291 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
292 + echo FrmAppHelper::kses( $message, 'a' ); // WPCS: XSS ok.
332 293 echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>';
333 294 echo '</p></div></td></tr>';
334 295 }
335 296
@@ -398,9 +359,9 @@
398 359
399 360 // if there is no download url, this license does not apply to the addon
400 361 if ( isset( $addon['package'] ) ) {
401 362 $this->is_parent_licence = true;
402 - } elseif ( isset( $addon['error'] ) ) {
363 + } elseif ( isset( $addons['error'] ) ) {
403 364 // if the license is expired, we must assume all add-ons were packaged
404 365 $this->is_parent_licence = true;
405 366 $this->is_expired_addon = true;
406 367 }
@@ -454,65 +415,40 @@
454 415
455 416 private function has_been_cleared() {
456 417 $last_cleared = get_option( 'frm_last_cleared' );
457 418
458 - return ( $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ) );
419 + return ( $last_cleared && $last_cleared > date( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ) );
459 420 }
460 421
461 422 private function cleared_plugins() {
462 - update_option( 'frm_last_cleared', gmdate( 'Y-m-d H:i:s' ) );
423 + update_option( 'frm_last_cleared', date( 'Y-m-d H:i:s' ) );
463 424 }
464 425
465 426 private function is_license_revoked() {
466 - if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
427 + if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // WPCS: CSRF ok.
467 428 return;
468 429 }
469 430
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 431 if ( is_multisite() ) {
500 432 $last_checked = get_site_option( $this->transient_key() );
501 433 } else {
502 434 $last_checked = get_option( $this->transient_key() );
503 435 }
504 - return $last_checked;
505 - }
506 436
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' ) );
437 + $seven_days_ago = date( 'Y-m-d H:i:s', strtotime( '-7 days' ) );
438 +
439 + if ( ! $last_checked || $last_checked < $seven_days_ago ) {
440 + // check weekly
441 + if ( is_multisite() ) {
442 + update_site_option( $this->transient_key(), date( 'Y-m-d H:i:s' ) );
443 + } else {
444 + update_option( $this->transient_key(), date( 'Y-m-d H:i:s' ) );
445 + }
446 +
447 + $response = $this->get_license_status();
448 + if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] ) {
449 + $this->clear_license();
450 + }
515 451 }
516 452 }
517 453
518 454 /**
@@ -525,38 +461,32 @@
525 461 public static function activate() {
526 462 FrmAppHelper::permission_check( 'frm_change_settings' );
527 463 check_ajax_referer( 'frm_ajax', 'nonce' );
528 464
529 - $license = stripslashes( FrmAppHelper::get_param( 'license', '', 'post', 'sanitize_text_field' ) );
530 - if ( empty( $license ) ) {
531 - wp_send_json(
532 - array(
533 - 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ),
534 - 'success' => false,
465 + if ( ! isset( $_POST['license'] ) || empty( $_POST['license'] ) ) {
466 + wp_die(
467 + json_encode(
468 + array(
469 + 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ),
470 + 'success' => false,
471 + )
535 472 )
536 473 );
537 474 }
538 475
476 + $license = stripslashes( FrmAppHelper::get_param( 'license', '', 'post', 'sanitize_text_field' ) );
539 477 $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
540 - $response = self::activate_license_for_plugin( $license, $plugin_slug );
478 + $this_plugin = self::get_addon( $plugin_slug );
479 + $response = $this_plugin->activate_license( $license );
541 480
542 - wp_send_json( $response );
481 + echo json_encode( $response );
482 + wp_die();
543 483 }
544 484
545 - /**
546 - * @since 4.08
547 - */
548 - public static function activate_license_for_plugin( $license, $plugin_slug ) {
549 - $this_plugin = self::get_addon( $plugin_slug );
550 - return $this_plugin->activate_license( $license );
551 - }
552 -
553 485 private function activate_license( $license ) {
554 486 $this->set_license( $license );
555 487 $this->license = $license;
556 488
557 - $this->die_if_not_allowed();
558 -
559 489 $response = $this->get_license_status();
560 490 $response['message'] = '';
561 491 $response['success'] = false;
562 492
@@ -577,32 +507,11 @@
577 507 }
578 508 $this->set_active( $is_valid );
579 509 }
580 510
581 - $this->update_last_checked();
582 -
583 511 return $response;
584 512 }
585 513
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 514 private function get_license_status() {
606 515 $response = array(
607 516 'status' => 'missing',
608 517 'error' => true,
@@ -618,9 +527,9 @@
618 527 $license_data = $this->send_mothership_request( 'activate_license' );
619 528
620 529 // $license_data->license will be either "valid" or "invalid"
621 530 if ( is_array( $license_data ) ) {
622 - if ( isset( $license_data['license'] ) && in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) {
531 + if ( in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) {
623 532 $response['status'] = $license_data['license'];
624 533 }
625 534 } else {
626 535 $response['status'] = $license_data;
@@ -643,31 +552,16 @@
643 552 'missing' => __( 'That license key is invalid', 'formidable' ),
644 553 );
645 554 }
646 555
647 - /**
648 - * @since 4.03
649 - */
650 - public static function reset_cache() {
651 - FrmAppHelper::permission_check( 'frm_change_settings' );
652 - check_ajax_referer( 'frm_ajax', 'nonce' );
653 -
654 - $this_plugin = self::set_license_from_post();
655 - $this_plugin->delete_cache();
656 -
657 - $response = array(
658 - 'success' => true,
659 - 'message' => __( 'Cache cleared', 'formidable' ),
660 - );
661 -
662 - wp_send_json( $response );
663 - }
664 -
665 556 public static function deactivate() {
666 557 FrmAppHelper::permission_check( 'frm_change_settings' );
667 558 check_ajax_referer( 'frm_ajax', 'nonce' );
668 559
669 - $this_plugin = self::set_license_from_post();
560 + $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
561 + $this_plugin = self::get_addon( $plugin_slug );
562 + $license = $this_plugin->get_license();
563 + $this_plugin->license = $license;
670 564
671 565 $response = array(
672 566 'success' => false,
673 567 'message' => '',
@@ -686,25 +580,12 @@
686 580 }
687 581
688 582 $this_plugin->clear_license();
689 583
690 - wp_send_json( $response );
584 + echo json_encode( $response );
585 + wp_die();
691 586 }
692 587
693 - /**
694 - * @since 4.03
695 - */
696 - private static function set_license_from_post() {
697 - $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
698 - $this_plugin = self::get_addon( $plugin_slug );
699 - $license = $this_plugin->get_license();
700 - $this_plugin->license = $license;
701 - return $this_plugin;
702 - }
703 -
704 - /**
705 - * @return string
706 - */
707 588 public function send_mothership_request( $action ) {
708 589 $api_params = array(
709 590 'edd_action' => $action,
710 591 'license' => $this->license,
@@ -721,12 +602,9 @@
721 602 'timeout' => 25,
722 603 'user-agent' => $this->plugin_slug . '/' . $this->version . '; ' . get_bloginfo( 'url' ),
723 604 );
724 605
725 - $resp = wp_remote_post(
726 - $this->store_url . '?l=' . urlencode( base64_encode( $this->license ) ),
727 - $arg_array
728 - );
606 + $resp = wp_remote_post( $this->store_url, $arg_array );
729 607 $body = wp_remote_retrieve_body( $resp );
730 608
731 609 $message = __( 'Your License Key was invalid', 'formidable' );
732 610 if ( is_wp_error( $resp ) ) {
@@ -744,16 +622,10 @@
744 622 } else {
745 623 $message = $json_res;
746 624 }
747 625 } 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 - );
626 + /* translators: %1$s: Error code, %2$s: Error message */
627 + $message = sprintf( __( 'There was a %1$s error: %2$s', 'formidable' ), $resp['response']['code'], $resp['response']['message'] . ' ' . $resp['body'] );
756 628 }
757 629 }
758 630
759 631 return $message;
@@ -759,13 +631,7 @@
759 631 return $message;
760 632 }
761 633
762 634 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 );
635 + set_site_transient( 'update_plugins', null );
770 636 }
771 637 }