| @@ -26,19 +26,17 @@ | ||
| 26 | 26 | protected static $plugin; |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * @since 6.15 |
| 30 | - * | |
| 31 | - * @return void | |
| 32 | 30 | */ |
| 33 | 31 | public static function load_admin_hooks() { |
| 34 | - add_action( 'admin_menu', self::class . '::menu', 100 ); | |
| 35 | - add_filter( 'pre_set_site_transient_update_plugins', self::class . '::check_update' ); | |
| 32 | + add_action( 'admin_menu', __CLASS__ . '::menu', 100 ); | |
| 33 | + add_filter( 'pre_set_site_transient_update_plugins', __CLASS__ . '::check_update' ); | |
| 36 | 34 | |
| 37 | 35 | if ( FrmAppHelper::is_admin_page( 'formidable-addons' ) ) { |
| 38 | 36 | self::$request_addon_url = 'https://connect.formidableforms.com/add-on-request/'; |
| 39 | 37 | |
| 40 | - add_action( 'admin_enqueue_scripts', self::class . '::enqueue_assets', 15 ); | |
| 38 | + add_action( 'admin_enqueue_scripts', __CLASS__ . '::enqueue_assets', 15 ); | |
| 41 | 39 | add_filter( 'frm_show_footer_links', '__return_false' ); |
| 42 | 40 | } |
| 43 | 41 | } |
| 44 | 42 | |
| @@ -98,9 +96,9 @@ | ||
| 98 | 96 | return; |
| 99 | 97 | } |
| 100 | 98 | |
| 101 | 99 | $label = __( 'Add-Ons', 'formidable' ); |
| 102 | - $label = '<span style="color:#3FCA89">' . esc_html( $label ) . '</span>'; | |
| 100 | + $label = '<span style="color:#3FCA89">' . $label . '</span>'; | |
| 103 | 101 | |
| 104 | 102 | add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), $label, 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' ); |
| 105 | 103 | |
| 106 | 104 | // remove default created subpage, make the page with highest priority as default. |
| @@ -106,18 +104,12 @@ | ||
| 106 | 104 | // remove default created subpage, make the page with highest priority as default. |
| 107 | 105 | remove_submenu_page( 'formidable', 'formidable' ); |
| 108 | 106 | |
| 109 | 107 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 110 | - $cta_text = FrmSalesApi::get_best_sale_value( 'menu_cta_text' ); | |
| 111 | - | |
| 112 | - if ( ! $cta_text ) { | |
| 113 | - $cta_text = __( 'Upgrade', 'formidable' ); | |
| 114 | - } | |
| 115 | - | |
| 116 | 108 | add_submenu_page( |
| 117 | 109 | 'formidable', |
| 118 | 110 | 'Formidable | ' . __( 'Upgrade', 'formidable' ), |
| 119 | - '<span class="frm-upgrade-submenu">' . esc_html( $cta_text ) . '</span>', | |
| 111 | + '<span class="frm-upgrade-submenu">' . __( 'Upgrade', 'formidable' ) . '</span>', | |
| 120 | 112 | 'frm_view_forms', |
| 121 | 113 | 'formidable-pro-upgrade', |
| 122 | 114 | function () { |
| 123 | 115 | // This function doesn't need to do anything. |
| @@ -126,9 +118,9 @@ | ||
| 126 | 118 | ); |
| 127 | 119 | } elseif ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) ) { |
| 128 | 120 | wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) ); |
| 129 | 121 | exit; |
| 130 | - }//end if | |
| 122 | + } | |
| 131 | 123 | } |
| 132 | 124 | |
| 133 | 125 | /** |
| 134 | 126 | * @return void |
| @@ -145,9 +137,9 @@ | ||
| 145 | 137 | |
| 146 | 138 | if ( isset( $addons['error'] ) ) { |
| 147 | 139 | $api = new FrmFormApi(); |
| 148 | 140 | $errors = $api->get_error_from_response( $addons ); |
| 149 | - $license_type = $addons['error']['type'] ?? ''; | |
| 141 | + $license_type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : ''; | |
| 150 | 142 | unset( $addons['error'] ); |
| 151 | 143 | } |
| 152 | 144 | |
| 153 | 145 | $pro = array( |
| @@ -198,9 +190,8 @@ | ||
| 198 | 190 | } |
| 199 | 191 | } |
| 200 | 192 | |
| 201 | 193 | $special_categories = array(); |
| 202 | - | |
| 203 | 194 | if ( 'elite' !== self::license_type() ) { |
| 204 | 195 | $special_categories['available-addons'] = array( |
| 205 | 196 | 'name' => __( 'Available', 'formidable' ), |
| 206 | 197 | // To be assigned via JavaScript. |
| @@ -232,9 +223,8 @@ | ||
| 232 | 223 | * |
| 233 | 224 | * @since 6.15 |
| 234 | 225 | * |
| 235 | 226 | * @param array $addon The addon array that will be modified by reference. |
| 236 | - * | |
| 237 | 227 | * @return void |
| 238 | 228 | */ |
| 239 | 229 | protected static function set_categories( &$addon ) { |
| 240 | 230 | if ( ! isset( $addon['categories'] ) ) { |
| @@ -265,9 +255,8 @@ | ||
| 265 | 255 | * @return void |
| 266 | 256 | */ |
| 267 | 257 | public static function license_settings() { |
| 268 | 258 | $plugins = apply_filters( 'frm_installed_addons', array() ); |
| 269 | - | |
| 270 | 259 | if ( empty( $plugins ) ) { |
| 271 | 260 | esc_html_e( 'There are no plugins on your site that require a license', 'formidable' ); |
| 272 | 261 | |
| 273 | 262 | return; |
| @@ -314,9 +303,8 @@ | ||
| 314 | 303 | /** |
| 315 | 304 | * If the API is unable to connect, show something on the addons page |
| 316 | 305 | * |
| 317 | 306 | * @since 3.04.03 |
| 318 | - * | |
| 319 | 307 | * @return array |
| 320 | 308 | */ |
| 321 | 309 | protected static function fallback_plugin_list() { |
| 322 | 310 | $list = array( |
| @@ -413,9 +401,8 @@ | ||
| 413 | 401 | /** |
| 414 | 402 | * If Pro is missing but has been authenticated, include a download URL |
| 415 | 403 | * |
| 416 | 404 | * @since 3.04.03 |
| 417 | - * | |
| 418 | 405 | * @return string |
| 419 | 406 | */ |
| 420 | 407 | public static function get_pro_download_url() { |
| 421 | 408 | $license = self::get_pro_license(); |
| @@ -422,20 +409,17 @@ | ||
| 422 | 409 | $api = new FrmFormApi( $license ); |
| 423 | 410 | $downloads = $api->get_api_info(); |
| 424 | 411 | $pro = self::get_pro_from_addons( $downloads ); |
| 425 | 412 | |
| 426 | - return $pro['url'] ?? ''; | |
| 413 | + return isset( $pro['url'] ) ? $pro['url'] : ''; | |
| 427 | 414 | } |
| 428 | 415 | |
| 429 | 416 | /** |
| 430 | 417 | * @since 4.08 |
| 431 | - * | |
| 432 | - * @return string | |
| 433 | 418 | */ |
| 434 | 419 | public static function get_pro_license() { |
| 435 | 420 | $pro_cred_store = 'frmpro-credentials'; |
| 436 | 421 | $pro_wpmu_store = 'frmpro-wpmu-sitewide'; |
| 437 | - | |
| 438 | 422 | if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) { |
| 439 | 423 | $creds = get_site_option( $pro_cred_store ); |
| 440 | 424 | } else { |
| 441 | 425 | $creds = get_option( $pro_cred_store ); |
| @@ -445,9 +429,8 @@ | ||
| 445 | 429 | return ''; |
| 446 | 430 | } |
| 447 | 431 | |
| 448 | 432 | $license = $creds['license']; |
| 449 | - | |
| 450 | 433 | if ( empty( $license ) ) { |
| 451 | 434 | return ''; |
| 452 | 435 | } |
| 453 | 436 | |
| @@ -461,19 +444,16 @@ | ||
| 461 | 444 | /** |
| 462 | 445 | * @since 4.08 |
| 463 | 446 | * |
| 464 | 447 | * @param array $addons |
| 465 | - * | |
| 466 | 448 | * @return array |
| 467 | 449 | */ |
| 468 | 450 | protected static function get_pro_from_addons( $addons ) { |
| 469 | - return $addons['93790'] ?? array(); | |
| 451 | + return isset( $addons['93790'] ) ? $addons['93790'] : array(); | |
| 470 | 452 | } |
| 471 | 453 | |
| 472 | 454 | /** |
| 473 | 455 | * @since 4.06 |
| 474 | - * | |
| 475 | - * @return string | |
| 476 | 456 | */ |
| 477 | 457 | public static function license_type() { |
| 478 | 458 | if ( is_callable( 'FrmProAddonsController::license_type' ) ) { |
| 479 | 459 | return FrmProAddonsController::license_type(); |
| @@ -488,21 +468,18 @@ | ||
| 488 | 468 | * @return bool |
| 489 | 469 | */ |
| 490 | 470 | public static function is_license_expired() { |
| 491 | 471 | $version_info = self::get_primary_license_info(); |
| 492 | - | |
| 493 | 472 | if ( ! isset( $version_info['error'] ) ) { |
| 494 | 473 | return false; |
| 495 | 474 | } |
| 496 | 475 | |
| 497 | - $expires = $version_info['error']['expires'] ?? 0; | |
| 498 | - | |
| 476 | + $expires = isset( $version_info['error']['expires'] ) ? $version_info['error']['expires'] : 0; | |
| 499 | 477 | if ( empty( $expires ) || $expires > time() ) { |
| 500 | 478 | return false; |
| 501 | 479 | } |
| 502 | 480 | |
| 503 | 481 | $rate_limited = ! empty( $version_info['response_code'] ) && 429 === (int) $version_info['response_code']; |
| 504 | - | |
| 505 | 482 | if ( $rate_limited ) { |
| 506 | 483 | // Do not return false positives for rate limited responses. |
| 507 | 484 | return false; |
| 508 | 485 | } |
| @@ -517,13 +494,11 @@ | ||
| 517 | 494 | * @return array|false |
| 518 | 495 | */ |
| 519 | 496 | public static function get_primary_license_info() { |
| 520 | 497 | $installed_addons = apply_filters( 'frm_installed_addons', array() ); |
| 521 | - | |
| 522 | 498 | if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) { |
| 523 | 499 | return false; |
| 524 | 500 | } |
| 525 | - | |
| 526 | 501 | $installed_addons = array( |
| 527 | 502 | 'formidable_pro' => $installed_addons['formidable_pro'], |
| 528 | 503 | ); |
| 529 | 504 | |
| @@ -531,12 +506,8 @@ | ||
| 531 | 506 | } |
| 532 | 507 | |
| 533 | 508 | /** |
| 534 | 509 | * @since 3.04.03 |
| 535 | - * | |
| 536 | - * @param mixed $transient | |
| 537 | - * | |
| 538 | - * @return object | |
| 539 | 510 | */ |
| 540 | 511 | public static function check_update( $transient ) { |
| 541 | 512 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 542 | 513 | // Don't make any changes if only Lite is installed. |
| @@ -547,9 +518,8 @@ | ||
| 547 | 518 | $transient = new stdClass(); |
| 548 | 519 | } |
| 549 | 520 | |
| 550 | 521 | $installed_addons = apply_filters( 'frm_installed_addons', array() ); |
| 551 | - | |
| 552 | 522 | if ( empty( $installed_addons ) ) { |
| 553 | 523 | return $transient; |
| 554 | 524 | } |
| 555 | 525 | |
| @@ -564,9 +534,8 @@ | ||
| 564 | 534 | continue; |
| 565 | 535 | } |
| 566 | 536 | |
| 567 | 537 | $folder = $plugin->plugin; |
| 568 | - | |
| 569 | 538 | if ( empty( $folder ) ) { |
| 570 | 539 | continue; |
| 571 | 540 | } |
| 572 | 541 | |
| @@ -574,10 +543,10 @@ | ||
| 574 | 543 | // don't show an update if the plugin isn't installed |
| 575 | 544 | continue; |
| 576 | 545 | } |
| 577 | 546 | |
| 578 | - $wp_plugin = $wp_plugins[ $folder ] ?? array(); | |
| 579 | - $wp_version = $wp_plugin['Version'] ?? '1.0'; | |
| 547 | + $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array(); | |
| 548 | + $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0'; | |
| 580 | 549 | $plugin->slug = explode( '/', $folder )[0]; |
| 581 | 550 | |
| 582 | 551 | if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) { |
| 583 | 552 | $transient->response[ $folder ] = $plugin; |
| @@ -597,9 +566,8 @@ | ||
| 597 | 566 | * Because this gets called on "pre_set_site_transient_update_plugins" an old version of FrmAppHelper may be loaded on plugin update. |
| 598 | 567 | * This means that trying to access FrmAppHelper::get_plugins when upgrading from a Lite version before v5.5 results in a one-off error. |
| 599 | 568 | * |
| 600 | 569 | * @since 5.5.2 |
| 601 | - * | |
| 602 | 570 | * @return array |
| 603 | 571 | */ |
| 604 | 572 | protected static function get_plugins() { |
| 605 | 573 | if ( ! function_exists( 'get_plugins' ) ) { |
| @@ -639,9 +607,8 @@ | ||
| 639 | 607 | continue; |
| 640 | 608 | } |
| 641 | 609 | |
| 642 | 610 | $new_license = $addon->license; |
| 643 | - | |
| 644 | 611 | if ( empty( $new_license ) || in_array( $new_license, $checked_licenses ) ) { |
| 645 | 612 | continue; |
| 646 | 613 | } |
| 647 | 614 | |
| @@ -647,9 +614,8 @@ | ||
| 647 | 614 | |
| 648 | 615 | $checked_licenses[] = $new_license; |
| 649 | 616 | |
| 650 | 617 | $api = new FrmFormApi( $new_license ); |
| 651 | - | |
| 652 | 618 | if ( empty( $version_info ) ) { |
| 653 | 619 | $version_info = $api->get_api_info(); |
| 654 | 620 | continue; |
| 655 | 621 | } |
| @@ -654,21 +620,18 @@ | ||
| 654 | 620 | continue; |
| 655 | 621 | } |
| 656 | 622 | |
| 657 | 623 | $plugin = $api->get_addon_for_license( $addon, $version_info ); |
| 658 | - | |
| 659 | 624 | if ( empty( $plugin ) ) { |
| 660 | 625 | continue; |
| 661 | 626 | } |
| 662 | 627 | |
| 663 | - $download_id = $plugin['id'] ?? 0; | |
| 664 | - | |
| 628 | + $download_id = isset( $plugin['id'] ) ? $plugin['id'] : 0; | |
| 665 | 629 | if ( ! empty( $download_id ) && ! isset( $version_info[ $download_id ]['package'] ) ) { |
| 666 | 630 | // if this addon is using its own license, get the update url |
| 667 | 631 | $addon_info = $api->get_api_info(); |
| 668 | 632 | |
| 669 | 633 | $version_info[ $download_id ] = $addon_info[ $download_id ]; |
| 670 | - | |
| 671 | 634 | if ( isset( $addon_info['error'] ) ) { |
| 672 | 635 | $version_info[ $download_id ]['error'] = array( |
| 673 | 636 | 'message' => $addon_info['error']['message'], |
| 674 | 637 | 'code' => $addon_info['error']['code'], |
| @@ -683,11 +646,9 @@ | ||
| 683 | 646 | /** |
| 684 | 647 | * Get the action link for an addon that isn't active. |
| 685 | 648 | * |
| 686 | 649 | * @since 3.06.03 |
| 687 | - * | |
| 688 | 650 | * @param string $plugin The plugin slug. |
| 689 | - * | |
| 690 | 651 | * @return array |
| 691 | 652 | */ |
| 692 | 653 | public static function install_link( $plugin ) { |
| 693 | 654 | $link = array(); |
| @@ -724,20 +685,16 @@ | ||
| 724 | 685 | } |
| 725 | 686 | |
| 726 | 687 | /** |
| 727 | 688 | * @since 4.09 |
| 728 | - * | |
| 729 | 689 | * @param string $plugin The plugin slug. |
| 730 | - * | |
| 731 | 690 | * @return array|false |
| 732 | 691 | */ |
| 733 | 692 | public static function get_addon( $plugin ) { |
| 734 | 693 | $addons = self::get_api_addons(); |
| 735 | 694 | self::prepare_addons( $addons ); |
| 736 | - | |
| 737 | 695 | foreach ( $addons as $addon ) { |
| 738 | 696 | $slug = explode( '/', $addon['plugin'] ); |
| 739 | - | |
| 740 | 697 | if ( $slug[0] === 'formidable-' . $plugin ) { |
| 741 | 698 | return $addon; |
| 742 | 699 | } |
| 743 | 700 | } |
| @@ -745,15 +702,13 @@ | ||
| 745 | 702 | } |
| 746 | 703 | |
| 747 | 704 | /** |
| 748 | 705 | * @since 4.09 |
| 749 | - * | |
| 750 | 706 | * @return string |
| 751 | 707 | */ |
| 752 | 708 | protected static function get_license_type() { |
| 753 | 709 | $license_type = ''; |
| 754 | 710 | $addons = self::get_api_addons(); |
| 755 | - | |
| 756 | 711 | if ( isset( $addons['error'] ) && isset( $addons['error']['type'] ) ) { |
| 757 | 712 | $license_type = $addons['error']['type']; |
| 758 | 713 | } |
| 759 | 714 | return $license_type; |
| @@ -769,9 +724,8 @@ | ||
| 769 | 724 | */ |
| 770 | 725 | public static function get_addon_for_license( $addons, $license ) { |
| 771 | 726 | $download_id = $license->download_id; |
| 772 | 727 | $plugin = array(); |
| 773 | - | |
| 774 | 728 | if ( empty( $download_id ) && ! empty( $addons ) ) { |
| 775 | 729 | foreach ( $addons as $addon ) { |
| 776 | 730 | if ( strtolower( $license->plugin_name ) === strtolower( $addon['title'] ) ) { |
| 777 | 731 | return $addon; |
| @@ -784,21 +738,17 @@ | ||
| 784 | 738 | return $plugin; |
| 785 | 739 | } |
| 786 | 740 | |
| 787 | 741 | /** |
| 788 | - * @param array $addons | |
| 789 | - * | |
| 790 | 742 | * @return void |
| 791 | 743 | */ |
| 792 | 744 | protected static function prepare_addons( &$addons ) { |
| 793 | 745 | $activate_url = ''; |
| 794 | - | |
| 795 | 746 | if ( current_user_can( 'activate_plugins' ) ) { |
| 796 | 747 | $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) ); |
| 797 | 748 | } |
| 798 | 749 | |
| 799 | 750 | $loop_addons = $addons; |
| 800 | - | |
| 801 | 751 | foreach ( $loop_addons as $id => $addon ) { |
| 802 | 752 | if ( is_numeric( $id ) ) { |
| 803 | 753 | $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] ); |
| 804 | 754 | $file_name = $addon['plugin']; |
| @@ -803,17 +753,14 @@ | ||
| 803 | 753 | $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] ); |
| 804 | 754 | $file_name = $addon['plugin']; |
| 805 | 755 | } else { |
| 806 | 756 | $slug = $id; |
| 807 | - | |
| 808 | 757 | if ( isset( $addon['file'] ) ) { |
| 809 | 758 | $base_file = $addon['file']; |
| 810 | 759 | } else { |
| 811 | 760 | $base_file = 'formidable-' . $slug; |
| 812 | 761 | } |
| 813 | - | |
| 814 | 762 | $file_name = $base_file . '/' . $base_file . '.php'; |
| 815 | - | |
| 816 | 763 | if ( ! isset( $addon['plugin'] ) ) { |
| 817 | 764 | $addon['plugin'] = $file_name; |
| 818 | 765 | } |
| 819 | 766 | } |
| @@ -818,12 +765,10 @@ | ||
| 818 | 765 | } |
| 819 | 766 | } |
| 820 | 767 | |
| 821 | 768 | $addon['installed'] = self::is_installed( $file_name ); |
| 822 | - | |
| 823 | 769 | if ( $addon['installed'] && 'formidable-views/formidable-views.php' === $file_name ) { |
| 824 | 770 | $active_views_version = self::get_active_views_version(); |
| 825 | - | |
| 826 | 771 | if ( false !== $active_views_version && $slug !== $active_views_version ) { |
| 827 | 772 | $addon['installed'] = false; |
| 828 | 773 | } |
| 829 | 774 | } |
| @@ -857,11 +802,8 @@ | ||
| 857 | 802 | }//end foreach |
| 858 | 803 | } |
| 859 | 804 | |
| 860 | 805 | /** |
| 861 | - * @param string $file_name | |
| 862 | - * @param string $slug | |
| 863 | - * | |
| 864 | 806 | * @return bool |
| 865 | 807 | */ |
| 866 | 808 | private static function is_plugin_active( $file_name, $slug ) { |
| 867 | 809 | if ( 'formidable-views/formidable-views.php' === $file_name ) { |
| @@ -876,9 +818,8 @@ | ||
| 876 | 818 | private static function get_active_views_version() { |
| 877 | 819 | if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) { |
| 878 | 820 | return false; |
| 879 | 821 | } |
| 880 | - | |
| 881 | 822 | $plugin_version = FrmViewsAppHelper::plugin_version(); |
| 882 | 823 | return version_compare( $plugin_version, '5.0', '>=' ) ? 'visual-views' : 'views'; |
| 883 | 824 | } |
| 884 | 825 | |
| @@ -884,25 +825,22 @@ | ||
| 884 | 825 | |
| 885 | 826 | /** |
| 886 | 827 | * @since 3.04.02 |
| 887 | 828 | * |
| 888 | - * @param string $link | |
| 889 | - * | |
| 890 | 829 | * @return void |
| 891 | 830 | */ |
| 892 | 831 | protected static function prepare_addon_link( &$link ) { |
| 893 | 832 | $site_url = 'https://formidableforms.com/'; |
| 894 | - | |
| 895 | 833 | if ( strpos( $link, 'http' ) !== 0 ) { |
| 896 | 834 | $link = $site_url . $link; |
| 897 | 835 | } |
| 898 | - | |
| 899 | 836 | $link = FrmAppHelper::make_affiliate_url( $link ); |
| 900 | - | |
| 901 | - $utm = array( | |
| 902 | - 'campaign' => 'addons', | |
| 837 | + $query_args = array( | |
| 838 | + 'utm_source' => 'WordPress', | |
| 839 | + 'utm_medium' => 'addons', | |
| 840 | + 'utm_campaign' => 'liteplugin', | |
| 903 | 841 | ); |
| 904 | - $link = FrmAppHelper::maybe_add_missing_utm( $link, $utm ); | |
| 842 | + $link = add_query_arg( $query_args, $link ); | |
| 905 | 843 | } |
| 906 | 844 | |
| 907 | 845 | /** |
| 908 | 846 | * Add the status to the addon array. Status options are: |
| @@ -909,10 +847,8 @@ | ||
| 909 | 847 | * installed, active, not installed |
| 910 | 848 | * |
| 911 | 849 | * @since 3.04.02 |
| 912 | 850 | * |
| 913 | - * @param array $addon | |
| 914 | - * | |
| 915 | 851 | * @return void |
| 916 | 852 | */ |
| 917 | 853 | protected static function set_addon_status( &$addon ) { |
| 918 | 854 | if ( ! empty( $addon['activate_url'] ) ) { |
| @@ -939,9 +875,8 @@ | ||
| 939 | 875 | * @param string $plugin |
| 940 | 876 | * @param string $redirect |
| 941 | 877 | * @param bool $network_wide |
| 942 | 878 | * @param bool $silent |
| 943 | - * | |
| 944 | 879 | * @return WP_Error|null Null on success, WP_Error on invalid file. |
| 945 | 880 | */ |
| 946 | 881 | protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) { |
| 947 | 882 | if ( ! function_exists( 'activate_plugin' ) ) { |
| @@ -956,9 +891,8 @@ | ||
| 956 | 891 | * @since 6.8 |
| 957 | 892 | * |
| 958 | 893 | * @param string $plugin |
| 959 | 894 | * @param bool $silent |
| 960 | - * | |
| 961 | 895 | * @return void |
| 962 | 896 | */ |
| 963 | 897 | protected static function deactivate_plugin( $plugin, $silent = false ) { |
| 964 | 898 | if ( ! function_exists( 'deactivate_plugins' ) ) { |
| @@ -972,9 +906,8 @@ | ||
| 972 | 906 | * |
| 973 | 907 | * @since 6.8 |
| 974 | 908 | * |
| 975 | 909 | * @param string $plugin |
| 976 | - * | |
| 977 | 910 | * @return true|WP_Error True on success, WP_Error on invalid file. |
| 978 | 911 | */ |
| 979 | 912 | protected static function uninstall_plugin( $plugin ) { |
| 980 | 913 | if ( ! current_user_can( 'delete_plugins' ) ) { |
| @@ -1019,9 +952,8 @@ | ||
| 1019 | 952 | |
| 1020 | 953 | self::maybe_show_cred_form(); |
| 1021 | 954 | |
| 1022 | 955 | $installed = self::install_addon(); |
| 1023 | - | |
| 1024 | 956 | if ( is_array( $installed ) && isset( $installed['message'] ) ) { |
| 1025 | 957 | return $installed; |
| 1026 | 958 | } |
| 1027 | 959 | self::handle_addon_action( $installed, 'activate' ); |
| @@ -1036,9 +968,9 @@ | ||
| 1036 | 968 | if ( ! function_exists( 'request_filesystem_credentials' ) ) { |
| 1037 | 969 | include_once ABSPATH . 'wp-admin/includes/file.php'; |
| 1038 | 970 | } |
| 1039 | 971 | |
| 1040 | - // Start output buffering to catch the filesystem form if credentials are needed. | |
| 972 | + // Start output bufferring to catch the filesystem form if credentials are needed. | |
| 1041 | 973 | ob_start(); |
| 1042 | 974 | |
| 1043 | 975 | $show_form = false; |
| 1044 | 976 | $method = ''; |
| @@ -1085,10 +1017,8 @@ | ||
| 1085 | 1017 | * We do not need any extra credentials if we have gotten this far, |
| 1086 | 1018 | * so let's install the plugin. |
| 1087 | 1019 | * |
| 1088 | 1020 | * @since 3.04.02 |
| 1089 | - * | |
| 1090 | - * @return array|string | |
| 1091 | 1021 | */ |
| 1092 | 1022 | protected static function install_addon() { |
| 1093 | 1023 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 1094 | 1024 | |
| @@ -1108,9 +1038,8 @@ | ||
| 1108 | 1038 | // Flush the cache and return the newly installed plugin basename. |
| 1109 | 1039 | wp_cache_flush(); |
| 1110 | 1040 | |
| 1111 | 1041 | $plugin = $installer->plugin_info(); |
| 1112 | - | |
| 1113 | 1042 | if ( ! $plugin ) { |
| 1114 | 1043 | return array( |
| 1115 | 1044 | 'message' => 'Plugin was not installed. ' . $installer->result, |
| 1116 | 1045 | 'success' => false, |
| @@ -1180,9 +1109,8 @@ | ||
| 1180 | 1109 | * @since 6.8 |
| 1181 | 1110 | * |
| 1182 | 1111 | * @param callable $action_callback The specific add-on action to be executed. |
| 1183 | 1112 | * @param callable|null $response_callback Optional. The response handling callback. Default null. |
| 1184 | - * | |
| 1185 | 1113 | * @return void |
| 1186 | 1114 | */ |
| 1187 | 1115 | private static function process_addon_action( $action_callback, $response_callback = null ) { |
| 1188 | 1116 | self::install_addon_permissions(); |
| @@ -1205,9 +1133,8 @@ | ||
| 1205 | 1133 | * @since 6.8 |
| 1206 | 1134 | * |
| 1207 | 1135 | * @param string $installed The plugin folder name with file name. |
| 1208 | 1136 | * @param string $action The action type ('activate', 'deactivate', 'uninstall'). |
| 1209 | - * | |
| 1210 | 1137 | * @return array|void |
| 1211 | 1138 | */ |
| 1212 | 1139 | protected static function handle_addon_action( $installed, $action ) { |
| 1213 | 1140 | if ( ! $installed || ! $action ) { |
| @@ -1266,9 +1193,8 @@ | ||
| 1266 | 1193 | * @return string |
| 1267 | 1194 | */ |
| 1268 | 1195 | private static function get_activating_page() { |
| 1269 | 1196 | $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' ); |
| 1270 | - | |
| 1271 | 1197 | if ( false !== strpos( $referer, 'frm_action=settings' ) ) { |
| 1272 | 1198 | return 'settings'; |
| 1273 | 1199 | } |
| 1274 | 1200 | |
| @@ -1301,14 +1227,12 @@ | ||
| 1301 | 1227 | * @return string |
| 1302 | 1228 | */ |
| 1303 | 1229 | public static function connect_link() { |
| 1304 | 1230 | $auth = get_option( 'frm_connect_token' ); |
| 1305 | - | |
| 1306 | 1231 | if ( empty( $auth ) ) { |
| 1307 | 1232 | $auth = hash( 'sha512', wp_rand() ); |
| 1308 | 1233 | update_option( 'frm_connect_token', $auth, 'no' ); |
| 1309 | 1234 | } |
| 1310 | - | |
| 1311 | 1235 | $page = FrmAppHelper::simple_get( 'page', 'sanitize_title', 'formidable-settings' ); |
| 1312 | 1236 | $link = 'https://formidableforms.com/api-connect/'; |
| 1313 | 1237 | $args = array( |
| 1314 | 1238 | 'v' => 2, |
| @@ -1337,9 +1261,8 @@ | ||
| 1337 | 1261 | |
| 1338 | 1262 | // The download link is not required if already installed. |
| 1339 | 1263 | $is_installed = FrmAppHelper::pro_is_included(); |
| 1340 | 1264 | $file_missing = ! $is_installed && empty( $post_url ); |
| 1341 | - | |
| 1342 | 1265 | if ( ! $post_auth || $file_missing ) { |
| 1343 | 1266 | return false; |
| 1344 | 1267 | } |
| 1345 | 1268 | |
| @@ -1344,9 +1267,8 @@ | ||
| 1344 | 1267 | } |
| 1345 | 1268 | |
| 1346 | 1269 | // Verify auth. |
| 1347 | 1270 | $auth = get_option( 'frm_connect_token' ); |
| 1348 | - | |
| 1349 | 1271 | if ( empty( $auth ) || ! hash_equals( $auth, $post_auth ) ) { |
| 1350 | 1272 | return false; |
| 1351 | 1273 | } |
| 1352 | 1274 | |
| @@ -1362,17 +1284,17 @@ | ||
| 1362 | 1284 | */ |
| 1363 | 1285 | public static function install_addon_api() { |
| 1364 | 1286 | self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' ); |
| 1365 | 1287 | |
| 1288 | + $error = esc_html__( 'Could not install an upgrade. Please download from formidableforms.com and install manually.', 'formidable' ); | |
| 1289 | + | |
| 1366 | 1290 | // Delete so cannot replay. |
| 1367 | 1291 | delete_option( 'frm_connect_token' ); |
| 1368 | 1292 | |
| 1369 | 1293 | // It's already installed and active. |
| 1370 | 1294 | $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true ); |
| 1371 | - | |
| 1372 | 1295 | if ( is_wp_error( $active ) ) { |
| 1373 | 1296 | $response = self::maybe_download_and_activate(); |
| 1374 | - | |
| 1375 | 1297 | if ( is_array( $response ) ) { |
| 1376 | 1298 | // The download failed. |
| 1377 | 1299 | return $response; |
| 1378 | 1300 | } |
| @@ -1381,9 +1303,8 @@ | ||
| 1381 | 1303 | // If empty license, save it now. |
| 1382 | 1304 | if ( empty( self::get_pro_license() ) && function_exists( 'load_formidable_pro' ) ) { |
| 1383 | 1305 | load_formidable_pro(); |
| 1384 | 1306 | $license = stripslashes( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) ); |
| 1385 | - | |
| 1386 | 1307 | if ( ! $license ) { |
| 1387 | 1308 | return array( |
| 1388 | 1309 | 'success' => false, |
| 1389 | 1310 | 'error' => 'That site does not have a valid license key.', |
| @@ -1390,9 +1311,8 @@ | ||
| 1390 | 1311 | ); |
| 1391 | 1312 | } |
| 1392 | 1313 | |
| 1393 | 1314 | $response = FrmAddon::activate_license_for_plugin( $license, 'formidable_pro' ); |
| 1394 | - | |
| 1395 | 1315 | if ( ! $response['success'] ) { |
| 1396 | 1316 | // Could not activate license. |
| 1397 | 1317 | return $response; |
| 1398 | 1318 | } |
| @@ -1417,9 +1337,8 @@ | ||
| 1417 | 1337 | } |
| 1418 | 1338 | |
| 1419 | 1339 | // Download plugin now. |
| 1420 | 1340 | $response = self::download_and_activate(); |
| 1421 | - | |
| 1422 | 1341 | if ( is_array( $response ) && isset( $response['success'] ) ) { |
| 1423 | 1342 | // The download failed. |
| 1424 | 1343 | return $response; |
| 1425 | 1344 | } |
| @@ -1433,9 +1352,8 @@ | ||
| 1433 | 1352 | * @since 4.09 |
| 1434 | 1353 | * |
| 1435 | 1354 | * @param string $plugin |
| 1436 | 1355 | * @param array|string $upgrade_link_args |
| 1437 | - * | |
| 1438 | 1356 | * @return void |
| 1439 | 1357 | */ |
| 1440 | 1358 | public static function conditional_action_button( $plugin, $upgrade_link_args ) { |
| 1441 | 1359 | if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) { |
| @@ -1470,9 +1388,8 @@ | ||
| 1470 | 1388 | * @type false|string $license_type |
| 1471 | 1389 | * @type string $plan_required |
| 1472 | 1390 | * @type string $upgrade_link |
| 1473 | 1391 | * } |
| 1474 | - * | |
| 1475 | 1392 | * @return void |
| 1476 | 1393 | */ |
| 1477 | 1394 | public static function show_conditional_action_button( $atts ) { |
| 1478 | 1395 | if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) { |
| @@ -1493,9 +1410,8 @@ | ||
| 1493 | 1410 | */ |
| 1494 | 1411 | public static function addon_upgrade_link( $addon, $upgrade_link ) { |
| 1495 | 1412 | $atts = is_array( $upgrade_link ) ? $upgrade_link : array(); |
| 1496 | 1413 | $upgrade_link = is_array( $upgrade_link ) ? $upgrade_link['link'] : $upgrade_link; |
| 1497 | - $text = ! empty( $atts['text'] ) ? $atts['text'] : __( 'Upgrade Now', 'formidable' ); | |
| 1498 | 1414 | |
| 1499 | 1415 | if ( $addon ) { |
| 1500 | 1416 | $upgrade_link .= '&utm_content=' . $addon['slug']; |
| 1501 | 1417 | } |
| @@ -1505,15 +1421,14 @@ | ||
| 1505 | 1421 | $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] ); |
| 1506 | 1422 | } |
| 1507 | 1423 | |
| 1508 | 1424 | $class = ! empty( $atts['class'] ) ? $atts['class'] : ''; |
| 1509 | - | |
| 1510 | 1425 | if ( strpos( $class, 'frm-button' ) === false ) { |
| 1511 | 1426 | $class .= ' frm-button-secondary frm-button-sm'; |
| 1512 | 1427 | } |
| 1513 | 1428 | ?> |
| 1514 | 1429 | <a class="install-now button <?php echo esc_attr( $class ); ?>" href="<?php echo esc_url( $upgrade_link ); ?>" target="_blank" rel="noopener" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>"> |
| 1515 | - <?php echo esc_html( $text ); ?> | |
| 1430 | + <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?> | |
| 1516 | 1431 | </a> |
| 1517 | 1432 | <?php |
| 1518 | 1433 | } |
| 1519 | 1434 | |
| @@ -1525,9 +1440,8 @@ | ||
| 1525 | 1440 | public static function ajax_install_addon() { |
| 1526 | 1441 | self::install_addon_permissions(); |
| 1527 | 1442 | |
| 1528 | 1443 | $result = self::download_and_activate(); |
| 1529 | - | |
| 1530 | 1444 | if ( isset( $result['success'] ) && ! $result['success'] ) { |
| 1531 | 1445 | echo json_encode( $result ); |
| 1532 | 1446 | wp_die(); |
| 1533 | 1447 | } |
| @@ -1571,10 +1485,8 @@ | ||
| 1571 | 1485 | /** |
| 1572 | 1486 | * Gets required plan for an addon. |
| 1573 | 1487 | * |
| 1574 | 1488 | * @since 6.4.2 |
| 1575 | - * | |
| 1576 | - * @param int|string $addon_id | |
| 1577 | 1489 | * |
| 1578 | 1490 | * @return string Empty string if no plan is required for active license. |
| 1579 | 1491 | */ |
| 1580 | 1492 | public static function get_addon_required_plan( $addon_id ) { |