Completed
Push — master ( ca3d95...790a2a )
by Stephanie
02:56
created

FrmAddonsController::upgrade_to_pro()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
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 = self::get_error_from_response( $addons );
22
		if ( isset( $addons['error'] ) ) {
23
			unset( $addons['error'] );
24
		}
25
		self::prepare_addons( $addons );
26
27
		$pricing = FrmAppHelper::admin_upgrade_link( 'addons' );
28
29
		include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' );
30
	}
31
32
	public static function license_settings() {
33
		$plugins = apply_filters( 'frm_installed_addons', array() );
34
		if ( empty( $plugins ) ) {
35
			esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
36
			return;
37
		}
38
39
		ksort( $plugins );
40
41
		include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' );
42
	}
43
44
	private static function get_api_addons() {
45
		$license = '';
46
		$edd_update = self::get_pro_updater();
47
		if ( ! empty( $edd_update ) ) {
48
			$license = $edd_update->license;
49
		}
50
51
		$addons = self::get_addon_info( $license );
52
53
		if ( empty( $addons ) ) {
54
			$addons = self::fallback_plugin_list();
55
		} else {
56
			foreach ( $addons as $k => $addon ) {
57
				if ( empty( $addon['excerpt'] ) && $k !== 'error' ) {
58
					unset( $addons[ $k ] );
59
				}
60
			}
61
		}
62
63
		return $addons;
64
	}
65
66
	/**
67
	 * @since 3.04.03
68
	 */
69
	public static function get_pro_updater() {
70
		if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::get_updater' ) ) {
71
			return FrmProAppHelper::get_updater();
72
		}
73
74
		return false;
75
	}
76
77
	/**
78
	 * If the API is unable to connect, show something on the addons page
79
	 *
80
	 * @since 3.04.03
81
	 * @return array
82
	 */
83
	private static function fallback_plugin_list() {
84
		return array(
85
			'formidable-pro' => array(
86
				'title'   => 'Formidable Pro',
87
				'link'    => 'pricing/',
88
				'docs'    => '',
89
				'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.',
90
			),
91
			'mailchimp' => array(
92
				'title'   => 'MailChimp Forms',
93
				'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.',
94
			),
95
			'registration' => array(
96
				'title'   => 'User Registration Forms',
97
				'link'    => 'downloads/user-registration/',
98
				'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.',
99
			),
100
			'paypal' => array(
101
				'title'   => 'PayPal Standard Forms',
102
				'link'    => 'downloads/paypal-standard/',
103
				'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.',
104
			),
105
			'stripe' => array(
106
				'title'   => 'Stripe Forms',
107
				'docs'    => 'knowledgebase/stripe/',
108
				'excerpt' => 'Any Formidable forms on your site can accept credit card payments without users ever leaving your site.',
109
			),
110
			'authorize-net' => array(
111
				'title'   => 'Authorize.net AIM Forms',
112
				'link'    => 'downloads/authorize-net-aim/',
113
				'docs'    => 'knowledgebase/authorize-net-aim/',
114
				'excerpt' => 'Accept one-time payments directly on your site, using Authorize.net AIM.',
115
			),
116
			'woocommerce' => array(
117
				'title'   => 'WooCommerce Forms',
118
				'excerpt' => 'Use a Formidable form on your WooCommerce product pages.',
119
			),
120
			'autoresponder' => array(
121
				'title'   => 'Form Action Automation',
122
				'docs'    => 'knowledgebase/schedule-autoresponder/',
123
				'excerpt' => 'Schedule email notifications, SMS messages, and API actions.',
124
			),
125
			'modal' => array(
126
				'title'   => 'Bootstrap Modal Forms',
127
				'link'    => 'downloads/bootstrap-modal/',
128
				'docs'    => 'knowledgebase/bootstrap-modal/',
129
				'excerpt' => 'Open a view or form in a Bootstrap popup.',
130
			),
131
			'bootstrap' => array(
132
				'title'   => 'Bootstrap Style Forms',
133
				'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.',
134
			),
135
			'zapier' => array(
136
				'title'   => 'Zapier Forms',
137
				'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.',
138
			),
139
			'signature' => array(
140
				'title'   => 'Digital Signature Forms',
141
				'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.',
142
			),
143
			'api' => array(
144
				'title'   => 'Formidable Forms API',
145
				'link'    => 'downloads/formidable-api/',
146
				'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.',
147
			),
148
			'twilio' => array(
149
				'title'   => 'Twilio SMS Forms',
150
				'docs'    => 'knowledgebase/twilio-add-on/',
151
				'excerpt' => 'Allow users to text their votes for polls created by Formidable Forms, or send SMS notifications when entries are submitted or updated.',
152
			),
153
		);
154
	}
