1 | <?php |
||
12 | |||
13 | class BD_EDD_API_Wrapper { |
||
14 | /** |
||
15 | * Store url. |
||
16 | * |
||
17 | * @since 5.0 |
||
18 | */ |
||
19 | const STORE_URL = 'http://bulkwp.com'; |
||
20 | |||
21 | /** |
||
22 | * Check license. |
||
23 | * |
||
24 | * @since 5.0 |
||
25 | * @static |
||
26 | * |
||
27 | * @param string $addon Addon name |
||
28 | * @param string $license The license code |
||
29 | * |
||
30 | * @return array|false False if request fails, API response otherwise |
||
31 | */ |
||
32 | public static function check_license( $addon, $license ) { |
||
33 | $api_params = array( |
||
34 | 'edd_action' => 'check_license', |
||
35 | 'license' => trim( $license ), |
||
36 | 'item_name' => urlencode( $addon ), |
||
37 | 'url' => home_url(), |
||
38 | ); |
||
39 | |||
40 | $license_data = array( |
||
41 | 'license' => $license, |
||
42 | 'item_name' => $addon, |
||
43 | 'validity' => 'invalid', |
||
44 | ); |
||
45 | |||
46 | $response = self::call_edd_api( $api_params ); |
||
47 | |||
48 | if ( $response && isset( $response->license ) ) { |
||
49 | if ( 'valid' == $response->license ) { |
||
50 | $license_data['license'] = $license; |
||
51 | $license_data['validity'] = 'valid'; |
||
52 | $license_data['expires'] = $response->expires; |
||
53 | $license_data['addon-name'] = $response->item_name; |
||
54 | } elseif ( 'invalid' == $response->license ) { |
||
55 | $license_data['validity'] = 'invalid'; |
||
56 | } elseif ( 'site_inactive' == $response->license ) { |
||
57 | $license_data['validity'] = 'invalid'; |
||
58 | } |
||
59 | |||
60 | return $license_data; |
||
61 | } |
||
62 | |||
63 | return false; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Activate license. |
||
68 | * |
||
69 | * @since 5.0 |
||
70 | * @static |
||
71 | * |
||
72 | * @param string $addon The addon that needs to be activated |
||
73 | * @param string $license The license code |
||
74 | * |
||
75 | * @return array|false False if request fails, License info otherwise |
||
76 | */ |
||
77 | public static function activate_license( $addon, $license ) { |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Deactivate License. |
||
113 | * |
||
114 | * @since 5.0 |
||
115 | * @static |
||
116 | * |
||
117 | * @param string $addon The addon that needs to be deactivated |
||
118 | * @param string $license The license code |
||
119 | * |
||
120 | * @return bool True if deactivated, False otherwise |
||
121 | */ |
||
122 | public static function deactivate_license( $addon, $license ) { |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Call the EDD API. |
||
143 | * |
||
144 | * @since 5.0 |
||
145 | * @static |
||
146 | * @access private |
||
147 | * |
||
148 | * @param array $api_params Parameters for API |
||
149 | * |
||
150 | * @return array|bool $license_data False if request fails, API response otherwise |
||
151 | */ |
||
152 | private static function call_edd_api( $api_params ) { |
||
153 | $response = wp_remote_get( add_query_arg( $api_params, self::STORE_URL ), array( 'timeout' => 15, 'sslverify' => false ) ); |
||
154 | |||
155 | // make sure the response came back okay |
||
156 | if ( is_wp_error( $response ) ) { |
||
165 |