PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.07.01
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.07.01
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 +130 -541 6.34.07.01 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 }
@@ -18,10 +10,11 @@
18 10 return;
19 11 }
20 12
21 13 $label = __( 'Add-Ons', 'formidable' );
22 - $label = '<span style="color:#fe5a1d">' . $label . '</span>';
23 -
14 + if ( FrmAppHelper::pro_is_installed() ) {
15 + $label = '<span style="color:#fe5a1d">' . $label . '</span>';
16 + }
24 17 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), $label, 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' );
25 18
26 19 if ( ! FrmAppHelper::pro_is_installed() ) {
27 20 add_submenu_page(
@@ -26,22 +19,16 @@
26 19 if ( ! FrmAppHelper::pro_is_installed() ) {
27 20 add_submenu_page(
28 21 'formidable',
29 22 'Formidable | ' . __( 'Upgrade', 'formidable' ),
30 - '<span class="frm-upgrade-submenu">' . __( 'Upgrade', 'formidable' ) . '</span>',
23 + '<span style="color:#fe5a1d">' . __( 'Upgrade', 'formidable' ) . '</span>',
31 24 'frm_view_forms',
32 25 'formidable-pro-upgrade',
33 26 'FrmAddonsController::upgrade_to_pro'
34 27 );
35 - } elseif ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) ) {
36 - wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) );
37 - exit;
38 28 }
39 29 }
40 30
41 - /**
42 - * @return void
43 - */
44 31 public static function list_addons() {
45 32 FrmAppHelper::include_svg();
46 33 $installed_addons = apply_filters( 'frm_installed_addons', array() );
47 34 $license_type = '';
@@ -54,19 +41,8 @@
54 41 $errors = $api->get_error_from_response( $addons );
55 42 $license_type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : '';
56 43 unset( $addons['error'] );
57 44 }
58 -
59 - $pro = array(
60 - 'pro' => array(
61 - 'title' => 'Formidable Forms Pro',
62 - 'slug' => 'formidable-pro',
63 - 'released' => '2011-02-05',
64 - 'docs' => 'knowledgebase/',
65 - 'excerpt' => 'Create calculators, surveys, smart forms, and data-driven applications. Build directories, real estate listings, job boards, and much more.',
66 - ),
67 - );
68 - $addons = $pro + $addons;
69 45 self::prepare_addons( $addons );
70 46
71 47 $pricing = FrmAppHelper::admin_upgrade_link( 'addons' );
72 48
@@ -72,11 +48,8 @@
72 48
73 49 include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' );
74 50 }
75 51
76 - /**
77 - * @return void
78 - */
79 52 public static function license_settings() {
80 53 $plugins = apply_filters( 'frm_installed_addons', array() );
81 54 if ( empty( $plugins ) ) {
82 55 esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
@@ -88,12 +61,9 @@
88 61
89 62 include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' );
90 63 }
91 64
92 - /**
93 - * @return array
94 - */
95 - protected static function get_api_addons() {
65 + private static function get_api_addons() {
96 66 $api = new FrmFormApi();
97 67 $addons = $api->get_api_info();
98 68
99 69 if ( empty( $addons ) ) {
@@ -114,19 +84,19 @@
114 84 *
115 85 * @since 3.04.03
116 86 * @return array
117 87 */
118 - protected static function fallback_plugin_list() {
119 - $list = array(
88 + private static function fallback_plugin_list() {
89 + return array(
120 90 'formidable-pro' => array(
121 - 'title' => 'Formidable Forms Pro',
91 + 'title' => 'Formidable Forms',
122 92 'link' => 'pricing/',
123 93 'docs' => '',
124 94 '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 95 ),
126 96 '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.',
97 + 'title' => 'MailChimp Forms',
98 + '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 99 ),
130 100 'registration' => array(
131 101 'title' => 'User Registration Forms',
132 102 'link' => 'downloads/user-registration/',
@@ -184,28 +154,9 @@
184 154 'title' => 'Twilio SMS Forms',
185 155 'docs' => 'knowledgebase/twilio-add-on/',
186 156 'excerpt' => 'Allow users to text their votes for polls created by Formidable Forms, or send SMS notifications when entries are submitted or updated.',
187 157 ),
188 - 'views' => array(
189 - 'title' => 'Formidable Views',
190 - 'excerpt' => 'Add the power of views to your Formidable Forms to display your form submissions in listings, tables, calendars, and more.',
191 - ),
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 158 );
198 -
199 - $defaults = array(
200 - 'released' => '',
201 - );
202 -
203 - foreach ( $list as $k => $info ) {
204 - $info['slug'] = $k;
205 - $list[ $k ] = array_merge( $defaults, $info );
206 - }
207 - return $list;
208 159 }
209 160
210 161 /**
211 162 * If Pro is missing but has been authenticated, include a download URL
@@ -213,20 +164,8 @@
213 164 * @since 3.04.03
214 165 * @return string
215 166 */
216 167 public static function get_pro_download_url() {
217 - $license = self::get_pro_license();
218 - $api = new FrmFormApi( $license );
219 - $downloads = $api->get_api_info();
220 - $pro = self::get_pro_from_addons( $downloads );
221 -
222 - return isset( $pro['url'] ) ? $pro['url'] : '';
223 - }
224 -
225 - /**
226 - * @since 4.08
227 - */
228 - public static function get_pro_license() {
229 168 $pro_cred_store = 'frmpro-credentials';
230 169 $pro_wpmu_store = 'frmpro-wpmu-sitewide';
231 170 if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) {
232 171 $creds = get_site_option( $pro_cred_store );
@@ -246,19 +185,14 @@
246 185 if ( strpos( $license, '-' ) ) {
247 186 // this is a fix for licenses saved in the past
248 187 $license = strtoupper( $license );
249 188 }
250 - return $license;
251 - }
252 189
253 - /**
254 - * @since 4.08
255 - *
256 - * @param array $addons
257 - * @return array
258 - */
259 - protected static function get_pro_from_addons( $addons ) {
260 - return isset( $addons['93790'] ) ? $addons['93790'] : array();
190 + $api = new FrmFormApi( $license );
191 + $downloads = $api->get_api_info();
192 + $pro = isset( $downloads['93790'] ) ? $downloads['93790'] : array();
193 +
194 + return isset( $pro['url'] ) ? $pro['url'] : '';
261 195 }
262 196
263 197 /**
264 198 * @since 4.06
@@ -263,46 +197,40 @@
263 197 /**
264 198 * @since 4.06
265 199 */
266 200 public static function license_type() {
267 - if ( is_callable( 'FrmProAddonsController::license_type' ) ) {
268 - return FrmProAddonsController::license_type();
201 + $api = new FrmFormApi();
202 + $addons = $api->get_api_info();
203 + $type = 'free';
204 +
205 + if ( isset( $addons['error'] ) ) {
206 + if ( isset( $addons['error']['code'] ) && $addons['error']['code'] === 'expired' ) {
207 + return $addons['error']['code'];
208 + }
209 + $type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : $type;
269 210 }
270 211
271 - return 'free';
272 - }
273 -
274 - /**
275 - * @since 4.0.01
276 - */
277 - public static function is_license_expired() {
278 - $version_info = self::get_primary_license_info();
279 - if ( ! isset( $version_info['error'] ) ) {
280 - return false;
212 + $pro = isset( $addons['93790'] ) ? $addons['93790'] : array();
213 + if ( $type === 'free' ) {
214 + $type = isset( $pro['type'] ) ? $pro['type'] : $type;
215 + if ( $type === 'free' ) {
216 + return $type;
217 + }
281 218 }
282 219
283 - return $version_info['error'];
284 - }
285 -
286 - /**
287 - * @since 4.08
288 - *
289 - * @return boolean|int false or the number of days until expiration.
290 - */
291 - public static function is_license_expiring() {
292 - if ( is_callable( 'FrmProAddonsController::is_license_expiring' ) ) {
293 - return FrmProAddonsController::is_license_expiring();
220 + if ( isset( $pro['code'] ) && $pro['code'] === 'grandfathered' ) {
221 + return $pro['code'];
294 222 }
295 223
296 - return false;
224 + $expires = isset( $pro['expires'] ) ? $pro['expires'] : '';
225 + $expired = $expires ? $expires < time() : false;
226 + return $expired ? 'expired' : strtolower( $type );
297 227 }
298 228
299 229 /**
300 - * @since 4.08
301 - *
302 - * @return array|false
230 + * @since 4.0.01
303 231 */
304 - protected static function get_primary_license_info() {
232 + public static function is_license_expired() {
305 233 $installed_addons = apply_filters( 'frm_installed_addons', array() );
306 234 if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) {
307 235 return false;
308 236 }
@@ -309,9 +237,14 @@
309 237 $installed_addons = array(
310 238 'formidable_pro' => $installed_addons['formidable_pro'],
311 239 );
312 240
313 - return self::fill_update_addon_info( $installed_addons );
241 + $version_info = self::fill_update_addon_info( $installed_addons );
242 + if ( ! isset( $version_info['error'] ) ) {
243 + return false;
244 + }
245 +
246 + return $version_info['error'];
314 247 }
315 248
316 249 /**
317 250 * @since 3.04.03
@@ -316,13 +249,8 @@
316 249 /**
317 250 * @since 3.04.03
318 251 */
319 252 public static function check_update( $transient ) {
320 - if ( ! FrmAppHelper::pro_is_installed() ) {
321 - // Don't make any changes if only Lite is installed.
322 - return $transient;
323 - }
324 -
325 253 if ( ! is_object( $transient ) ) {
326 254 $transient = new stdClass();
327 255 }
328 256
@@ -330,12 +258,17 @@
330 258 if ( empty( $installed_addons ) ) {
331 259 return $transient;
332 260 }
333 261
334 - $version_info = self::fill_update_addon_info( $installed_addons );
262 + $version_info = self::fill_update_addon_info( $installed_addons );
263 +
335 264 $transient->last_checked = time();
336 - $wp_plugins = self::get_plugins();
337 265
266 + if ( ! function_exists( 'get_plugins' ) ) {
267 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
268 + }
269 + $wp_plugins = get_plugins();
270 +
338 271 foreach ( $version_info as $id => $plugin ) {
339 272 $plugin = (object) $plugin;
340 273
341 274 if ( ! isset( $plugin->new_version ) || ! isset( $plugin->package ) ) {
@@ -368,23 +301,8 @@
368 301 return $transient;
369 302 }
370 303
371 304 /**
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 305 * Check if a plugin is installed before showing an update for it
388 306 *
389 307 * @since 3.05
390 308 *
@@ -391,10 +309,15 @@
391 309 * @param string $plugin - the folder/filename.php for a plugin
392 310 *
393 311 * @return bool - True if installed
394 312 */
395 - protected static function is_installed( $plugin ) {
396 - $all_plugins = self::get_plugins();
313 + private static function is_installed( $plugin ) {
314 + if ( ! function_exists( 'get_plugins' ) ) {
315 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
316 + }
317 +
318 + $all_plugins = get_plugins();
319 +
397 320 return isset( $all_plugins[ $plugin ] );
398 321 }
399 322
400 323 /**
@@ -403,9 +326,9 @@
403 326 * @param array $installed_addons
404 327 *
405 328 * @return array
406 329 */
407 - protected static function fill_update_addon_info( $installed_addons ) {
330 + private static function fill_update_addon_info( $installed_addons ) {
408 331 $checked_licenses = array();
409 332 $version_info = array();
410 333
411 334 foreach ( $installed_addons as $addon ) {
@@ -453,16 +376,22 @@
453 376 /**
454 377 * Get the action link for an addon that isn't active.
455 378 *
456 379 * @since 3.06.03
457 - * @param string $plugin The plugin slug
380 + * @param string $addon The plugin slug
458 381 * @return array
459 382 */
460 383 public static function install_link( $plugin ) {
461 - $link = array();
462 - $addon = self::get_addon( $plugin );
384 + $link = array();
385 + $addons = self::get_api_addons();
386 + self::prepare_addons( $addons );
463 387
464 - if ( $addon ) {
388 + foreach ( $addons as $addon ) {
389 + $slug = explode( '/', $addon['plugin'] );
390 + if ( $slug[0] !== 'formidable-' . $plugin ) {
391 + continue;
392 + }
393 +
465 394 if ( $addon['status']['type'] === 'installed' && ! empty( $addon['activate_url'] ) ) {
466 395 $link = array(
467 396 'url' => $addon['plugin'],
468 397 'class' => 'frm-activate-addon',
@@ -480,49 +409,14 @@
480 409
481 410 if ( ! empty( $link ) ) {
482 411 $link['status'] = $addon['status']['type'];
483 412 }
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 - }
490 413
491 - return $link;
492 - }
493 -
494 - /**
495 - * @since 4.09
496 - * @param string $plugin The plugin slug
497 - * @return array|false
498 - */
499 - protected static function get_addon( $plugin ) {
500 - $addons = self::get_api_addons();
501 - self::prepare_addons( $addons );
502 - foreach ( $addons as $addon ) {
503 - $slug = explode( '/', $addon['plugin'] );
504 - if ( $slug[0] === 'formidable-' . $plugin ) {
505 - return $addon;
506 - }
414 + return $link;
507 415 }
508 - return false;
509 416 }
510 417
511 418 /**
512 - * @since 4.09
513 - * @return string
514 - */
515 - protected static function get_license_type() {
516 - $license_type = '';
517 - $addons = self::get_api_addons();
518 - if ( isset( $addons['error'] ) && isset( $addons['error']['type'] ) ) {
519 - $license_type = $addons['error']['type'];
520 - }
521 - return $license_type;
522 - }
523 -
524 - /**
525 419 * @since 3.04.03
526 420 *
527 421 * @param array $addons
528 422 * @param object $license The FrmAddon object
@@ -544,12 +438,9 @@
544 438
545 439 return $plugin;
546 440 }
547 441
548 - /**
549 - * @return void
550 - */
551 - protected static function prepare_addons( &$addons ) {
442 + private static function prepare_addons( &$addons ) {
552 443 $activate_url = '';
553 444 if ( current_user_can( 'activate_plugins' ) ) {
554 445 $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) );
555 446 }
@@ -566,24 +457,14 @@
566 457 } else {
567 458 $base_file = 'formidable-' . $slug;
568 459 }
569 460 $file_name = $base_file . '/' . $base_file . '.php';
570 - if ( ! isset( $addon['plugin'] ) ) {
571 - $addon['plugin'] = $file_name;
572 - }
573 461 }
574 462
575 - $addon['installed'] = self::is_installed( $file_name );
576 - if ( $addon['installed'] && 'formidable-views/formidable-views.php' === $file_name ) {
577 - $active_views_version = self::get_active_views_version();
578 - if ( false !== $active_views_version && $slug !== $active_views_version ) {
579 - $addon['installed'] = false;
580 - }
581 - }
582 -
463 + $addon['installed'] = self::is_installed( $file_name );
583 464 $addon['activate_url'] = '';
584 465
585 - if ( $addon['installed'] && ! empty( $activate_url ) && ! self::is_plugin_active( $file_name, $slug ) ) {
466 + if ( $addon['installed'] && ! empty( $activate_url ) && ! is_plugin_active( $file_name ) ) {
586 467 $addon['activate_url'] = add_query_arg(
587 468 array(
588 469 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ),
589 470 'plugin' => $file_name,
@@ -607,34 +488,11 @@
607 488 }
608 489 }
609 490
610 491 /**
611 - * @return bool
612 - */
613 - private static function is_plugin_active( $file_name, $slug ) {
614 - if ( 'formidable-views/formidable-views.php' === $file_name ) {
615 - return self::get_active_views_version() === $slug;
616 - }
617 - return is_plugin_active( $file_name );
618 - }
619 -
620 - /**
621 - * @return string|false either 'visual-views' or 'views', false if one is not found.
622 - */
623 - private static function get_active_views_version() {
624 - if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) {
625 - return false;
626 - }
627 - $plugin_version = FrmViewsAppHelper::plugin_version();
628 - return version_compare( $plugin_version, '5.0', '>=' ) ? 'visual-views' : 'views';
629 - }
630 -
631 - /**
632 492 * @since 3.04.02
633 - *
634 - * @return void
635 493 */
636 - protected static function prepare_addon_link( &$link ) {
494 + private static function prepare_addon_link( &$link ) {
637 495 $site_url = 'https://formidableforms.com/';
638 496 if ( strpos( $link, 'http' ) !== 0 ) {
639 497 $link = $site_url . $link;
640 498 }
@@ -651,12 +509,10 @@
651 509 * Add the status to the addon array. Status options are:
652 510 * installed, active, not installed
653 511 *
654 512 * @since 3.04.02
655 - *
656 - * @return void
657 513 */
658 - protected static function set_addon_status( &$addon ) {
514 + private static function set_addon_status( &$addon ) {
659 515 if ( ! empty( $addon['activate_url'] ) ) {
660 516 $addon['status'] = array(
661 517 'type' => 'installed',
662 518 'label' => __( 'Installed', 'formidable' ),
@@ -673,11 +529,8 @@
673 529 );
674 530 }
675 531 }
676 532
677 - /**
678 - * @return void
679 - */
680 533 public static function upgrade_to_pro() {
681 534 FrmAppHelper::include_svg();
682 535
683 536 $link_parts = array(
@@ -887,16 +740,14 @@
887 740 /**
888 741 * Install Pro after connection with Formidable.
889 742 *
890 743 * @since 4.02.05
891 - *
892 - * @return void
893 744 */
894 745 public static function connect_pro() {
895 746 FrmAppHelper::permission_check( 'install_plugins' );
896 747 check_ajax_referer( 'frm_ajax', 'nonce' );
897 748
898 - $url = self::get_current_plugin();
749 + $url = FrmAppHelper::get_post_param( 'plugin', '', 'sanitize_text_field' );
899 750 if ( FrmAppHelper::pro_is_installed() || empty( $url ) ) {
900 751 wp_die();
901 752 }
902 753
@@ -902,15 +753,14 @@
902 753
903 754 $response = array();
904 755
905 756 // It's already installed and active.
906 - $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
757 + $active = activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
907 758 if ( is_wp_error( $active ) ) {
908 759 // The plugin was installed, but not active. Download it now.
909 760 self::ajax_install_addon();
910 761 } else {
911 - $response['active'] = true;
912 - $response['success'] = true;
762 + $response['active'] = true;
913 763 }
914 764
915 765 echo json_encode( $response );
916 766 wp_die();
@@ -916,62 +766,32 @@
916 766 wp_die();
917 767 }
918 768
919 769 /**
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.
770 + * @since 3.04.02
927 771 */
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 - }
772 + public static function ajax_install_addon() {
934 773
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 - }
774 + self::install_addon_permissions();
946 775
947 - /**
948 - * @since 4.08
949 - */
950 - protected static function download_and_activate() {
951 - if ( is_admin() ) {
952 - FrmAppHelper::set_current_screen_and_hook_suffix();
953 - }
776 + // Set the current screen to avoid undefined notices.
777 + global $hook_suffix;
778 + set_current_screen();
954 779
955 780 self::maybe_show_cred_form();
956 781
957 782 $installed = self::install_addon();
958 - if ( is_array( $installed ) && isset( $installed['message'] ) ) {
959 - return $installed;
960 - }
961 783 self::maybe_activate_addon( $installed );
784 +
785 + // Send back a response.
786 + echo json_encode( __( 'Your plugin has been installed. Please reload the page to see more options.', 'formidable' ) );
787 + wp_die();
962 788 }
963 789
964 790 /**
965 791 * @since 3.04.02
966 - *
967 - * @return void
968 792 */
969 - protected static function maybe_show_cred_form() {
970 - if ( ! function_exists( 'request_filesystem_credentials' ) ) {
971 - include_once( ABSPATH . 'wp-admin/includes/file.php' );
972 - }
973 -
793 + private static function maybe_show_cred_form() {
974 794 // Start output bufferring to catch the filesystem form if credentials are needed.
975 795 ob_start();
976 796
977 797 $show_form = false;
@@ -987,17 +807,12 @@
987 807 $show_form = true;
988 808 }
989 809
990 810 if ( $show_form ) {
991 - $form = ob_get_clean();
992 - $message = __( 'Sorry, your site requires FTP authentication. Please download plugins from FormidableForms.com and install them manually.', 'formidable' );
993 - $data = $form;
994 - $response = array(
995 - 'success' => false,
996 - 'message' => $message,
997 - 'form' => $form,
998 - );
999 - wp_send_json( $response );
811 + //$form = ob_get_clean();
812 + //TODO: test this: echo json_encode( array( 'form' => $form ) );
813 + echo json_encode( array( 'form' => __( 'Sorry, you\'re site requires FTP authentication. Please install plugins manaully.', 'formidable' ) ) );
814 + wp_die();
1000 815 }
1001 816
1002 817 ob_end_clean();
1003 818 }
@@ -1002,41 +817,18 @@
1002 817 ob_end_clean();
1003 818 }
1004 819
1005 820 /**
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 821 * We do not need any extra credentials if we have gotten this far,
1023 822 * so let's install the plugin.
1024 823 *
1025 824 * @since 3.04.02
1026 825 */
1027 - protected static function install_addon() {
1028 - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
826 + private static function install_addon() {
827 + require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
1029 828
1030 - $download_url = self::get_current_plugin();
829 + $download_url = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' );
1031 830
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 831 // Create the plugin upgrader with our custom skin.
1040 832 $installer = new Plugin_Upgrader( new FrmInstallerSkin() );
1041 833 $installer->install( $download_url );
1042 834
@@ -1042,91 +834,78 @@
1042 834
1043 835 // Flush the cache and return the newly installed plugin basename.
1044 836 wp_cache_flush();
1045 837
1046 - $plugin = $installer->plugin_info();
1047 - if ( ! $plugin ) {
1048 - return array(
1049 - 'message' => 'Plugin was not installed. ' . $installer->result,
1050 - 'success' => false,
1051 - );
1052 - }
1053 - return $plugin;
838 + return $installer->plugin_info();
1054 839 }
1055 840
1056 841 /**
1057 842 * @since 3.06.03
1058 - *
1059 - * @return void
1060 843 */
1061 844 public static function ajax_activate_addon() {
1062 845
1063 846 self::install_addon_permissions();
1064 847
1065 - FrmAppHelper::set_current_screen_and_hook_suffix();
848 + // Set the current screen to avoid undefined notices.
849 + global $hook_suffix;
850 + set_current_screen();
1066 851
1067 852 $plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
1068 853 self::maybe_activate_addon( $plugin );
1069 854
1070 - echo json_encode( self::get_addon_activation_response() );
855 + // Send back a response.
856 + echo json_encode( __( 'Your plugin has been activated. Please reload the page to see more options.', 'formidable' ) );
1071 857 wp_die();
1072 858 }
1073 859
1074 860 /**
1075 - * @return array
861 + * @since 4.06.02
1076 862 */
1077 - private static function get_addon_activation_response() {
1078 - $activating_page = self::get_activating_page();
863 + public static function ajax_multiple_addons() {
864 + self::install_addon_permissions();
1079 865
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 - );
866 + // Set the current screen to avoid undefined notices.
867 + global $hook_suffix;
868 + set_current_screen();
1084 869
1085 - return $response;
1086 - }
870 + $download_urls = FrmAppHelper::get_param( 'plugin', '', 'post' );
871 + $download_urls = explode( ',', $download_urls );
872 + FrmAppHelper::sanitize_value( 'esc_url_raw', $download_urls );
1087 873
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';
874 + foreach ( $download_urls as $download_url ) {
875 + $_POST['plugin'] = $download_url;
876 + if ( strpos( $download_url, 'http' ) !== false ) {
877 + // Installing.
878 + self::maybe_show_cred_form();
879 +
880 + $installed = self::install_addon();
881 + self::maybe_activate_addon( $installed );
882 + } else {
883 + // Activating.
884 + self::maybe_activate_addon( $download_url );
885 + }
1098 886 }
1099 887
1100 - if ( false !== strpos( $referer, 'frm_action=edit' ) ) {
1101 - return 'form_builder';
1102 - }
888 + echo json_encode( __( 'Your plugins have been installed and activated.', 'formidable' ) );
1103 889
1104 - return '';
890 + wp_die();
1105 891 }
1106 892
1107 893 /**
1108 894 * @since 3.04.02
1109 - *
1110 895 * @param string $installed The plugin folder name with file name
1111 896 */
1112 - protected static function maybe_activate_addon( $installed ) {
897 + private static function maybe_activate_addon( $installed ) {
1113 898 if ( ! $installed ) {
1114 899 return;
1115 900 }
1116 901
1117 - $activate = self::activate_plugin( $installed );
902 + $activate = activate_plugin( $installed );
1118 903 if ( is_wp_error( $activate ) ) {
1119 904 // Ignore the invalid header message that shows with nested plugins.
1120 905 if ( $activate->get_error_code() !== 'no_plugin_header' ) {
1121 - if ( wp_doing_ajax() ) {
1122 - echo json_encode( array( 'error' => $activate->get_error_message() ) );
1123 - wp_die();
1124 - }
1125 - return array(
1126 - 'message' => $activate->get_error_message(),
1127 - 'success' => false,
1128 - );
906 + echo json_encode( array( 'error' => $activate->get_error_message() ) );
907 + wp_die();
1129 908 }
1130 909 }
1131 910 }
1132 911
@@ -1133,15 +912,13 @@
1133 912 /**
1134 913 * Run security checks before installing
1135 914 *
1136 915 * @since 3.04.02
1137 - *
1138 - * @return void
1139 916 */
1140 - protected static function install_addon_permissions() {
917 + private static function install_addon_permissions() {
1141 918 check_ajax_referer( 'frm_ajax', 'nonce' );
1142 919
1143 - if ( ! current_user_can( 'activate_plugins' ) || ! self::get_current_plugin() ) {
920 + if ( ! current_user_can( 'activate_plugins' ) || ! isset( $_POST['plugin'] ) ) {
1144 921 echo json_encode( true );
1145 922 wp_die();
1146 923 }
1147 924 }
@@ -1146,189 +923,8 @@
1146 923 }
1147 924 }
1148 925
1149 926 /**
1150 - * @since 4.08
1151 - *
1152 - * @return string
1153 - */
1154 - public static function connect_link() {
1155 - $auth = get_option( 'frm_connect_token' );
1156 - if ( empty( $auth ) ) {
1157 - $auth = hash( 'sha512', wp_rand() );
1158 - update_option( 'frm_connect_token', $auth );
1159 - }
1160 - $link = FrmAppHelper::admin_upgrade_link( 'connect', 'api-connect' );
1161 - $args = array(
1162 - 'v' => 2,
1163 - 'siteurl' => FrmAppHelper::site_url(),
1164 - 'url' => get_rest_url(),
1165 - 'token' => $auth,
1166 - 'l' => self::get_pro_license(),
1167 - );
1168 -
1169 - return add_query_arg( $args, $link );
1170 - }
1171 -
1172 - /**
1173 - * Check the auth value for install permission.
1174 - *
1175 - * @since 4.08
1176 - *
1177 - * @return bool
1178 - */
1179 - public static function can_install_addon_api() {
1180 - // Verify params present (auth & download link).
1181 - $post_auth = FrmAppHelper::get_param( 'token', '', 'request', 'sanitize_text_field' );
1182 - $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' );
1183 -
1184 - if ( empty( $post_auth ) || empty( $post_url ) ) {
1185 - return false;
1186 - }
1187 -
1188 - // Verify auth.
1189 - $auth = get_option( 'frm_connect_token' );
1190 - if ( empty( $auth ) || ! hash_equals( $auth, $post_auth ) ) {
1191 - return false;
1192 - }
1193 -
1194 - return true;
1195 - }
1196 -
1197 - /**
1198 - * Install and/or activate the add-on file.
1199 - *
1200 - * @since 4.08
1201 - */
1202 - public static function install_addon_api() {
1203 - self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' );
1204 -
1205 - $error = esc_html__( 'Could not install an upgrade. Please download from formidableforms.com and install manually.', 'formidable' );
1206 -
1207 - // Delete so cannot replay.
1208 - delete_option( 'frm_connect_token' );
1209 -
1210 - // It's already installed and active.
1211 - $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
1212 - if ( is_wp_error( $active ) ) {
1213 - // Download plugin now.
1214 - $response = self::download_and_activate();
1215 - if ( is_array( $response ) && isset( $response['success'] ) ) {
1216 - return $response;
1217 - }
1218 - }
1219 -
1220 - // If empty license, save it now.
1221 - if ( empty( self::get_pro_license() ) && function_exists( 'load_formidable_pro' ) ) {
1222 - load_formidable_pro();
1223 - $license = stripslashes( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) );
1224 - if ( ! $license ) {
1225 - return array(
1226 - 'success' => false,
1227 - 'error' => 'That site does not have a valid license key.',
1228 - );
1229 - }
1230 -
1231 - $response = FrmAddon::activate_license_for_plugin( $license, 'formidable_pro' );
1232 - if ( ! $response['success'] ) {
1233 - // Could not activate license.
1234 - return $response;
1235 - }
1236 - }
1237 -
1238 - return array(
1239 - 'success' => true,
1240 - );
1241 - }
1242 -
1243 - /**
1244 - * Render a conditional action button for a specified plugin
1245 - *
1246 - * @param string $plugin
1247 - * @param array|string $upgrade_link_args
1248 - * @since 4.09
1249 - */
1250 - public static function conditional_action_button( $plugin, $upgrade_link_args ) {
1251 - if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) {
1252 - return FrmProAddonsController::conditional_action_button( $plugin, $upgrade_link_args );
1253 - }
1254 -
1255 - $addon = self::get_addon( $plugin );
1256 - $upgrade_link = FrmAppHelper::admin_upgrade_link( $upgrade_link_args );
1257 - self::addon_upgrade_link( $addon, $upgrade_link );
1258 - }
1259 -
1260 - /**
1261 - * Render a conditional action button for an add on
1262 - *
1263 - * @since 4.09.01
1264 - *
1265 - * @param array $addon
1266 - * @param string|false $license_type
1267 - * @param string $plan_required
1268 - * @param string $upgrade_link
1269 - */
1270 - public static function show_conditional_action_button( $atts ) {
1271 - if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) {
1272 - return FrmProAddonsController::show_conditional_action_button( $atts );
1273 - }
1274 -
1275 - self::addon_upgrade_link( $atts['addon'], $atts['upgrade_link'] );
1276 - }
1277 -
1278 - /**
1279 - * @since 4.09.01
1280 - *
1281 - * @param array|false $addon
1282 - *
1283 - * @return void
1284 - */
1285 - protected static function addon_upgrade_link( $addon, $upgrade_link ) {
1286 - if ( $addon ) {
1287 - $upgrade_link .= '&utm_content=' . $addon['slug'];
1288 - }
1289 -
1290 - if ( $addon && isset( $addon['categories'] ) && in_array( 'Solution', $addon['categories'], true ) ) {
1291 - // Solutions will go to a separate page.
1292 - $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] );
1293 - }
1294 - ?>
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' ); ?>">
1296 - <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?>
1297 - </a>
1298 - <?php
1299 - }
1300 -
1301 - /**
1302 - * @since 3.04.02
1303 - *
1304 - * @return void
1305 - */
1306 - public static function ajax_install_addon() {
1307 - self::install_addon_permissions();
1308 -
1309 - $result = self::download_and_activate();
1310 - if ( isset( $result['success'] ) && ! $result['success'] ) {
1311 - echo json_encode( $result );
1312 - wp_die();
1313 - }
1314 -
1315 - echo json_encode( self::get_addon_activation_response() );
1316 - wp_die();
1317 - }
1318 -
1319 - /**
1320 - * @since 4.06.02
1321 - *
1322 - * @deprecated 4.09.01
1323 - *
1324 - * @return void
1325 - */
1326 - public static function ajax_multiple_addons() {
1327 - FrmDeprecated::ajax_multiple_addons();
1328 - }
1329 -
1330 - /**
1331 927 * @since 3.04.03
1332 928 * @deprecated 3.06
1333 929 * @codeCoverageIgnore
1334 930 * @return array
@@ -1369,14 +965,10 @@
1369 965 }
1370 966
1371 967 /**
1372 968 * @since 3.04.03
1373 - *
1374 969 * @deprecated 3.06
1375 - *
1376 970 * @codeCoverageIgnore
1377 - *
1378 - * @return void
1379 971 */
1380 972 public static function reset_cached_addons( $license = '' ) {
1381 973 FrmDeprecated::reset_cached_addons( $license );
1382 974 }
@@ -1410,12 +1002,9 @@
1410 1002 }
1411 1003
1412 1004 /**
1413 1005 * @deprecated 3.04.03
1414 - *
1415 1006 * @codeCoverageIgnore
1416 - *
1417 - * @return void
1418 1007 */
1419 1008 public static function get_licenses() {
1420 1009 FrmDeprecated::get_licenses();
1421 1010 }