155
156
	/**
157
	 * If Pro is missing but has been authenticated, include a download URL
158
	 *
159
	 * @since 3.04.03
160
	 * @return string
161
	 */
162
	public static function get_pro_download_url() {
163
		$pro_cred_store  = 'frmpro-credentials';
164
		$pro_wpmu_store  = 'frmpro-wpmu-sitewide';
165
		if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) {
166
			$creds = get_site_option( $pro_cred_store );
167
		} else {
168
			$creds = get_option( $pro_cred_store );
169
		}
170
171
		if ( empty( $creds ) || ! is_array( $creds ) || ! isset( $creds['license'] ) ) {
172
			return '';
173
		}
174
175
		$license = $creds['license'];
176
		if ( empty( $license ) ) {
177
			return '';
178
		}
179
180
		if ( strpos( $license, '-' ) ) {
181
			// this is a fix for licenses saved in the past
182
			$license = strtoupper( $license );
183
		}
184
185
		$downloads = self::get_addon_info( $license );
186
		$pro = isset( $downloads['93790'] ) ? $downloads['93790'] : array();
187
188
		return isset( $pro['url'] ) ? $pro['url'] : '';
189
	}
190
191
	/**
192
	 * @since 3.04.03
193
	 * @return array
194
	 */
195
	public static function get_addon_info( $license = '' ) {
196
		$addons = array();
0 ignored issues
show
Unused Code introduced by
$addons is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
197
		$url = 'https://formidableforms.com/wp-json/s11edd/v1/updates/';
198
		if ( ! empty( $license ) ) {
199
			$url .= '?l=' . urlencode( base64_encode( $license ) );
200
		}
201
202
		$addons = self::get_cached_addons( $license );
203
		if ( ! empty( $addons ) ) {
204
			return $addons;
205
		}
206
207
		$response = wp_remote_get( $url );
208
		if ( is_array( $response ) && ! is_wp_error( $response ) ) {
209
		    $addons = $response['body'];
210
			if ( ! empty( $addons ) ) {
211
				$addons = json_decode( $addons, true );
212
213
				$skip_categories = array( 'WordPress Form Templates', 'WordPress Form Style Templates' );
214
				foreach ( $addons as $k => $addon ) {
215
					if ( ! isset( $addon['categories'] ) ) {
216
						continue;
217
					}
218
					$cats = array_intersect( $skip_categories, $addon['categories'] );
219
					if ( ! empty( $cats ) ) {
220
						unset( $addons[ $k ] );
221
					}
222
				}
223
224
				self::set_cached_addons( $addons, $license );
225
			}
226
		}
227
228
		return $addons;
229
	}
230
231
	/**
232
	 * @since 3.04.03
233
	 * @return array
234
	 */
