PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.03
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.03
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 +39 -197 6.35.0.03 View file →
@@ -4,16 +4,8 @@
4 4 }
5 5
6 6 class FrmAddonsController {
7 7
8 - /**
9 - * @var string $plugin
10 - */
11 - protected static $plugin;
12 -
13 - /**
14 - * @return void
15 - */
16 8 public static function menu() {
17 9 if ( ! current_user_can( 'activate_plugins' ) ) {
18 10 return;
19 11 }
@@ -37,11 +29,8 @@
37 29 exit;
38 30 }
39 31 }
40 32
41 - /**
42 - * @return void
43 - */
44 33 public static function list_addons() {
45 34 FrmAppHelper::include_svg();
46 35 $installed_addons = apply_filters( 'frm_installed_addons', array() );
47 36 $license_type = '';
@@ -72,11 +61,8 @@
72 61
73 62 include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' );
74 63 }
75 64
76 - /**
77 - * @return void
78 - */
79 65 public static function license_settings() {
80 66 $plugins = apply_filters( 'frm_installed_addons', array() );
81 67 if ( empty( $plugins ) ) {
82 68 esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
@@ -88,11 +74,8 @@
88 74
89 75 include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' );
90 76 }
91 77
92 - /**
93 - * @return array
94 - */
95 78 protected static function get_api_addons() {
96 79 $api = new FrmFormApi();
97 80 $addons = $api->get_api_info();
98 81
@@ -123,10 +106,10 @@
123 106 'docs' => '',
124 107 'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.',
125 108 ),
126 109 'mailchimp' => array(
127 - 'title' => 'Mailchimp Forms',
128 - 'excerpt' => 'Get on the path to more sales and leads in a matter of minutes. Add leads to a Mailchimp mailing list when they submit forms and update their information along with the entry.',
110 + 'title' => 'MailChimp Forms',
111 + 'excerpt' => 'Get on the path to more sales and leads in a matter of minutes. Add leads to a MailChimp mailing list when they submit forms and update their information along with the entry.',
129 112 ),
130 113 'registration' => array(
131 114 'title' => 'User Registration Forms',
132 115 'link' => 'downloads/user-registration/',
@@ -188,13 +171,8 @@
188 171 'views' => array(
189 172 'title' => 'Formidable Views',
190 173 'excerpt' => 'Add the power of views to your Formidable Forms to display your form submissions in listings, tables, calendars, and more.',
191 174 ),
192 - 'quiz_maker' => array(
193 - 'title' => 'Quiz Maker',
194 - 'link' => 'downloads/quiz-maker/',
195 - 'excerpt' => 'Make quizzes, automatically score them and show user scores.',
196 - ),
197 175 );
198 176
199 177 $defaults = array(
200 178 'released' => '',
@@ -251,11 +229,8 @@
251 229 }
252 230
253 231 /**
254 232 * @since 4.08
255 - *
256 - * @param array $addons
257 - * @return array
258 233 */
259 234 protected static function get_pro_from_addons( $addons ) {
260 235 return isset( $addons['93790'] ) ? $addons['93790'] : array();
261 236 }
@@ -297,10 +272,8 @@
297 272 }
298 273
299 274 /**
300 275 * @since 4.08
301 - *
302 - * @return array|false
303 276 */
304 277 protected static function get_primary_license_info() {
305 278 $installed_addons = apply_filters( 'frm_installed_addons', array() );
306 279 if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) {
@@ -330,12 +303,17 @@
330 303 if ( empty( $installed_addons ) ) {
331 304 return $transient;
332 305 }
333 306
334 - $version_info = self::fill_update_addon_info( $installed_addons );
307 + $version_info = self::fill_update_addon_info( $installed_addons );
308 +
335 309 $transient->last_checked = time();
336 - $wp_plugins = self::get_plugins();
337 310
311 + if ( ! function_exists( 'get_plugins' ) ) {
312 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
313 + }
314 + $wp_plugins = get_plugins();
315 +
338 316 foreach ( $version_info as $id => $plugin ) {
339 317 $plugin = (object) $plugin;
340 318
341 319 if ( ! isset( $plugin->new_version ) || ! isset( $plugin->package ) ) {
@@ -368,23 +346,8 @@
368 346 return $transient;
369 347 }
370 348
371 349 /**
372 - * Copy of FrmAppHelper::get_plugins.
373 - * Because this gets called on "pre_set_site_transient_update_plugins" an old version of FrmAppHelper may be loaded on plugin update.
374 - * This means that trying to access FrmAppHelper::get_plugins when upgrading from a Lite version before v5.5 results in a one-off error.
375 - *
376 - * @since 5.5.2
377 - * @return array
378 - */
379 - protected static function get_plugins() {
380 - if ( ! function_exists( 'get_plugins' ) ) {
381 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
382 - }
383 - return get_plugins();
384 - }
385 -
386 - /**
387 350 * Check if a plugin is installed before showing an update for it
388 351 *
389 352 * @since 3.05
390 353 *
@@ -392,9 +355,14 @@
392 355 *
393 356 * @return bool - True if installed
394 357 */
395 358 protected static function is_installed( $plugin ) {
396 - $all_plugins = self::get_plugins();
359 + if ( ! function_exists( 'get_plugins' ) ) {
360 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
361 + }
362 +
363 + $all_plugins = get_plugins();
364 +
397 365 return isset( $all_plugins[ $plugin ] );
398 366 }
399 367
400 368 /**
@@ -480,13 +448,8 @@
480 448
481 449 if ( ! empty( $link ) ) {
482 450 $link['status'] = $addon['status']['type'];
483 451 }
484 - } elseif ( current_user_can( 'activate_plugins' ) && self::is_installed( 'formidable-' . $plugin . '/formidable-' . $plugin . '.php' ) ) {
485 - $link = array(
486 - 'url' => 'formidable-' . $plugin . '/formidable-' . $plugin . '.php',
487 - 'class' => 'frm-activate-addon',
488 - );
489 452 }
490 453
491 454 return $link;
492 455 }
@@ -544,11 +507,8 @@
544 507
545 508 return $plugin;
546 509 }
547 510
548 - /**
549 - * @return void
550 - */
551 511 protected static function prepare_addons( &$addons ) {
552 512 $activate_url = '';
553 513 if ( current_user_can( 'activate_plugins' ) ) {
554 514 $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) );
@@ -606,11 +566,8 @@
606 566 $addons[ $id ] = $addon;
607 567 }
608 568 }
609 569
610 - /**
611 - * @return bool
612 - */
613 570 private static function is_plugin_active( $file_name, $slug ) {
614 571 if ( 'formidable-views/formidable-views.php' === $file_name ) {
615 572 return self::get_active_views_version() === $slug;
616 573 }
@@ -629,10 +586,8 @@
629 586 }
630 587
631 588 /**
632 589 * @since 3.04.02
633 - *
634 - * @return void
635 590 */
636 591 protected static function prepare_addon_link( &$link ) {
637 592 $site_url = 'https://formidableforms.com/';
638 593 if ( strpos( $link, 'http' ) !== 0 ) {
@@ -651,10 +606,8 @@
651 606 * Add the status to the addon array. Status options are:
652 607 * installed, active, not installed
653 608 *
654 609 * @since 3.04.02
655 - *
656 - * @return void
657 610 */
658 611 protected static function set_addon_status( &$addon ) {
659 612 if ( ! empty( $addon['activate_url'] ) ) {
660 613 $addon['status'] = array(
@@ -673,11 +626,8 @@
673 626 );
674 627 }
675 628 }
676 629
677 - /**
678 - * @return void
679 - */
680 630 public static function upgrade_to_pro() {
681 631 FrmAppHelper::include_svg();
682 632
683 633 $link_parts = array(
@@ -887,16 +837,14 @@
887 837 /**
888 838 * Install Pro after connection with Formidable.
889 839 *
890 840 * @since 4.02.05
891 - *
892 - * @return void
893 841 */
894 842 public static function connect_pro() {
895 843 FrmAppHelper::permission_check( 'install_plugins' );
896 844 check_ajax_referer( 'frm_ajax', 'nonce' );
897 845
898 - $url = self::get_current_plugin();
846 + $url = FrmAppHelper::get_post_param( 'plugin', '', 'sanitize_text_field' );
899 847 if ( FrmAppHelper::pro_is_installed() || empty( $url ) ) {
900 848 wp_die();
901 849 }
902 850
@@ -902,9 +850,9 @@
902 850
903 851 $response = array();
904 852
905 853 // It's already installed and active.
906 - $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
854 + $active = activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
907 855 if ( is_wp_error( $active ) ) {
908 856 // The plugin was installed, but not active. Download it now.
909 857 self::ajax_install_addon();
910 858 } else {
@@ -916,41 +864,15 @@
916 864 wp_die();
917 865 }
918 866
919 867 /**
920 - * @since 5.5.2
921 - *
922 - * @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.
927 - */
928 - protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
929 - if ( ! function_exists( 'activate_plugin' ) ) {
930 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
931 - }
932 - return activate_plugin( $plugin, $redirect, $network_wide, $silent );
933 - }
934 -
935 - /**
936 - * @since 5.0.10
937 - *
938 - * @return string
939 - */
940 - protected static function get_current_plugin() {
941 - if ( ! isset( self::$plugin ) ) {
942 - self::$plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' );
943 - }
944 - return self::$plugin;
945 - }
946 -
947 - /**
948 868 * @since 4.08
949 869 */
950 870 protected static function download_and_activate() {
871 + // Set the current screen to avoid undefined notices.
951 872 if ( is_admin() ) {
952 - FrmAppHelper::set_current_screen_and_hook_suffix();
873 + global $hook_suffix;
874 + set_current_screen();
953 875 }
954 876
955 877 self::maybe_show_cred_form();
956 878
@@ -962,10 +884,8 @@
962 884 }
963 885
964 886 /**
965 887 * @since 3.04.02
966 - *
967 - * @return void
968 888 */
969 889 protected static function maybe_show_cred_form() {
970 890 if ( ! function_exists( 'request_filesystem_credentials' ) ) {
971 891 include_once( ABSPATH . 'wp-admin/includes/file.php' );
@@ -1002,24 +922,8 @@
1002 922 ob_end_clean();
1003 923 }
1004 924
1005 925 /**
1006 - * Checks if an addon download url is allowed.
1007 - *
1008 - * @since 6.2
1009 - *
1010 - * @param string $download_url
1011 - *
1012 - * @return bool
1013 - */
1014 - public static function url_is_allowed( $download_url ) {
1015 - return (
1016 - FrmAppHelper::validate_url_is_in_s3_bucket( $download_url, 'zip' ) ||
1017 - ( strpos( $download_url, 'https://downloads.wordpress.org/plugin' ) === 0 && substr_compare( $download_url, '.zip', -4 ) === 0 )
1018 - );
1019 - }
1020 -
1021 - /**
1022 926 * We do not need any extra credentials if we have gotten this far,
1023 927 * so let's install the plugin.
1024 928 *
1025 929 * @since 3.04.02
@@ -1024,19 +928,12 @@
1024 928 *
1025 929 * @since 3.04.02
1026 930 */
1027 931 protected static function install_addon() {
1028 - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
932 + require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
1029 933
1030 - $download_url = self::get_current_plugin();
934 + $download_url = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' );
1031 935
1032 - if ( ! self::url_is_allowed( $download_url ) ) {
1033 - return array(
1034 - 'message' => 'Plugin URL is not valid',
1035 - 'success' => false,
1036 - );
1037 - }
1038 -
1039 936 // Create the plugin upgrader with our custom skin.
1040 937 $installer = new Plugin_Upgrader( new FrmInstallerSkin() );
1041 938 $installer->install( $download_url );
1042 939
@@ -1043,9 +940,9 @@
1043 940 // Flush the cache and return the newly installed plugin basename.
1044 941 wp_cache_flush();
1045 942
1046 943 $plugin = $installer->plugin_info();
1047 - if ( ! $plugin ) {
944 + if ( empty( $plugin ) ) {
1048 945 return array(
1049 946 'message' => 'Plugin was not installed. ' . $installer->result,
1050 947 'success' => false,
1051 948 );
@@ -1054,60 +951,27 @@
1054 951 }
1055 952
1056 953 /**
1057 954 * @since 3.06.03
1058 - *
1059 - * @return void
1060 955 */
1061 956 public static function ajax_activate_addon() {
1062 957
1063 958 self::install_addon_permissions();
1064 959
1065 - FrmAppHelper::set_current_screen_and_hook_suffix();
960 + // Set the current screen to avoid undefined notices.
961 + global $hook_suffix;
962 + set_current_screen();
1066 963
1067 964 $plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
1068 965 self::maybe_activate_addon( $plugin );
1069 966
1070 - echo json_encode( self::get_addon_activation_response() );
967 + // Send back a response.
968 + echo json_encode( __( 'Your plugin has been activated. Please reload the page to see more options.', 'formidable' ) );
1071 969 wp_die();
1072 970 }
1073 971
1074 972 /**
1075 - * @return array
1076 - */
1077 - private static function get_addon_activation_response() {
1078 - $activating_page = self::get_activating_page();
1079 -
1080 - $response = array(
1081 - 'message' => __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ),
1082 - 'saveAndReload' => $activating_page,
1083 - );
1084 -
1085 - return $response;
1086 - }
1087 -
1088 - /**
1089 - * Return a string that reflects the page from which the addon is being activated on,
1090 - * if it is from settings or form builder, otherwise return empty string.
1091 - *
1092 - * @return string
1093 - */
1094 - private static function get_activating_page() {
1095 - $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
1096 - if ( false !== strpos( $referer, 'frm_action=settings' ) ) {
1097 - return 'settings';
1098 - }
1099 -
1100 - if ( false !== strpos( $referer, 'frm_action=edit' ) ) {
1101 - return 'form_builder';
1102 - }
1103 -
1104 - return '';
1105 - }
1106 -
1107 - /**
1108 973 * @since 3.04.02
1109 - *
1110 974 * @param string $installed The plugin folder name with file name
1111 975 */
1112 976 protected static function maybe_activate_addon( $installed ) {
1113 977 if ( ! $installed ) {
@@ -1113,9 +977,9 @@
1113 977 if ( ! $installed ) {
1114 978 return;
1115 979 }
1116 980
1117 - $activate = self::activate_plugin( $installed );
981 + $activate = activate_plugin( $installed );
1118 982 if ( is_wp_error( $activate ) ) {
1119 983 // Ignore the invalid header message that shows with nested plugins.
1120 984 if ( $activate->get_error_code() !== 'no_plugin_header' ) {
1121 985 if ( wp_doing_ajax() ) {
@@ -1133,15 +997,13 @@
1133 997 /**
1134 998 * Run security checks before installing
1135 999 *
1136 1000 * @since 3.04.02
1137 - *
1138 - * @return void
1139 1001 */
1140 1002 protected static function install_addon_permissions() {
1141 1003 check_ajax_referer( 'frm_ajax', 'nonce' );
1142 1004
1143 - if ( ! current_user_can( 'activate_plugins' ) || ! self::get_current_plugin() ) {
1005 + if ( ! current_user_can( 'activate_plugins' ) || ! isset( $_POST['plugin'] ) ) {
1144 1006 echo json_encode( true );
1145 1007 wp_die();
1146 1008 }
1147 1009 }
@@ -1147,10 +1009,8 @@
1147 1009 }
1148 1010
1149 1011 /**
1150 1012 * @since 4.08
1151 - *
1152 - * @return string
1153 1013 */
1154 1014 public static function connect_link() {
1155 1015 $auth = get_option( 'frm_connect_token' );
1156 1016 if ( empty( $auth ) ) {
@@ -1199,9 +1059,11 @@
1199 1059 *
1200 1060 * @since 4.08
1201 1061 */
1202 1062 public static function install_addon_api() {
1203 - self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' );
1063 + // Sanitize when it's used to prevent double sanitizing.
1064 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
1065 + $_POST['plugin'] = isset( $_REQUEST['file_url'] ) ? $_REQUEST['file_url'] : ''; // Set for later use
1204 1066
1205 1067 $error = esc_html__( 'Could not install an upgrade. Please download from formidableforms.com and install manually.', 'formidable' );
1206 1068
1207 1069 // Delete so cannot replay.
@@ -1207,9 +1069,9 @@
1207 1069 // Delete so cannot replay.
1208 1070 delete_option( 'frm_connect_token' );
1209 1071
1210 1072 // It's already installed and active.
1211 - $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
1073 + $active = activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
1212 1074 if ( is_wp_error( $active ) ) {
1213 1075 // Download plugin now.
1214 1076 $response = self::download_and_activate();
1215 1077 if ( is_array( $response ) && isset( $response['success'] ) ) {
@@ -1220,9 +1082,9 @@
1220 1082 // If empty license, save it now.
1221 1083 if ( empty( self::get_pro_license() ) && function_exists( 'load_formidable_pro' ) ) {
1222 1084 load_formidable_pro();
1223 1085 $license = stripslashes( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) );
1224 - if ( ! $license ) {
1086 + if ( empty( $license ) ) {
1225 1087 return array(
1226 1088 'success' => false,
1227 1089 'error' => 'That site does not have a valid license key.',
1228 1090 );
@@ -1260,9 +1122,8 @@
1260 1122 /**
1261 1123 * Render a conditional action button for an add on
1262 1124 *
1263 1125 * @since 4.09.01
1264 - *
1265 1126 * @param array $addon
1266 1127 * @param string|false $license_type
1267 1128 * @param string $plan_required
1268 1129 * @param string $upgrade_link
@@ -1276,12 +1137,8 @@
1276 1137 }
1277 1138
1278 1139 /**
1279 1140 * @since 4.09.01
1280 - *
1281 - * @param array|false $addon
1282 - *
1283 - * @return void
1284 1141 */
1285 1142 protected static function addon_upgrade_link( $addon, $upgrade_link ) {
1286 1143 if ( $addon ) {
1287 1144 $upgrade_link .= '&utm_content=' . $addon['slug'];
@@ -1291,9 +1148,9 @@
1291 1148 // Solutions will go to a separate page.
1292 1149 $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] );
1293 1150 }
1294 1151 ?>
1295 - <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' ); ?>">
1152 + <a class="install-now button button-secondary frm-button-secondary" href="<?php echo esc_url( $upgrade_link ); ?>" target="_blank" rel="noopener" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>">
1296 1153 <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?>
1297 1154 </a>
1298 1155 <?php
1299 1156 }
@@ -1299,30 +1156,22 @@
1299 1156 }
1300 1157
1301 1158 /**
1302 1159 * @since 3.04.02
1303 - *
1304 - * @return void
1305 1160 */
1306 1161 public static function ajax_install_addon() {
1307 1162 self::install_addon_permissions();
1308 1163
1309 - $result = self::download_and_activate();
1310 - if ( isset( $result['success'] ) && ! $result['success'] ) {
1311 - echo json_encode( $result );
1312 - wp_die();
1313 - }
1164 + self::download_and_activate();
1314 1165
1315 - echo json_encode( self::get_addon_activation_response() );
1166 + // Send back a response.
1167 + echo json_encode( __( 'Your plugin has been installed. Please reload the page to see more options.', 'formidable' ) );
1316 1168 wp_die();
1317 1169 }
1318 1170
1319 1171 /**
1320 1172 * @since 4.06.02
1321 - *
1322 1173 * @deprecated 4.09.01
1323 - *
1324 - * @return void
1325 1174 */
1326 1175 public static function ajax_multiple_addons() {
1327 1176 FrmDeprecated::ajax_multiple_addons();
1328 1177 }
@@ -1369,14 +1218,10 @@
1369 1218 }
1370 1219
1371 1220 /**
1372 1221 * @since 3.04.03
1373 - *
1374 1222 * @deprecated 3.06
1375 - *
1376 1223 * @codeCoverageIgnore
1377 - *
1378 - * @return void
1379 1224 */
1380 1225 public static function reset_cached_addons( $license = '' ) {
1381 1226 FrmDeprecated::reset_cached_addons( $license );
1382 1227 }
@@ -1410,12 +1255,9 @@
1410 1255 }
1411 1256
1412 1257 /**
1413 1258 * @deprecated 3.04.03
1414 - *
1415 1259 * @codeCoverageIgnore
1416 - *
1417 - * @return void
1418 1260 */
1419 1261 public static function get_licenses() {
1420 1262 FrmDeprecated::get_licenses();
1421 1263 }