Completed
Push — master ( 7c7246...01d385 )
by Stephanie
03:35
created

FrmAddonsController::license_settings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6667
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
3
class FrmAddonsController {
4
5
	public static function menu() {
6
		add_submenu_page( 'formidable', 'Formidable | '. __( 'AddOns', 'formidable' ), __( 'AddOns', 'formidable' ), 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' );
7
	}
8
9
	public static function list_addons() {
10
		$installed_addons = apply_filters( 'frm_installed_addons', array() );
11
12
		$pro_link = 'http://formidablepro.com/pricing';
13
		$addons = self::get_api_addons();
14
		if ( ! is_array( $addons ) ) {
15
			$addons = array(
16
				array( 'url' => $pro_link, 'name' => 'Formidable Pro', 'slug' => 'formidable_pro' ),
17
			);
18
		} else {
19
			$addons = $addons['products'];
20
		}
21
		$addons = array_reverse( $addons );
22
		$append_affiliate = '';
23
24
		$plugin_names = array(
25
			'formidable-pro' => 'formidable/pro', 'wp-multilingual' => 'formidable-wpml',
26
			'registration-lite' => 'formidable-registration', 'bootstrap-modal' => 'formidable-modal',
27
			'paypal-standard' => 'formidable-paypal', 'formidable-api' => 'formidable-api',
28
		);
29
30
		include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' );
31
	}
32
33
	public static function license_settings() {
34
		$plugins = apply_filters( 'frm_installed_addons', array() );
35
		if ( empty( $plugins ) ) {
36
			_e( 'There are no plugins on your site that require a license', 'formidable' );
37
			return;
38
		}
39
40
		include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' );
41
	}
42
43
	private static function get_api_addons() {
44
		$addons = get_transient( 'frm_api_addons' );
45
		if ( $addons !== false ) {
1 ignored issue
show
introduced by
Found "!== false". Use Yoda Condition checks, you must
Loading history...
46
			return $addons;
47
		}
48
49
		$url = 'https://formidablepro.com/edd-api/products?number=40';
50
51
		$arg_array = array(
52
			'body'      => array(
53
				'url'   => home_url(),
54
			),
55
			'timeout'   => 15,
56
			'sslverify' => false,
57
			'user-agent' => 'Formidable/' . FrmAppHelper::$plug_version . '; ' . home_url(),
58
		);
59
60
		$response = wp_remote_post( $url, $arg_array );
61
		$body = wp_remote_retrieve_body( $response );
62
		if ( ! is_wp_error( $response ) && ! is_wp_error( $body ) ) {
63
			$addons = json_decode( $body, true );
64
			set_transient( 'frm_api_addons', $addons, 60 * 60 * 24 * 5 ); // check every 5 days
65
			if ( is_array( $addons ) ) {
66
				return $addons;
67
			}
68
		}
69
70
		return false;
71
	}
72
}
73