235
	private static function get_cached_addons( $license = '' ) {
236
		$cache_key = self::get_cache_key( $license );
237
		$cache     = get_option( $cache_key );
238
239 View Code Duplication
		if ( empty( $cache ) || empty( $cache['timeout'] ) || current_time( 'timestamp' ) > $cache['timeout'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
240
			return false; // Cache is expired
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by FrmAddonsController::get_cached_addons of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
241
		}
242
243
		return json_decode( $cache['value'], true );
244
	}
245
246
	/**
247
	 * @since 3.04.03
248
	 */
249 View Code Duplication
	private static function set_cached_addons( $addons, $license = '' ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
250
		$cache_key = self::get_cache_key( $license );
251
		$data = array(
252
			'timeout' => strtotime( '+6 hours', current_time( 'timestamp' ) ),
253
			'value'   => json_encode( $addons ),
254
		);
255
256
		update_option( $cache_key, $data, 'no' );
257
	}
258
259
	/**
260
	 * @since 3.04.03
261
	 */
262
	public static function reset_cached_addons( $license = '' ) {
263
		delete_option( self::get_cache_key( $license ) );
264
	}
265
266
	/**
267
	 * @since 3.04.03
268
	 * @return string
269
	 */
270
	public static function get_cache_key( $license ) {
271
		return 'frm_addons_l' . ( empty( $license ) ? '' : md5( $license ) );
272
	}
273
274
	/**
275
	 * @since 3.04.03
276
	 * @return array
277
	 */
278
	public static function error_for_license( $license ) {
279
		$errors = array();
280
		if ( ! empty( $license ) ) {
281
			$addons = self::get_addon_info( $license );
282
			$errors = self::get_error_from_response( $addons );
283
		}
284
		return $errors;
285
	}
286
287
	/**
288
	 * @since 3.04.03
289
	 * @return array
290
	 */
291
	private static function get_error_from_response( $addons ) {
292
		$errors = array();
293
		if ( isset( $addons['error'] ) ) {
294
			$errors[] = $addons['error']['message'];
295
			do_action( 'frm_license_error', $addons['error'] );
296
		}
297
		return $errors;
298
	}
299
300
	/**
301
	 * @since 3.04.03
302
	 */
303
	public static function check_update( $transient ) {
304
		if ( ! is_object( $transient ) ) {
305
			$transient = new stdClass;
306
		}
307
308
		$installed_addons = apply_filters( 'frm_installed_addons', array() );
309
		if ( empty( $installed_addons ) ) {
310
			return $transient;
311
		}
312
313
		$version_info = self::fill_update_addon_info( $installed_addons );
314
315
		$transient->last_checked = time();
316
317
		$wp_plugins = get_plugins();
318
319
		foreach ( $version_info as $id => $plugin ) {
320
			$plugin = (object) $plugin;
321
322
			if ( ! isset( $plugin->new_version ) || ! isset( $plugin->package ) ) {
323
				continue;
324
			}
325
326
			$folder = $plugin->plugin;
327
			if ( empty( $folder ) ) {
328
				continue;
329
			}
330
331
			$wp_plugin  = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array();
332
			$wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0';
333
334
			if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) {
335
				$slug = explode( '/', $folder );
336
				$plugin->slug = $slug[0];
337
				$transient->response[ $folder ] = $plugin;
338
			}
339
340
			$transient->checked[ $folder ] = $wp_version;
341
342
		}
343
344
		return $transient;
345
	}
346
347
	/**
348
	 * @since 3.04.03
349
	 *
350
	 * @param array $installed_addons
351
	 *
352
	 * @return array
353
	 */
354
	private static function fill_update_addon_info( $installed_addons ) {
355
		$checked_licenses = array();
356
		$version_info     = array();
357
358
		foreach ( $installed_addons as $addon ) {
359
			if ( $addon->store_url !== 'https://formidableforms.com' ) {
360
				// check if this is a third-party addon
361
				continue;
362
			}
363
364
			$new_license = $addon->license;
365
			if ( empty( $new_license ) || in_array( $new_license, $checked_licenses ) ) {
366
				continue;
367
			}
368
369
			$checked_licenses[] = $new_license;
370
371
			if ( empty( $version_info ) ) {
372
				$version_info = self::get_addon_info( $new_license );
373
				continue;
374
			}
375
376
			$plugin = self::get_addon_for_license( $version_info, $addon );
377
			if ( empty( $plugin ) ) {
378
				continue;
379
			}
380
381
			$download_id = isset( $plugin['id'] ) ? $plugin['id'] : 0;
382
			if ( ! empty( $download_id ) && ! isset( $version_info[ $download_id ]['package'] ) ) {
383
				// if this addon is using its own license, get the update url
384
				$addon_info = self::get_addon_info( $new_license );
385
386
				$version_info[ $download_id ] = $addon_info[ $download_id ];
387
				if ( isset( $addon_info['error'] ) ) {
388
					$version_info[ $download_id ]['error'] = array(
389
						'message' => $addon_info['error']['message'],
390
						'code'    => $addon_info['error']['code'],
391
					);
392
				}
393
			}
394
		}
395
396
		return $version_info;
397
	}
398
399
	/**
400
	 * @since 3.04.03
401
	 * @param array $addons
402
	 * @param object $license The FrmAddon object
403
	 * @return array
404
	 */
405
	public static function get_addon_for_license( $addons, $license ) {
406
		$download_id = $license->download_id;
407
		$plugin = array();
408
		if ( empty( $download_id ) ) {
409
			foreach ( $addons as $addon ) {
410
				if ( strtolower( $license->plugin_name ) == strtolower( $addon['title'] ) ) {
411
					return $addon;
412
				}
413
			}
414
		} elseif ( isset( $addons[ $download_id ] ) ) {
415
			$plugin = $addons[ $download_id ];
416
		}
417
418
		return $plugin;
419
	}
