PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
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
formidable / classes / controllers / FrmAddonsController.php

FrmAddonsController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 3.06.06, at classes/controllers/FrmAddonsController.php

892 lines 24.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class FrmAddonsController {
4
5 public static function menu() {
6 if ( ! current_user_can( 'activate_plugins' ) ) {
7 return;
8 }
9
10 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), __( 'Add-Ons', 'formidable' ), 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' );
11
12 if ( ! FrmAppHelper::pro_is_installed() ) {
13 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Upgrade to Pro', 'formidable' ), __( 'Upgrade to Pro', 'formidable' ), 'frm_view_forms', 'formidable-pro-upgrade', 'FrmAddonsController::upgrade_to_pro' );
14 }
15 }
16
17 public static function list_addons() {
18 $installed_addons = apply_filters( 'frm_installed_addons', array() );
19
20 $addons = self::get_api_addons();
21 $errors = array();
22 if ( isset( $addons['error'] ) ) {
23 $api = new FrmFormApi();
24 $errors = $api->get_error_from_response( $addons );
25 unset( $addons['error'] );
26 }
27 self::prepare_addons( $addons );
28
29 $pricing = FrmAppHelper::admin_upgrade_link( 'addons' );
30
31 include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' );
32 }
33
34 public static function license_settings() {
35 $plugins = apply_filters( 'frm_installed_addons', array() );
36 if ( empty( $plugins ) ) {
37 esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
38 return;
39 }
40
41 ksort( $plugins );
42
43 include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' );
44 }
45
46 private static function get_api_addons() {
47 $api = new FrmFormApi();
48 $addons = $api->get_api_info();
49
50 if ( empty( $addons ) ) {
51 $addons = self::fallback_plugin_list();
52 } else {
53 foreach ( $addons as $k => $addon ) {
54 if ( empty( $addon['excerpt'] ) && $k !== 'error' ) {
55 unset( $addons[ $k ] );
56 }
57 }
58 }
59
60 return $addons;
61 }
62
63 /**
64 * If the API is unable to connect, show something on the addons page
65 *
66 * @since 3.04.03
67 * @return array
68 */
69 private static function fallback_plugin_list() {
70 return array(
71 'formidable-pro' => array(
72 'title' => 'Formidable Pro',
73 'link' => 'pricing/',
74 'docs' => '',
75 'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.',
76 ),
77 'mailchimp' => array(
78 'title' => 'MailChimp Forms',
79 '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.',
80 ),
81 'registration' => array(
82 'title' => 'User Registration Forms',
83 'link' => 'downloads/user-registration/',
84 'excerpt' => 'Give new users access to your site as quickly and painlessly as possible. Allow users to register, edit and be able to login to their profiles on your site from the front end in a clean, customized registration form.',
85 ),
86 'paypal' => array(
87 'title' => 'PayPal Standard Forms',
88 'link' => 'downloads/paypal-standard/',
89 'excerpt' => 'Automate your business by collecting instant payments from your clients. Collect information, calculate a total, and send them on to PayPal. Require a payment before publishing content on your site.',
90 ),
91 'stripe' => array(
92 'title' => 'Stripe Forms',
93 'docs' => 'knowledgebase/stripe/',
94 'excerpt' => 'Any Formidable forms on your site can accept credit card payments without users ever leaving your site.',
95 ),
96 'authorize-net' => array(
97 'title' => 'Authorize.net AIM Forms',
98 'link' => 'downloads/authorize-net-aim/',
99 'docs' => 'knowledgebase/authorize-net-aim/',
100 'excerpt' => 'Accept one-time payments directly on your site, using Authorize.net AIM.',
101 ),
102 'woocommerce' => array(
103 'title' => 'WooCommerce Forms',
104 'excerpt' => 'Use a Formidable form on your WooCommerce product pages.',
105 ),
106 'autoresponder' => array(
107 'title' => 'Form Action Automation',
108 'docs' => 'knowledgebase/schedule-autoresponder/',
109 'excerpt' => 'Schedule email notifications, SMS messages, and API actions.',
110 ),
111 'modal' => array(
112 'title' => 'Bootstrap Modal Forms',
113 'link' => 'downloads/bootstrap-modal/',
114 'docs' => 'knowledgebase/bootstrap-modal/',
115 'excerpt' => 'Open a view or form in a Bootstrap popup.',
116 ),
117 'bootstrap' => array(
118 'title' => 'Bootstrap Style Forms',
119 'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.',
120 ),
121 'zapier' => array(
122 'title' => 'Zapier Forms',
123 'excerpt' => 'Connect with hundreds of different applications through Zapier. Insert a new row in a Google docs spreadsheet, post on Twitter, or add a new Dropbox file with your form.',
124 ),
125 'signature' => array(
126 'title' => 'Digital Signature Forms',
127 'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.',
128 ),
129 'api' => array(
130 'title' => 'Formidable Forms API',
131 'link' => 'downloads/formidable-api/',
132 'excerpt' => 'Send entry results to any other site that has a Rest API. This includes the option of sending entries from one Formidable site to another.',
133 ),
134 'twilio' => array(
135 'title' => 'Twilio SMS Forms',
136 'docs' => 'knowledgebase/twilio-add-on/',
137 'excerpt' => 'Allow users to text their votes for polls created by Formidable Forms, or send SMS notifications when entries are submitted or updated.',
138 ),
139 );
140 }
141
142 /**
143 * If Pro is missing but has been authenticated, include a download URL
144 *
145 * @since 3.04.03
146 * @return string
147 */
148 public static function get_pro_download_url() {
149 $pro_cred_store = 'frmpro-credentials';
150 $pro_wpmu_store = 'frmpro-wpmu-sitewide';
151 if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) {
152 $creds = get_site_option( $pro_cred_store );
153 } else {
154 $creds = get_option( $pro_cred_store );
155 }
156
157 if ( empty( $creds ) || ! is_array( $creds ) || ! isset( $creds['license'] ) ) {
158 return '';
159 }
160
161 $license = $creds['license'];
162 if ( empty( $license ) ) {
163 return '';
164 }
165
166 if ( strpos( $license, '-' ) ) {
167 // this is a fix for licenses saved in the past
168 $license = strtoupper( $license );
169 }
170
171 $api = new FrmFormApi( $license );
172 $downloads = $api->get_api_info();
173 $pro = isset( $downloads['93790'] ) ? $downloads['93790'] : array();
174
175 return isset( $pro['url'] ) ? $pro['url'] : '';
176 }
177
178 /**
179 * @since 3.04.03
180 */
181 public static function check_update( $transient ) {
182 if ( ! is_object( $transient ) ) {
183 $transient = new stdClass();
184 }
185
186 $installed_addons = apply_filters( 'frm_installed_addons', array() );
187 if ( empty( $installed_addons ) ) {
188 return $transient;
189 }
190
191 $version_info = self::fill_update_addon_info( $installed_addons );
192
193 $transient->last_checked = time();
194
195 $wp_plugins = get_plugins();
196
197 foreach ( $version_info as $id => $plugin ) {
198 $plugin = (object) $plugin;
199
200 if ( ! isset( $plugin->new_version ) || ! isset( $plugin->package ) ) {
201 continue;
202 }
203
204 $folder = $plugin->plugin;
205 if ( empty( $folder ) ) {
206 continue;
207 }
208
209 if ( ! self::is_installed( $folder ) ) {
210 // don't show an update if the plugin isn't installed
211 continue;
212 }
213
214 $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array();
215 $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0';
216
217 if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) {
218 $slug = explode( '/', $folder );
219 $plugin->slug = $slug[0];
220 $transient->response[ $folder ] = $plugin;
221 }
222
223 $transient->checked[ $folder ] = $wp_version;
224
225 }
226
227 return $transient;
228 }
229
230 /**
231 * Check if a plugin is installed before showing an update for it
232 *
233 * @since 3.05
234 * @param string $plugin - the folder/filename.php for a plugin
235 * @return bool - True if installed
236 */
237 private static function is_installed( $plugin ) {
238 if ( ! function_exists( 'get_plugins' ) ) {
239 require_once ABSPATH . 'wp-admin/includes/plugin.php';
240 }
241
242 $all_plugins = get_plugins();
243 return isset( $all_plugins[ $plugin ] );
244 }
245
246 /**
247 * @since 3.04.03
248 *
249 * @param array $installed_addons
250 *
251 * @return array
252 */
253 private static function fill_update_addon_info( $installed_addons ) {
254 $checked_licenses = array();
255 $version_info = array();
256
257 foreach ( $installed_addons as $addon ) {
258 if ( $addon->store_url !== 'https://formidableforms.com' ) {
259 // check if this is a third-party addon
260 continue;
261 }
262
263 $new_license = $addon->license;
264 if ( empty( $new_license ) || in_array( $new_license, $checked_licenses ) ) {
265 continue;
266 }
267
268 $checked_licenses[] = $new_license;
269
270 $api = new FrmFormApi( $new_license );
271 if ( empty( $version_info ) ) {
272 $version_info = $api->get_api_info();
273 continue;
274 }
275
276 $plugin = $api->get_addon_for_license( $addon, $version_info );
277 if ( empty( $plugin ) ) {
278 continue;
279 }
280
281 $download_id = isset( $plugin['id'] ) ? $plugin['id'] : 0;
282 if ( ! empty( $download_id ) && ! isset( $version_info[ $download_id ]['package'] ) ) {
283 // if this addon is using its own license, get the update url
284 $addon_info = $api->get_api_info();
285
286 $version_info[ $download_id ] = $addon_info[ $download_id ];
287 if ( isset( $addon_info['error'] ) ) {
288 $version_info[ $download_id ]['error'] = array(
289 'message' => $addon_info['error']['message'],
290 'code' => $addon_info['error']['code'],
291 );
292 }
293 }
294 }
295
296 return $version_info;
297 }
298
299 /**
300 * Get the action link for an addon that isn't active.
301 *
302 * @since 3.06.03
303 * @param string $addon The plugin slug
304 * @return array
305 */
306 public static function install_link( $plugin ) {
307 $link = array();
308 $addons = self::get_api_addons();
309 self::prepare_addons( $addons );
310
311 foreach ( $addons as $addon ) {
312 $slug = explode( '/', $addon['plugin'] );
313 if ( $slug[0] !== 'formidable-' . $plugin ) {
314 continue;
315 }
316
317 if ( $addon['status']['type'] === 'installed' && ! empty( $addon['activate_url'] ) ) {
318 $link = array(
319 'url' => $addon['plugin'],
320 'class' => 'frm-activate-addon',
321 );
322 } elseif ( isset( $addon['url'] ) && ! empty( $addon['url'] ) ) {
323 $link = array(
324 'url' => $addon['url'],
325 'class' => 'frm-install-addon',
326 );
327 }
328
329 return $link;
330 }
331 }
332
333 /**
334 * @since 3.04.03
335 * @param array $addons
336 * @param object $license The FrmAddon object
337 * @return array
338 */
339 public static function get_addon_for_license( $addons, $license ) {
340 $download_id = $license->download_id;
341 $plugin = array();
342 if ( empty( $download_id ) && ! empty( $addons ) ) {
343 foreach ( $addons as $addon ) {
344 if ( strtolower( $license->plugin_name ) == strtolower( $addon['title'] ) ) {
345 return $addon;
346 }
347 }
348 } elseif ( isset( $addons[ $download_id ] ) ) {
349 $plugin = $addons[ $download_id ];
350 }
351
352 return $plugin;
353 }
354
355 private static function prepare_addons( &$addons ) {
356 $activate_url = '';
357 if ( current_user_can( 'activate_plugins' ) ) {
358 $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) );
359 }
360
361 $loop_addons = $addons;
362 foreach ( $loop_addons as $id => $addon ) {
363 if ( is_numeric( $id ) ) {
364 $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] );
365 $file_name = $addon['plugin'];
366 } else {
367 $slug = $id;
368 if ( isset( $addon['file'] ) ) {
369 $base_file = $addon['file'];
370 } else {
371 $base_file = 'formidable-' . $slug;
372 }
373 $file_name = $base_file . '/' . $base_file . '.php';
374 }
375
376 $addon['installed'] = self::is_installed( $file_name );
377 $addon['activate_url'] = '';
378
379 if ( $addon['installed'] && ! empty( $activate_url ) && ! is_plugin_active( $file_name ) ) {
380 $addon['activate_url'] = add_query_arg(
381 array(
382 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ),
383 'plugin' => $file_name,
384 ),
385 $activate_url
386 );
387 }
388
389 if ( ! isset( $addon['docs'] ) ) {
390 $addon['docs'] = 'knowledgebase/formidable-' . $slug . '/';
391 }
392 self::prepare_addon_link( $addon['docs'] );
393
394 if ( ! isset( $addon['link'] ) ) {
395 $addon['link'] = 'downloads/' . $slug . '/';
396 }
397 self::prepare_addon_link( $addon['link'] );
398
399 self::set_addon_status( $addon );
400 $addons[ $id ] = $addon;
401 }
402 }
403
404 /**
405 * @since 3.04.02
406 */
407 private static function prepare_addon_link( &$link ) {
408 $site_url = 'https://formidableforms.com/';
409 if ( strpos( $link, 'http' ) !== 0 ) {
410 $link = $site_url . $link;
411 }
412 $link = FrmAppHelper::make_affiliate_url( $link );
413 $query_args = array(
414 'utm_source' => 'WordPress',
415 'utm_medium' => 'addons',
416 'utm_campaign' => 'liteplugin',
417 );
418 $link = add_query_arg( $query_args, $link );
419 }
420
421 /**
422 * Add the status to the addon array. Status options are:
423 * installed, active, not installed
424 *
425 * @since 3.04.02
426 */
427 private static function set_addon_status( &$addon ) {
428 if ( ! empty( $addon['activate_url'] ) ) {
429 $addon['status'] = array(
430 'type' => 'installed',
431 'label' => __( 'Installed', 'formidable' ),
432 );
433 } elseif ( $addon['installed'] ) {
434 $addon['status'] = array(
435 'type' => 'active',
436 'label' => __( 'Active', 'formidable' ),
437 );
438 } else {
439 $addon['status'] = array(
440 'type' => 'not-installed',
441 'label' => __( 'Not Installed', 'formidable' ),
442 );
443 }
444 }
445
446 public static function upgrade_to_pro() {
447 $pro_pricing = self::prepare_pro_info();
448
449 $link_parts = array(
450 'medium' => 'upgrade',
451 'content' => 'button',
452 );
453
454 $features = array(
455 'Display Entries' => array(
456 array(
457 'label' => 'Display form data with virtually limitless views',
458 'link' => array(
459 'content' => 'views',
460 'anchor' => 'feature-display-form-data-views',
461 ),
462 'lite' => false,
463 ),
464 array(
465 'label' => 'Generate graphs and stats based on your submitted data',
466 'link' => array(
467 'content' => 'graphs',
468 'anchor' => 'feature-create-a-graph-wordpress-forms',
469 ),
470 'lite' => false,
471 ),
472 ),
473 'Entry Management' => array(
474 array(
475 'label' => 'Import entries from a CSV',
476 'link' => array(
477 'content' => 'import-entries',
478 'anchor' => 'feature-importing-exporting-wordpress-forms',
479 ),
480 'lite' => false,
481 ),
482 array(
483 'label' => 'Logged-in users can save drafts and return later',
484 'link' => array(
485 'content' => 'save-drafts',
486 'anchor' => 'feature-save-and-continue-partial-submissions',
487 ),
488 'lite' => false,
489 ),
490 array(
491 'label' => 'Flexibly and powerfully view, edit, and delete entries from anywhere on your site',
492 'link' => array(
493 'content' => 'front-edit',
494 'anchor' => 'feature-front-end-editing-wordpress',
495 ),
496 'lite' => false,
497 ),
498 array(
499 'label' => 'View form submissions from the back-end',
500 'lite' => true,
501 ),
502 array(
503 'label' => 'Export your entries to a CSV',
504 'lite' => true,
505 ),
506 ),
507 'Form Building' => array(
508 array(
509 'label' => 'Save a calculated value into a field',
510 'link' => array(
511 'content' => 'calculations',
512 'anchor' => 'feature-wordpress-calculated-fields-form',
513 ),
514 'lite' => false,
515 ),
516 array(
517 'label' => 'Allow multiple file uploads',
518 'link' => array(
519 'content' => 'file-uploads',
520 'anchor' => 'feature-wordpress-multiple-file-upload-form',
521 ),
522 'lite' => false,
523 ),
524 array(
525 'label' => 'Repeat sections of fields',
526 'link' => array(
527 'content' => 'repeaters',
528 'anchor' => 'feature-dynamically-add-form-fields',
529 ),
530 'lite' => false,
531 ),
532 array(
533 'label' => 'Hide and show fields conditionally based on other fields or the user\'s role',
534 'link' => array(
535 'content' => 'conditional-logic',
536 'anchor' => 'feature-conditional-logic-wordpress-forms',
537 ),
538 'lite' => false,
539 ),
540 array(
541 'label' => 'Confirmation fields',
542 'link' => array(
543 'content' => 'confirmation-fields',
544 'anchor' => 'feature-confirm-email-address-password-wordpress-form',
545 ),
546 'lite' => false,
547 ),
548 array(
549 'label' => 'Multi-paged forms',
550 'link' => array(
551 'content' => 'page-breaks',
552 'anchor' => 'feature-wordpress-multi-step-form',
553 ),
554 'lite' => false,
555 ),
556 array(
557 'label' => 'Include section headings, page breaks, rich text, dates, times, scales, star ratings, sliders, toggles, dynamic fields populated from other forms, passwords, and tags in advanced forms.',
558 'lite' => false,
559 ),
560 array(
561 'label' => 'Include text, email, url, paragraph text, radio, checkbox, dropdown fields, hidden fields, user ID fields, and HTML blocks in your form.',
562 'lite' => true,
563 ),
564 array(
565 'label' => 'Drag & Drop Form building',
566 'link' => array(
567 'content' => 'drag-drop',
568 'anchor' => 'feature-drag-drop-form-builder',
569 ),
570 'lite' => true,
571 ),
572 array(
573 'label' => 'Create forms from Templates',
574 'link' => array(
575 'content' => 'form-templates',
576 'anchor' => 'feature-wordpress-form-templates',
577 ),
578 'lite' => true,
579 ),
580 array(
581 'label' => 'Import and export forms with XML',
582 'link' => array(
583 'content' => 'import',
584 'anchor' => 'feature-importing-exporting-wordpress-forms',
585 ),
586 'lite' => true,
587 ),
588 array(
589 'label' => 'Use input placeholder text in your fields that clear when typing starts.',
590 'lite' => true,
591 ),
592 ),
593 'Form Actions' => array(
594 array(
595 'label' => 'Conditionally send your email notifications based on values in your form',
596 'link' => array(
597 'content' => 'conditional-emails',
598 'anchor' => 'feature-conditional-logic-wordpress-forms',
599 ),
600 'lite' => false,
601 ),
602 array(
603 'label' => 'Create and edit WordPress posts or custom posts from the front-end',
604 'link' => array(
605 'content' => 'create-posts',
606 'anchor' => 'feature-user-submitted-posts-wordpress-forms',
607 ),
608 'lite' => false,
609 ),
610 array(
611 'label' => 'Send multiple emails and autoresponders',
612 'link' => array(
613 'content' => 'multiple-emails',
614 'anchor' => 'feature-email-autoresponders-wordpress',
615 ),
616 'lite' => true,
617 ),
618 ),
619 'Form Appearance' => array(
620 array(
621 'label' => 'Create Multiple styles for different forms',
622 'link' => array(
623 'content' => 'multiple-styles',
624 'anchor' => 'feature-wordpress-visual-form-styler',
625 ),
626 'lite' => false,
627 ),
628 array(
629 'label' => 'Customizable layout with CSS classes',
630 'link' => array(
631 'content' => 'form-layout',
632 'anchor' => 'feature-wordpress-mobile-friendly-responsive-forms',
633 ),
634 'lite' => true,
635 ),
636 array(
637 'label' => 'Customize the HTML for your forms',
638 'link' => array(
639 'content' => 'custom-html',
640 'anchor' => 'feature-customize-form-html-wordpress',
641 ),
642 'lite' => true,
643 ),
644 array(
645 'label' => 'Style your form with the Visual Form Styler',
646 'lite' => true,
647 ),
648 ),
649 );
650
651 include( FrmAppHelper::plugin_path() . '/classes/views/addons/upgrade_to_pro.php' );
652 }
653
654 private static function prepare_pro_info() {
655 return array(
656 'personal' => array(
657 'id' => 2,
658 'download' => 19367654,
659 'price' => '49.00',
660 'name' => 'Personal',
661 ),
662 'professional' => array(
663 'id' => 0,
664 'download' => 19367001,
665 'price' => '99.00',
666 'name' => 'Creator',
667 ),
668 'smallbusiness' => array(
669 'id' => 0,
670 'download' => 19366995,
671 'price' => '199.00',
672 'name' => 'Business',
673 ),
674 'enterprise' => array(
675 'id' => 0,
676 'download' => 19366992,
677 'price' => '399.00',
678 'name' => 'Elite',
679 ),
680 );
681 }
682
683 /**
684 * @since 3.04.02
685 */
686 public static function ajax_install_addon() {
687
688 self::install_addon_permissions();
689
690 // Set the current screen to avoid undefined notices.
691 global $hook_suffix;
692 set_current_screen();
693
694 self::maybe_show_cred_form();
695
696 $installed = self::install_addon();
697 self::maybe_activate_addon( $installed );
698
699 // Send back a response.
700 echo json_encode( __( 'Your plugin has been installed. Please reload the page to see more options.', 'formidable' ) );
701 wp_die();
702 }
703
704 /**
705 * @since 3.04.02
706 */
707 private static function maybe_show_cred_form() {
708 // Start output bufferring to catch the filesystem form if credentials are needed.
709 ob_start();
710
711 $show_form = false;
712 $method = '';
713 $url = add_query_arg( array( 'page' => 'formidable-settings' ), admin_url( 'admin.php' ) );
714 $url = esc_url_raw( $url );
715 $creds = request_filesystem_credentials( $url, $method, false, false, null );
716
717 if ( false === $creds ) {
718 $show_form = true;
719 } elseif ( ! WP_Filesystem( $creds ) ) {
720 request_filesystem_credentials( $url, $method, true, false, null );
721 $show_form = true;
722 }
723
724 if ( $show_form ) {
725 $form = ob_get_clean();
726 //TODO: test this: echo json_encode( array( 'form' => $form ) );
727 echo json_encode( array( 'form' => __( 'Sorry, you\'re site requires FTP authentication. Please install plugins manaully.', 'formidable' ) ) );
728 wp_die();
729 }
730
731 ob_end_clean();
732 }
733
734 /**
735 * We do not need any extra credentials if we have gotten this far,
736 * so let's install the plugin.
737 *
738 * @since 3.04.02
739 */
740 private static function install_addon() {
741 require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
742
743 $download_url = esc_url_raw( $_POST['plugin'] );
744
745 // Create the plugin upgrader with our custom skin.
746 $installer = new Plugin_Upgrader( new FrmInstallerSkin() );
747 $installer->install( $download_url );
748
749 // Flush the cache and return the newly installed plugin basename.
750 wp_cache_flush();
751 return $installer->plugin_info();
752 }
753
754 /**
755 * @since 3.06.03
756 */
757 public static function ajax_activate_addon() {
758
759 self::install_addon_permissions();
760
761 // Set the current screen to avoid undefined notices.
762 global $hook_suffix;
763 set_current_screen();
764
765 $plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
766 self::maybe_activate_addon( $plugin );
767
768 // Send back a response.
769 echo json_encode( __( 'Your plugin has been activated. Please reload the page to see more options.', 'formidable' ) );
770 wp_die();
771 }
772
773 /**
774 * @since 3.04.02
775 * @param string $installed The plugin folder name with file name
776 */
777 private static function maybe_activate_addon( $installed ) {
778 if ( ! $installed ) {
779 return;
780 }
781
782 $activate = activate_plugin( $installed );
783 if ( is_wp_error( $activate ) ) {
784 // Ignore the invalid header message that shows with nested plugins.
785 if ( $activate->get_error_code() !== 'no_plugin_header' ) {
786 echo json_encode( array( 'error' => $activate->get_error_message() ) );
787 wp_die();
788 }
789 }
790 }
791
792 /**
793 * Run security checks before installing
794 *
795 * @since 3.04.02
796 */
797 private static function install_addon_permissions() {
798 check_ajax_referer( 'frm_ajax', 'nonce' );
799
800 if ( ! current_user_can( 'activate_plugins' ) || ! isset( $_POST['plugin'] ) ) {
801 echo json_encode( true );
802 wp_die();
803 }
804 }
805
806 /**
807 * @since 3.04.03
808 * @deprecated 3.06
809 * @codeCoverageIgnore
810 * @return array
811 */
812 public static function error_for_license( $license ) {
813 return FrmDeprecated::error_for_license( $license );
814 }
815
816 /**
817 * @since 3.04.03
818 * @deprecated 3.06
819 * @codeCoverageIgnore
820 */
821 public static function get_pro_updater() {
822 return FrmDeprecated::get_pro_updater();
823 }
824
825 /**
826 * @since 3.04.03
827 * @deprecated 3.06
828 * @codeCoverageIgnore
829 *
830 * @return array
831 */
832 public static function get_addon_info( $license = '' ) {
833 return FrmDeprecated::get_addon_info( $license );
834 }
835
836 /**
837 * @since 3.04.03
838 * @deprecated 3.06
839 * @codeCoverageIgnore
840 *
841 * @return string
842 */
843 public static function get_cache_key( $license ) {
844 return FrmDeprecated::get_cache_key( $license );
845 }
846
847 /**
848 * @since 3.04.03
849 * @deprecated 3.06
850 * @codeCoverageIgnore
851 */
852 public static function reset_cached_addons( $license = '' ) {
853 FrmDeprecated::reset_cached_addons( $license );
854 }
855
856 /**
857 * @since 2.03.08
858 * @deprecated 3.04.03
859 * @codeCoverageIgnore
860 *
861 * @param boolean $return
862 * @param string $package
863 *
864 * @return boolean
865 */
866 public static function add_shorten_edd_filename_filter( $return, $package ) {
867 return FrmDeprecated::add_shorten_edd_filename_filter( $return, $package );
868 }
869
870 /**
871 * @since 2.03.08
872 * @deprecated 3.04.03
873 * @codeCoverageIgnore
874 *
875 * @param string $filename
876 * @param string $ext
877 *
878 * @return string
879 */
880 public static function shorten_edd_filename( $filename, $ext ) {
881 return FrmDeprecated::shorten_edd_filename( $filename, $ext );
882 }
883
884 /**
885 * @deprecated 3.04.03
886 * @codeCoverageIgnore
887 */
888 public static function get_licenses() {
889 FrmDeprecated::get_licenses();
890 }
891 }
892