PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.11
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.11
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/controllers/FrmAddonsController.php +319 -213 6.46.11 View file →
@@ -5,9 +5,9 @@
5 5
6 6 class FrmAddonsController {
7 7
8 8 /**
9 - * @var string $plugin
9 + * @var string
10 10 */
11 11 protected static $plugin;
12 12
13 13 /**
@@ -18,12 +18,15 @@
18 18 return;
19 19 }
20 20
21 21 $label = __( 'Add-Ons', 'formidable' );
22 - $label = '<span style="color:#fe5a1d">' . $label . '</span>';
22 + $label = '<span style="color:#1da867">' . $label . '</span>';
23 23
24 24 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), $label, 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' );
25 25
26 + // remove default created subpage, make the page with highest priority as default.
27 + remove_submenu_page( 'formidable', 'formidable' );
28 +
26 29 if ( ! FrmAppHelper::pro_is_installed() ) {
27 30 add_submenu_page(
28 31 'formidable',
29 32 'Formidable | ' . __( 'Upgrade', 'formidable' ),
@@ -49,15 +52,15 @@
49 52 $addons = self::get_api_addons();
50 53 $errors = array();
51 54
52 55 if ( isset( $addons['error'] ) ) {
53 - $api = new FrmFormApi();
54 - $errors = $api->get_error_from_response( $addons );
56 + $api = new FrmFormApi();
57 + $errors = $api->get_error_from_response( $addons );
55 58 $license_type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : '';
56 59 unset( $addons['error'] );
57 60 }
58 61
59 - $pro = array(
62 + $pro = array(
60 63 'pro' => array(
61 64 'title' => 'Formidable Forms Pro',
62 65 'slug' => 'formidable-pro',
63 66 'released' => '2011-02-05',
@@ -69,9 +72,9 @@
69 72 self::prepare_addons( $addons );
70 73
71 74 $pricing = FrmAppHelper::admin_upgrade_link( 'addons' );
72 75
73 - include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' );
76 + include FrmAppHelper::plugin_path() . '/classes/views/addons/list.php';
74 77 }
75 78
76 79 /**
77 80 * @return void
@@ -85,9 +88,9 @@
85 88 }
86 89
87 90 ksort( $plugins );
88 91
89 - include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' );
92 + include FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php';
90 93 }
91 94
92 95 /**
93 96 * @return array
@@ -109,8 +112,21 @@
109 112 return $addons;
110 113 }
111 114
112 115 /**
116 + * Retrieves the count of available addons.
117 + *
118 + * @since 6.9
119 + *
120 + * @return int Count of addons.
121 + */
122 + public static function get_addons_count() {
123 + $addons = self::get_api_addons();
124 +
125 + return count( $addons );
126 + }
127 +
128 + /**
113 129 * If the API is unable to connect, show something on the addons page
114 130 *
115 131 * @since 3.04.03
116 132 * @return array
@@ -272,8 +288,10 @@
272 288 }
273 289
274 290 /**
275 291 * @since 4.0.01
292 + *
293 + * @return bool
276 294 */
277 295 public static function is_license_expired() {
278 296 $version_info = self::get_primary_license_info();
279 297 if ( ! isset( $version_info['error'] ) ) {
@@ -279,8 +297,19 @@
279 297 if ( ! isset( $version_info['error'] ) ) {
280 298 return false;
281 299 }
282 300
301 + $expires = isset( $version_info['error']['expires'] ) ? $version_info['error']['expires'] : 0;
302 + if ( empty( $expires ) || $expires > time() ) {
303 + return false;
304 + }
305 +
306 + $rate_limited = ! empty( $version_info['response_code'] ) && 429 === (int) $version_info['response_code'];
307 + if ( $rate_limited ) {
308 + // Do not return false positives for rate limited responses.
309 + return false;
310 + }
311 +
283 312 return $version_info['error'];
284 313 }
285 314
286 315 /**
@@ -285,9 +314,9 @@
285 314
286 315 /**
287 316 * @since 4.08
288 317 *
289 - * @return boolean|int false or the number of days until expiration.
318 + * @return bool|int false or the number of days until expiration.
290 319 */
291 320 public static function is_license_expiring() {
292 321 if ( is_callable( 'FrmProAddonsController::is_license_expiring' ) ) {
293 322 return FrmProAddonsController::is_license_expiring();
@@ -297,12 +326,13 @@
297 326 }
298 327
299 328 /**
300 329 * @since 4.08
330 + * @since 6.7 This is public.
301 331 *
302 332 * @return array|false
303 333 */
304 - protected static function get_primary_license_info() {
334 + public static function get_primary_license_info() {
305 335 $installed_addons = apply_filters( 'frm_installed_addons', array() );
306 336 if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) {
307 337 return false;
308 338 }
@@ -334,9 +364,9 @@
334 364 $version_info = self::fill_update_addon_info( $installed_addons );
335 365 $transient->last_checked = time();
336 366 $wp_plugins = self::get_plugins();
337 367
338 - foreach ( $version_info as $id => $plugin ) {
368 + foreach ( $version_info as $plugin ) {
339 369 $plugin = (object) $plugin;
340 370
341 371 if ( ! isset( $plugin->new_version ) || ! isset( $plugin->package ) ) {
342 372 continue;
@@ -351,20 +381,21 @@
351 381 // don't show an update if the plugin isn't installed
352 382 continue;
353 383 }
354 384
355 - $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array();
356 - $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0';
385 + $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array();
386 + $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0';
387 + $plugin->slug = explode( '/', $folder )[0];
357 388
358 389 if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) {
359 - $slug = explode( '/', $folder );
360 - $plugin->slug = $slug[0];
361 390 $transient->response[ $folder ] = $plugin;
391 + } else {
392 + $transient->no_update[ $folder ] = $plugin;
362 393 }
363 394
364 395 $transient->checked[ $folder ] = $wp_version;
365 396
366 - }
397 + }//end foreach
367 398
368 399 return $transient;
369 400 }
370 401
@@ -387,9 +418,9 @@
387 418 * Check if a plugin is installed before showing an update for it
388 419 *
389 420 * @since 3.05
390 421 *
391 - * @param string $plugin - the folder/filename.php for a plugin
422 + * @param string $plugin The folder/filename.php for a plugin.
392 423 *
393 424 * @return bool - True if installed
394 425 */
395 426 protected static function is_installed( $plugin ) {
@@ -444,9 +475,9 @@
444 475 'code' => $addon_info['error']['code'],
445 476 );
446 477 }
447 478 }
448 - }
479 + }//end foreach
449 480
450 481 return $version_info;
451 482 }
452 483
@@ -453,9 +484,9 @@
453 484 /**
454 485 * Get the action link for an addon that isn't active.
455 486 *
456 487 * @since 3.06.03
457 - * @param string $plugin The plugin slug
488 + * @param string $plugin The plugin slug.
458 489 * @return array
459 490 */
460 491 public static function install_link( $plugin ) {
461 492 $link = array();
@@ -466,14 +497,14 @@
466 497 $link = array(
467 498 'url' => $addon['plugin'],
468 499 'class' => 'frm-activate-addon',
469 500 );
470 - } elseif ( isset( $addon['url'] ) && ! empty( $addon['url'] ) ) {
501 + } elseif ( ! empty( $addon['url'] ) ) {
471 502 $link = array(
472 503 'url' => $addon['url'],
473 504 'class' => 'frm-install-addon',
474 505 );
475 - } elseif ( isset( $addon['categories'] ) && ! empty( $addon['categories'] ) ) {
506 + } elseif ( ! empty( $addon['categories'] ) ) {
476 507 $link = array(
477 508 'categories' => $addon['categories'],
478 509 );
479 510 }
@@ -485,9 +516,9 @@
485 516 $link = array(
486 517 'url' => 'formidable-' . $plugin . '/formidable-' . $plugin . '.php',
487 518 'class' => 'frm-activate-addon',
488 519 );
489 - }
520 + }//end if
490 521
491 522 return $link;
492 523 }
493 524
@@ -492,12 +523,12 @@
492 523 }
493 524
494 525 /**
495 526 * @since 4.09
496 - * @param string $plugin The plugin slug
527 + * @param string $plugin The plugin slug.
497 528 * @return array|false
498 529 */
499 - protected static function get_addon( $plugin ) {
530 + public static function get_addon( $plugin ) {
500 531 $addons = self::get_api_addons();
501 532 self::prepare_addons( $addons );
502 533 foreach ( $addons as $addon ) {
503 534 $slug = explode( '/', $addon['plugin'] );
@@ -523,10 +554,10 @@
523 554
524 555 /**
525 556 * @since 3.04.03
526 557 *
527 - * @param array $addons
528 - * @param object $license The FrmAddon object
558 + * @param array $addons
559 + * @param object $license The FrmAddon object.
529 560 *
530 561 * @return array
531 562 */
532 563 public static function get_addon_for_license( $addons, $license ) {
@@ -533,9 +564,9 @@
533 564 $download_id = $license->download_id;
534 565 $plugin = array();
535 566 if ( empty( $download_id ) && ! empty( $addons ) ) {
536 567 foreach ( $addons as $addon ) {
537 - if ( strtolower( $license->plugin_name ) == strtolower( $addon['title'] ) ) {
568 + if ( strtolower( $license->plugin_name ) === strtolower( $addon['title'] ) ) {
538 569 return $addon;
539 570 }
540 571 }
541 572 } elseif ( isset( $addons[ $download_id ] ) ) {
@@ -603,9 +634,9 @@
603 634 self::prepare_addon_link( $addon['link'] );
604 635
605 636 self::set_addon_status( $addon );
606 637 $addons[ $id ] = $addon;
607 - }
638 + }//end foreach
608 639 }
609 640
610 641 /**
611 642 * @return bool
@@ -617,9 +648,9 @@
617 648 return is_plugin_active( $file_name );
618 649 }
619 650
620 651 /**
621 - * @return string|false either 'visual-views' or 'views', false if one is not found.
652 + * @return false|string either 'visual-views' or 'views', false if one is not found.
622 653 */
623 654 private static function get_active_views_version() {
624 655 if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) {
625 656 return false;
@@ -685,9 +716,9 @@
685 716 'content' => 'button',
686 717 );
687 718
688 719 $features = array(
689 - 'Display Entries' => array(
720 + 'Display Entries' => array(
690 721 array(
691 722 'label' => 'Display form data with virtually limitless views',
692 723 'link' => array(
693 724 'content' => 'views',
@@ -737,9 +768,9 @@
737 768 'label' => 'Export your entries to a CSV',
738 769 'lite' => true,
739 770 ),
740 771 ),
741 - 'Form Building' => array(
772 + 'Form Building' => array(
742 773 array(
743 774 'label' => 'Save a calculated value into a field',
744 775 'link' => array(
745 776 'content' => 'calculations',
@@ -823,9 +854,9 @@
823 854 'label' => 'Use input placeholder text in your fields that clear when typing starts.',
824 855 'lite' => true,
825 856 ),
826 857 ),
827 - 'Form Actions' => array(
858 + 'Form Actions' => array(
828 859 array(
829 860 'label' => 'Conditionally send your email notifications based on values in your form',
830 861 'link' => array(
831 862 'content' => 'conditional-emails',
@@ -848,9 +879,9 @@
848 879 ),
849 880 'lite' => true,
850 881 ),
851 882 ),
852 - 'Form Appearance' => array(
883 + 'Form Appearance' => array(
853 884 array(
854 885 'label' => 'Create Multiple styles for different forms',
855 886 'link' => array(
856 887 'content' => 'multiple-styles',
@@ -880,57 +911,68 @@
880 911 ),
881 912 ),
882 913 );
883 914
884 - include( FrmAppHelper::plugin_path() . '/classes/views/addons/upgrade_to_pro.php' );
915 + include FrmAppHelper::plugin_path() . '/classes/views/addons/upgrade_to_pro.php';
885 916 }
886 917
887 918 /**
888 - * Install Pro after connection with Formidable.
919 + * @since 5.5.2
889 920 *
890 - * @since 4.02.05
921 + * @param string $plugin
922 + * @param string $redirect
923 + * @param bool $network_wide
924 + * @param bool $silent
925 + * @return WP_Error|null Null on success, WP_Error on invalid file.
926 + */
927 + protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
928 + if ( ! function_exists( 'activate_plugin' ) ) {
929 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
930 + }
931 + return activate_plugin( $plugin, $redirect, $network_wide, $silent );
932 + }
933 +
934 + /**
935 + * Deactivate a specified plugin.
891 936 *
937 + * @since 6.8
938 + *
939 + * @param string $plugin
940 + * @param bool $silent
892 941 * @return void
893 942 */
894 - public static function connect_pro() {
895 - FrmAppHelper::permission_check( 'install_plugins' );
896 - check_ajax_referer( 'frm_ajax', 'nonce' );
897 -
898 - $url = self::get_current_plugin();
899 - if ( FrmAppHelper::pro_is_installed() || empty( $url ) ) {
900 - wp_die();
943 + protected static function deactivate_plugin( $plugin, $silent = false ) {
944 + if ( ! function_exists( 'deactivate_plugins' ) ) {
945 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
901 946 }
902 -
903 - $response = array();
904 -
905 - // It's already installed and active.
906 - $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
907 - if ( is_wp_error( $active ) ) {
908 - // The plugin was installed, but not active. Download it now.
909 - self::ajax_install_addon();
910 - } else {
911 - $response['active'] = true;
912 - $response['success'] = true;
913 - }
914 -
915 - echo json_encode( $response );
916 - wp_die();
947 + deactivate_plugins( $plugin, $silent );
917 948 }
918 949
919 950 /**
920 - * @since 5.5.2
951 + * Uninstall a specified plugin.
921 952 *
953 + * @since 6.8
954 + *
922 955 * @param string $plugin
923 - * @param string $redirect
924 - * @param bool $network_wide
925 - * @param bool $silent
926 - * @return null|WP_Error Null on success, WP_Error on invalid file.
956 + * @return true|WP_Error True on success, WP_Error on invalid file.
927 957 */
928 - protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
929 - if ( ! function_exists( 'activate_plugin' ) ) {
958 + protected static function uninstall_plugin( $plugin ) {
959 + if ( ! current_user_can( 'delete_plugins' ) ) {
960 + return new WP_Error( 'uninstall_failed', __( 'Current user cannot delete plugins.', 'formidable' ) );
961 + }
962 +
963 + if ( ! function_exists( 'delete_plugins' ) ) {
930 964 require_once ABSPATH . 'wp-admin/includes/plugin.php';
931 965 }
932 - return activate_plugin( $plugin, $redirect, $network_wide, $silent );
966 +
967 + self::deactivate_plugin( $plugin, true );
968 + $result = delete_plugins( array( $plugin ) );
969 +
970 + if ( is_wp_error( $result ) ) {
971 + return $result;
972 + }
973 +
974 + return true;
933 975 }
934 976
935 977 /**
936 978 * @since 5.0.10
@@ -937,9 +979,9 @@
937 979 *
938 980 * @return string
939 981 */
940 982 protected static function get_current_plugin() {
941 - if ( ! isset( self::$plugin ) ) {
983 + if ( empty( self::$plugin ) ) {
942 984 self::$plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' );
943 985 }
944 986 return self::$plugin;
945 987 }
@@ -945,8 +987,10 @@
945 987 }
946 988
947 989 /**
948 990 * @since 4.08
991 + *
992 + * @return array|void
949 993 */
950 994 protected static function download_and_activate() {
951 995 if ( is_admin() ) {
952 996 FrmAppHelper::set_current_screen_and_hook_suffix();
@@ -957,9 +1001,9 @@
957 1001 $installed = self::install_addon();
958 1002 if ( is_array( $installed ) && isset( $installed['message'] ) ) {
959 1003 return $installed;
960 1004 }
961 - self::maybe_activate_addon( $installed );
1005 + self::handle_addon_action( $installed, 'activate' );
962 1006 }
963 1007
964 1008 /**
965 1009 * @since 3.04.02
@@ -967,9 +1011,9 @@
967 1011 * @return void
968 1012 */
969 1013 protected static function maybe_show_cred_form() {
970 1014 if ( ! function_exists( 'request_filesystem_credentials' ) ) {
971 - include_once( ABSPATH . 'wp-admin/includes/file.php' );
1015 + include_once ABSPATH . 'wp-admin/includes/file.php';
972 1016 }
973 1017
974 1018 // Start output bufferring to catch the filesystem form if credentials are needed.
975 1019 ob_start();
@@ -1011,11 +1055,9 @@
1011 1055 *
1012 1056 * @return bool
1013 1057 */
1014 1058 public static function url_is_allowed( $download_url ) {
1015 - return (
1016 - FrmAppHelper::validate_url_is_in_s3_bucket( $download_url, 'zip' ) || in_array( $download_url, self::allowed_external_urls(), true )
1017 - );
1059 + return FrmAppHelper::validate_url_is_in_s3_bucket( $download_url, 'zip' ) || in_array( $download_url, self::allowed_external_urls(), true );
1018 1060 }
1019 1061
1020 1062 /**
1021 1063 * We do not need any extra credentials if we have gotten this far,
@@ -1023,10 +1065,8 @@
1023 1065 *
1024 1066 * @since 3.04.02
1025 1067 */
1026 1068 protected static function install_addon() {
1027 - FrmAppHelper::permission_check( 'install_plugins' );
1028 -
1029 1069 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1030 1070
1031 1071 $download_url = self::get_current_plugin();
1032 1072
@@ -1054,33 +1094,139 @@
1054 1094 return $plugin;
1055 1095 }
1056 1096
1057 1097 /**
1058 - * @since 3.06.03
1098 + * Handle the AJAX request to activate an add-on.
1059 1099 *
1100 + * @since 6.8
1101 + *
1060 1102 * @return void
1061 1103 */
1062 1104 public static function ajax_activate_addon() {
1105 + self::process_addon_action(
1106 + function ( $plugin ) {
1107 + return self::handle_addon_action( $plugin, 'activate' );
1108 + },
1109 + array( 'FrmAddonsController', 'get_addon_activation_response' )
1110 + );
1111 + }
1063 1112
1113 + /**
1114 + * @since 3.04.02
1115 + *
1116 + * @param string $installed The plugin folder name with file name.
1117 + */
1118 + protected static function maybe_activate_addon( $installed ) {
1119 + self::ajax_activate_addon();
1120 + }
1121 +
1122 + /**
1123 + * Handle the AJAX request to deactivate an add-on.
1124 + *
1125 + * @since 6.8
1126 + *
1127 + * @return void
1128 + */
1129 + public static function ajax_deactivate_addon() {
1130 + self::process_addon_action(
1131 + function ( $plugin ) {
1132 + return self::handle_addon_action( $plugin, 'deactivate' );
1133 + }
1134 + );
1135 + }
1136 +
1137 + /**
1138 + * Handle the AJAX request to uninstall an add-on.
1139 + *
1140 + * @since 6.8
1141 + *
1142 + * @return void
1143 + */
1144 + public static function ajax_uninstall_addon() {
1145 + self::process_addon_action(
1146 + function ( $plugin ) {
1147 + return self::handle_addon_action( $plugin, 'uninstall' );
1148 + }
1149 + );
1150 + }
1151 +
1152 + /**
1153 + * Process a specific action (activate, deactivate, uninstall) on an add-on.
1154 + *
1155 + * @since 6.8
1156 + *
1157 + * @param callable $action_callback The specific add-on action to be executed.
1158 + * @param callable|null $response_callback Optional. The response handling callback. Default null.
1159 + * @return void
1160 + */
1161 + private static function process_addon_action( $action_callback, $response_callback = null ) {
1064 1162 self::install_addon_permissions();
1065 -
1066 1163 FrmAppHelper::set_current_screen_and_hook_suffix();
1067 1164
1068 1165 $plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
1069 - self::maybe_activate_addon( $plugin );
1166 + call_user_func( $action_callback, $plugin );
1070 1167
1071 - echo json_encode( self::get_addon_activation_response() );
1072 - wp_die();
1168 + if ( is_callable( $response_callback ) ) {
1169 + wp_send_json_success( call_user_func( $response_callback ) );
1170 + return;
1171 + }
1172 +
1173 + wp_send_json_success();
1073 1174 }
1074 1175
1075 1176 /**
1177 + * Attempt to perform a specific action (activate, deactivate, uninstall) on an add-on.
1178 + *
1179 + * @since 6.8
1180 + *
1181 + * @param string $installed The plugin folder name with file name.
1182 + * @param string $action The action type ('activate', 'deactivate', 'uninstall').
1183 + * @return array|void
1184 + */
1185 + protected static function handle_addon_action( $installed, $action ) {
1186 + if ( ! $installed || ! $action ) {
1187 + return;
1188 + }
1189 +
1190 + $result = null;
1191 + switch ( $action ) {
1192 + case 'activate':
1193 + $result = self::activate_plugin( $installed );
1194 + break;
1195 + case 'deactivate':
1196 + self::deactivate_plugin( $installed );
1197 + break;
1198 + case 'uninstall':
1199 + $result = self::uninstall_plugin( $installed );
1200 + break;
1201 + }
1202 +
1203 + if ( is_wp_error( $result ) ) {
1204 + // Ignore the invalid header message that shows with nested plugins.
1205 + if ( $result->get_error_code() !== 'no_plugin_header' ) {
1206 + if ( wp_doing_ajax() ) {
1207 + wp_send_json_error( array( 'error' => $result->get_error_message() ) );
1208 + }
1209 + return array(
1210 + 'message' => $result->get_error_message(),
1211 + 'success' => false,
1212 + );
1213 + }
1214 + }
1215 +
1216 + return $result;
1217 + }
1218 +
1219 + /**
1076 1220 * @return array
1077 1221 */
1078 1222 private static function get_addon_activation_response() {
1079 1223 $activating_page = self::get_activating_page();
1080 1224
1225 + $message = $activating_page ? __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ) : __( 'Your plugin has been activated.', 'formidable' );
1226 +
1081 1227 $response = array(
1082 - 'message' => __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ),
1228 + 'message' => $message,
1083 1229 'saveAndReload' => $activating_page,
1084 1230 );
1085 1231
1086 1232 return $response;
@@ -1105,34 +1251,8 @@
1105 1251 return '';
1106 1252 }
1107 1253
1108 1254 /**
1109 - * @since 3.04.02
1110 - *
1111 - * @param string $installed The plugin folder name with file name
1112 - */
1113 - protected static function maybe_activate_addon( $installed ) {
1114 - if ( ! $installed ) {
1115 - return;
1116 - }
1117 -
1118 - $activate = self::activate_plugin( $installed );
1119 - if ( is_wp_error( $activate ) ) {
1120 - // Ignore the invalid header message that shows with nested plugins.
1121 - if ( $activate->get_error_code() !== 'no_plugin_header' ) {
1122 - if ( wp_doing_ajax() ) {
1123 - echo json_encode( array( 'error' => $activate->get_error_message() ) );
1124 - wp_die();
1125 - }
1126 - return array(
1127 - 'message' => $activate->get_error_message(),
1128 - 'success' => false,
1129 - );
1130 - }
1131 - }
1132 - }
1133 -
1134 - /**
1135 1255 * Run security checks before installing
1136 1256 *
1137 1257 * @since 3.04.02
1138 1258 *
@@ -1155,15 +1275,18 @@
1155 1275 public static function connect_link() {
1156 1276 $auth = get_option( 'frm_connect_token' );
1157 1277 if ( empty( $auth ) ) {
1158 1278 $auth = hash( 'sha512', wp_rand() );
1159 - update_option( 'frm_connect_token', $auth );
1279 + update_option( 'frm_connect_token', $auth, 'no' );
1160 1280 }
1161 - $link = FrmAppHelper::admin_upgrade_link( 'connect', 'api-connect' );
1281 + $page = FrmAppHelper::simple_get( 'page', 'sanitize_title', 'formidable-settings' );
1282 + $link = 'https://formidableforms.com/api-connect/';
1162 1283 $args = array(
1163 1284 'v' => 2,
1164 1285 'siteurl' => FrmAppHelper::site_url(),
1165 1286 'url' => get_rest_url(),
1287 + 'inst' => (int) FrmAppHelper::pro_is_included(),
1288 + 'return' => $page,
1166 1289 'token' => $auth,
1167 1290 'l' => self::get_pro_license(),
1168 1291 );
1169 1292
@@ -1177,17 +1300,16 @@
1177 1300 *
1178 1301 * @return bool
1179 1302 */
1180 1303 public static function can_install_addon_api() {
1181 - if ( ! current_user_can( 'activate_plugins' ) ) {
1182 - return false;
1183 - }
1184 -
1185 1304 // Verify params present (auth & download link).
1186 1305 $post_auth = FrmAppHelper::get_param( 'token', '', 'request', 'sanitize_text_field' );
1187 1306 $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' );
1188 1307
1189 - if ( empty( $post_auth ) || empty( $post_url ) ) {
1308 + // The download link is not required if already installed.
1309 + $is_installed = FrmAppHelper::pro_is_included();
1310 + $file_missing = ! $is_installed && empty( $post_url );
1311 + if ( ! $post_auth || $file_missing ) {
1190 1312 return false;
1191 1313 }
1192 1314
1193 1315 // Verify auth.
@@ -1202,8 +1324,10 @@
1202 1324 /**
1203 1325 * Install and/or activate the add-on file.
1204 1326 *
1205 1327 * @since 4.08
1328 + *
1329 + * @return array
1206 1330 */
1207 1331 public static function install_addon_api() {
1208 1332 self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' );
1209 1333
@@ -1214,11 +1338,11 @@
1214 1338
1215 1339 // It's already installed and active.
1216 1340 $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
1217 1341 if ( is_wp_error( $active ) ) {
1218 - // Download plugin now.
1219 - $response = self::download_and_activate();
1220 - if ( is_array( $response ) && isset( $response['success'] ) ) {
1342 + $response = self::maybe_download_and_activate();
1343 + if ( is_array( $response ) ) {
1344 + // The download failed.
1221 1345 return $response;
1222 1346 }
1223 1347 }
1224 1348
@@ -1245,22 +1369,58 @@
1245 1369 );
1246 1370 }
1247 1371
1248 1372 /**
1373 + * @since 6.8.3
1374 + *
1375 + * @return array|true
1376 + */
1377 + private static function maybe_download_and_activate() {
1378 + if ( ! self::$plugin ) {
1379 + return array(
1380 + 'success' => false,
1381 + 'message' => __( 'The plugin download was not found.', 'formidable' ),
1382 + );
1383 + }
1384 +
1385 + // Download plugin now.
1386 + $response = self::download_and_activate();
1387 + if ( is_array( $response ) && isset( $response['success'] ) ) {
1388 + // The download failed.
1389 + return $response;
1390 + }
1391 +
1392 + return true;
1393 + }
1394 +
1395 + /**
1249 1396 * Render a conditional action button for a specified plugin
1250 1397 *
1251 - * @param string $plugin
1398 + * @since 4.09
1399 + *
1400 + * @param string $plugin
1252 1401 * @param array|string $upgrade_link_args
1253 - * @since 4.09
1402 + * @return void
1254 1403 */
1255 1404 public static function conditional_action_button( $plugin, $upgrade_link_args ) {
1256 1405 if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) {
1257 - return FrmProAddonsController::conditional_action_button( $plugin, $upgrade_link_args );
1406 + FrmProAddonsController::conditional_action_button( $plugin, $upgrade_link_args );
1407 + return;
1258 1408 }
1259 1409
1260 1410 $addon = self::get_addon( $plugin );
1261 1411 $upgrade_link = FrmAppHelper::admin_upgrade_link( $upgrade_link_args );
1262 - self::addon_upgrade_link( $addon, $upgrade_link );
1412 +
1413 + if ( ! is_array( $upgrade_link_args ) ) {
1414 + // A string $upgrade_link_args is used for the utm-medium value when calling
1415 + // FrmAppHelper::admin_upgrade_link above.
1416 + // For self::addon_upgrade_link, we'll pass just an empty array with the link key (set below).
1417 + $upgrade_link_args = array();
1418 + }
1419 +
1420 + $upgrade_link_args['link'] = $upgrade_link;
1421 +
1422 + self::addon_upgrade_link( $addon, $upgrade_link_args );
1263 1423 }
1264 1424
1265 1425 /**
1266 1426 * Render a conditional action button for an add on
@@ -1266,16 +1426,22 @@
1266 1426 * Render a conditional action button for an add on
1267 1427 *
1268 1428 * @since 4.09.01
1269 1429 *
1270 - * @param array $addon
1271 - * @param string|false $license_type
1272 - * @param string $plan_required
1273 - * @param string $upgrade_link
1430 + * @param array $atts {
1431 + * Button attributes.
1432 + *
1433 + * @type array $addon
1434 + * @type false|string $license_type
1435 + * @type string $plan_required
1436 + * @type string $upgrade_link
1437 + * }
1438 + * @return void
1274 1439 */
1275 1440 public static function show_conditional_action_button( $atts ) {
1276 1441 if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) {
1277 - return FrmProAddonsController::show_conditional_action_button( $atts );
1442 + FrmProAddonsController::show_conditional_action_button( $atts );
1443 + return;
1278 1444 }
1279 1445
1280 1446 self::addon_upgrade_link( $atts['addon'], $atts['upgrade_link'] );
1281 1447 }
@@ -1282,13 +1448,17 @@
1282 1448
1283 1449 /**
1284 1450 * @since 4.09.01
1285 1451 *
1286 - * @param array|false $addon
1452 + * @param array|false $addon
1453 + * @param array|string $upgrade_link
1287 1454 *
1288 1455 * @return void
1289 1456 */
1290 1457 protected static function addon_upgrade_link( $addon, $upgrade_link ) {
1458 + $atts = is_array( $upgrade_link ) ? $upgrade_link : array();
1459 + $upgrade_link = is_array( $upgrade_link ) ? $upgrade_link['link'] : $upgrade_link;
1460 +
1291 1461 if ( $addon ) {
1292 1462 $upgrade_link .= '&utm_content=' . $addon['slug'];
1293 1463 }
1294 1464
@@ -1295,10 +1465,15 @@
1295 1465 if ( $addon && isset( $addon['categories'] ) && in_array( 'Solution', $addon['categories'], true ) ) {
1296 1466 // Solutions will go to a separate page.
1297 1467 $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] );
1298 1468 }
1469 +
1470 + $class = ! empty( $atts['class'] ) ? $atts['class'] : '';
1471 + if ( strpos( $class, 'frm-button' ) === false ) {
1472 + $class .= ' frm-button-secondary frm-button-sm';
1473 + }
1299 1474 ?>
1300 - <a class="install-now button frm-button-secondary frm-button-sm" href="<?php echo esc_url( $upgrade_link ); ?>" target="_blank" rel="noopener" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>">
1475 + <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' ); ?>">
1301 1476 <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?>
1302 1477 </a>
1303 1478 <?php
1304 1479 }
@@ -1353,107 +1528,38 @@
1353 1528 return $allowed_url_list;
1354 1529 }
1355 1530
1356 1531 /**
1357 - * @since 4.06.02
1532 + * Gets required plan for an addon.
1358 1533 *
1359 - * @deprecated 4.09.01
1534 + * @since 6.4.2
1360 1535 *
1361 - * @return void
1536 + * @return string Empty string if no plan is required for active license.
1362 1537 */
1363 - public static function ajax_multiple_addons() {
1364 - FrmDeprecated::ajax_multiple_addons();
1365 - }
1538 + public static function get_addon_required_plan( $addon_id ) {
1539 + $api = new FrmFormApi();
1540 + $addons = $api->get_api_info();
1366 1541
1367 - /**
1368 - * @since 3.04.03
1369 - * @deprecated 3.06
1370 - * @codeCoverageIgnore
1371 - * @return array
1372 - */
1373 - public static function error_for_license( $license ) {
1374 - return FrmDeprecated::error_for_license( $license );
1375 - }
1542 + if ( is_array( $addons ) && array_key_exists( $addon_id, $addons ) ) {
1543 + $dates = $addons[ $addon_id ];
1544 + $requires = FrmFormsHelper::get_plan_required( $dates );
1545 + }
1376 1546
1377 - /**
1378 - * @since 3.04.03
1379 - * @deprecated 3.06
1380 - * @codeCoverageIgnore
1381 - */
1382 - public static function get_pro_updater() {
1383 - return FrmDeprecated::get_pro_updater();
1384 - }
1547 + if ( ! isset( $requires ) || ! is_string( $requires ) ) {
1548 + $requires = '';
1549 + }
1385 1550
1386 - /**
1387 - * @since 3.04.03
1388 - * @deprecated 3.06
1389 - * @codeCoverageIgnore
1390 - *
1391 - * @return array
1392 - */
1393 - public static function get_addon_info( $license = '' ) {
1394 - return FrmDeprecated::get_addon_info( $license );
1551 + return $requires;
1395 1552 }
1396 1553
1397 1554 /**
1398 - * @since 3.04.03
1399 - * @deprecated 3.06
1400 - * @codeCoverageIgnore
1555 + * @since 4.02.05
1556 + * @deprecated 6.8.3
1401 1557 *
1402 - * @return string
1403 - */
1404 - public static function get_cache_key( $license ) {
1405 - return FrmDeprecated::get_cache_key( $license );
1406 - }
1407 -
1408 - /**
1409 - * @since 3.04.03
1410 - *
1411 - * @deprecated 3.06
1412 - *
1413 1558 * @codeCoverageIgnore
1414 1559 *
1415 1560 * @return void
1416 1561 */
1417 - public static function reset_cached_addons( $license = '' ) {
1418 - FrmDeprecated::reset_cached_addons( $license );
1419 - }
1420 -
1421 - /**
1422 - * @since 2.03.08
1423 - * @deprecated 3.04.03
1424 - * @codeCoverageIgnore
1425 - *
1426 - * @param boolean $return
1427 - * @param string $package
1428 - *
1429 - * @return boolean
1430 - */
1431 - public static function add_shorten_edd_filename_filter( $return, $package ) {
1432 - return FrmDeprecated::add_shorten_edd_filename_filter( $return, $package );
1433 - }
1434 -
1435 - /**
1436 - * @since 2.03.08
1437 - * @deprecated 3.04.03
1438 - * @codeCoverageIgnore
1439 - *
1440 - * @param string $filename
1441 - * @param string $ext
1442 - *
1443 - * @return string
1444 - */
1445 - public static function shorten_edd_filename( $filename, $ext ) {
1446 - return FrmDeprecated::shorten_edd_filename( $filename, $ext );
1447 - }
1448 -
1449 - /**
1450 - * @deprecated 3.04.03
1451 - *
1452 - * @codeCoverageIgnore
1453 - *
1454 - * @return void
1455 - */
1456 - public static function get_licenses() {
1457 - FrmDeprecated::get_licenses();
1562 + public static function connect_pro() {
1563 + _deprecated_function( __METHOD__, '6.8.3' );
1458 1564 }
1459 1565 }