420
421
	private static function prepare_addons( &$addons ) {
422
		$activate_url = '';
423
		if ( current_user_can( 'activate_plugins' ) ) {
424
			$activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) );
425
		}
426
427
		$loop_addons = $addons;
428
		foreach ( $loop_addons as $id => $addon ) {
429
			if ( is_numeric( $id ) ) {
430
				$slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] );
431
				$file_name = $addon['plugin'];
432
			} else {
433
				$slug = $id;
434
				if ( isset( $addon['file'] ) ) {
435
					$base_file = $addon['file'];
436
				} else {
437
					$base_file = 'formidable-' . $slug;
438
				}
439
				$file_name = $base_file . '/' . $base_file . '.php';
440
			}
441
442
			$addon['installed']    = file_exists( WP_PLUGIN_DIR . '/' . $file_name );
443
			$addon['activate_url'] = '';
444
445
			if ( $addon['installed'] && ! empty( $activate_url ) && ! is_plugin_active( $file_name ) ) {
446
				$addon['activate_url'] = add_query_arg(
447
					array(
448
						'_wpnonce'    => wp_create_nonce( 'activate-plugin_' . $file_name ),
449
						'plugin'      => $file_name,
450
					),
451
					$activate_url
452
				);
453
			}
454
455
			if ( ! isset( $addon['docs'] ) ) {
456
				$addon['docs'] = 'knowledgebase/formidable-' . $slug . '/';
457
			}
458
			self::prepare_addon_link( $addon['docs'] );
459
460
			if ( ! isset( $addon['link'] ) ) {
461
				$addon['link'] = 'downloads/' . $slug . '/';
462
			}
463
			self::prepare_addon_link( $addon['link'] );
464
465
			self::set_addon_status( $addon );
466
			$addons[ $id ] = $addon;
467
		}
468
	}
469
470
	/**
471
	 * @since 3.04.02
472
	 */
473
	private static function prepare_addon_link( &$link ) {
474
		$site_url = 'https://formidableforms.com/';
475
		if ( strpos( $link, 'http' ) !== 0 ) {
476
			$link = $site_url . $link;
477
		}
478
		$link = FrmAppHelper::make_affiliate_url( $link );
479
		$query_args = array(
480
			'utm_source'   => 'WordPress',
481
			'utm_medium'   => 'addons',
482
			'utm_campaign' => 'liteplugin',
483
		);
484
		$link = add_query_arg( $query_args, $link );
485
	}
486
487
	/**
488
	 * Add the status to the addon array. Status options are:
489
	 * installed, active, not installed
490
	 *
491
	 * @since 3.04.02
492
	 */
493
	private static function set_addon_status( &$addon ) {
494
		if ( ! empty( $addon['activate_url'] ) ) {
495
			$addon['status'] = array(
496
				'type'  => 'installed',
497
				'label' => __( 'Installed', 'formidable' ),
498
			);
499
		} elseif ( $addon['installed'] ) {
500
			$addon['status'] = array(
501
				'type'  => 'active',
502
				'label' => __( 'Active', 'formidable' ),
503
			);
504
		} else {
505
			$addon['status'] = array(
506
				'type'  => 'not-installed',
507
				'label' => __( 'Not Installed', 'formidable' ),
508
			);
509
		}
510
	}
511
512
	public static function upgrade_to_pro() {
513
		$pro_pricing = self::prepare_pro_info();
514
515
		include( FrmAppHelper::plugin_path() . '/classes/views/addons/upgrade_to_pro.php' );
516
	}
517
518
	private static function prepare_pro_info() {
519
		return array(
520
			'personal'     => array(
521
				'id'       => 2,
522
				'download' => 19367654,
523
				'price'    => '49.00',
524
				'name'     => 'Personal',
525
			),
526
			'professional' => array(
527
				'id'       => 0,
528
				'download' => 19367001,
529
				'price'    => '99.00',
530
				'name'     => 'Creator',
531
			),
532
			'smallbusiness' => array(
533
				'id'       => 0,
534
				'download' => 19366995,
535
				'price'    => '199.00',
536
				'name'     => 'Business',
537
			),
538
			'enterprise'   => array(
539
				'id'       => 0,
540
				'download' => 19366992,
541
				'price'    => '399.00',
542
				'name'     => 'Enterprise',
543
			),
544
		);
545
	}
546
547
	/**
548
	 * @since 3.04.02
549
	 */
550
	public static function ajax_install_addon() {
551
552
		self::install_addon_permissions();
553
554
		// Set the current screen to avoid undefined notices.
555
		global $hook_suffix;
556
		set_current_screen();
557
558
		self::maybe_show_cred_form();
559
560
		$installed = self::install_addon();
561
		self::maybe_activate_addon( $installed );
562
563
		// Send back a response.
564
		echo json_encode( true );
565
		wp_die();
566
	}
567
568
	/**
569
	 * @since 3.04.02
570
	 */
571
	private static function maybe_show_cred_form() {
572
		// Start output bufferring to catch the filesystem form if credentials are needed.
573
		ob_start();
574
575
		$show_form = false;
576
		$method = '';
577
		$url    = add_query_arg( array( 'page' => 'formidable-settings' ), admin_url( 'admin.php' ) );
578
		$url    = esc_url_raw( $url );
579
		$creds  = request_filesystem_credentials( $url, $method, false, false, null );
580
581
		if ( false === $creds ) {
582
			$show_form = true;
583
		} elseif ( ! WP_Filesystem( $creds ) ) {
584
			request_filesystem_credentials( $url, $method, true, false, null );
585
			$show_form = true;
586
		}
587
588
		if ( $show_form ) {
589
			$form = ob_get_clean();
0 ignored issues
show
Unused Code introduced by
$form is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
590
			//TODO: test this: echo json_encode( array( 'form' => $form ) );
591
			echo json_encode( array( 'form' => __( 'Sorry, you\'re site requires FTP authentication. Please install plugins manaully.', 'formidable' ) ) );
592
			wp_die();
593
		}
594
595
		ob_end_clean();
596
	}
597
598
	/**
599
	 * We do not need any extra credentials if we have gotten this far,
600
	 * so let's install the plugin.
601
	 *
602
	 * @since 3.04.02
603
	 */
604
	private static function install_addon() {
605
		require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
606
607
		$download_url = esc_url_raw( $_POST['plugin'] );
608
609
		// Create the plugin upgrader with our custom skin.
610
		$installer = new Plugin_Upgrader( new FrmInstallerSkin() );
611
		$installer->install( $download_url );
612
613
		// Flush the cache and return the newly installed plugin basename.
614
		wp_cache_flush();
615
		return $installer->plugin_info();
616
	}
617
618
	/**
619
	 * @since 3.04.02
620
	 */
621
	private static function maybe_activate_addon( $installed ) {
622
		if ( ! $installed ) {
623
			return;
624
		}
625
626
		$activate = activate_plugin( $installed );
627
		if ( is_wp_error( $activate ) ) {
628
			echo json_encode( array( 'error' => $activate->get_error_message() ) );
629
			wp_die();
630
		}
631
	}
632
633
	/**
634
	 * Run security checks before installing
635
	 *
636
	 * @since 3.04.02
637
	 */
638
	private static function install_addon_permissions() {
639
		check_ajax_referer( 'frm_ajax', 'nonce' );
640
641
		if ( ! current_user_can( 'activate_plugins' ) || ! isset( $_POST['plugin'] ) ) {
642
			echo json_encode( true );
643
			wp_die();
644
		}
645
	}
646
647
	/**
648
	 * @since 2.03.08
649
	 * @deprecated 3.04.03
650
	 * @codeCoverageIgnore
651
	 *
652
	 * @param boolean $return
653
	 * @param string $package
654
	 *
655
	 * @return boolean
656
	 */
657
	public static function add_shorten_edd_filename_filter( $return, $package ) {
658
		return FrmDeprecated::add_shorten_edd_filename_filter( $return, $package );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::add_shorten_edd_filename_filter() has been deprecated with message: 3.04.03

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
659
	}
660
661
	/**
662
	 * @since 2.03.08
663
	 * @deprecated 3.04.03
664
	 * @codeCoverageIgnore
665
	 *
666
	 * @param string $filename
667
	 * @param string $ext
668
	 *
669
	 * @return string
670
	 */
671
	public static function shorten_edd_filename( $filename, $ext ) {
672
		return FrmDeprecated::shorten_edd_filename( $filename, $ext );
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::shorten_edd_filename() has been deprecated with message: 3.04.03

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
673
	}
674
675
	/**
676
	 * @deprecated 3.04.03
677
	 * @codeCoverageIgnore
678
	 */
679
	public static function get_licenses() {
680
		FrmDeprecated::get_licenses();
1 ignored issue
show
Deprecated Code introduced by
The method FrmDeprecated::get_licenses() has been deprecated with message: 3.04.03

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
681
	}
682
}
683