1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// Exit if accessed directly |
4
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
5
|
|
|
exit; |
6
|
|
|
} |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Allows plugins to use their own update API. |
10
|
|
|
* |
11
|
|
|
* @author Easy Digital Downloads |
12
|
|
|
* @version 1.6.17 |
13
|
|
|
*/ |
14
|
|
|
class EDD_SL_Plugin_Updater { |
15
|
|
|
|
16
|
|
|
private $api_url = ''; |
17
|
|
|
private $api_data = array(); |
18
|
|
|
private $name = ''; |
19
|
|
|
private $slug = ''; |
20
|
|
|
private $version = ''; |
21
|
|
|
private $wp_override = false; |
22
|
|
|
private $cache_key = ''; |
23
|
|
|
|
24
|
|
|
private $health_check_timeout = 5; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class constructor. |
28
|
|
|
* |
29
|
|
|
* @uses plugin_basename() |
30
|
|
|
* @uses hook() |
31
|
|
|
* |
32
|
|
|
* @param string $_api_url The URL pointing to the custom API endpoint. |
33
|
|
|
* @param string $_plugin_file Path to the plugin file. |
34
|
|
|
* @param array $_api_data Optional data to send with API calls. |
35
|
|
|
*/ |
36
|
|
|
public function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
37
|
|
|
|
38
|
|
|
global $edd_plugin_data, $edd_plugin_url_available; |
39
|
|
|
|
40
|
|
|
$this->api_url = trailingslashit( $_api_url ); |
41
|
|
|
|
42
|
|
|
// Do a quick status check on this domain if we haven't already checked it. |
43
|
|
|
$store_hash = md5( $this->api_url ); |
44
|
|
|
if ( ! is_array( $edd_plugin_url_available ) || ! isset( $edd_plugin_url_available[ $store_hash ] ) ) { |
45
|
|
|
$test_url_parts = parse_url( $this->api_url ); |
46
|
|
|
|
47
|
|
|
$scheme = ! empty( $test_url_parts['scheme'] ) ? $test_url_parts['scheme'] : 'http'; |
48
|
|
|
$host = ! empty( $test_url_parts['host'] ) ? $test_url_parts['host'] : ''; |
49
|
|
|
$port = ! empty( $test_url_parts['port'] ) ? ':' . $test_url_parts['port'] : ''; |
50
|
|
|
|
51
|
|
|
if ( empty( $host ) ) { |
52
|
|
|
$edd_plugin_url_available[ $store_hash ] = false; |
53
|
|
|
} else { |
54
|
|
|
$test_url = $scheme . '://' . $host . $port; |
55
|
|
|
$response = wp_remote_get( |
|
|
|
|
56
|
|
|
$test_url, array( |
57
|
|
|
'timeout' => $this->health_check_timeout, |
58
|
|
|
'sslverify' => true, |
59
|
|
|
) |
60
|
|
|
); |
61
|
|
|
$edd_plugin_url_available[ $store_hash ] = is_wp_error( $response ) ? false : true; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if ( false === $edd_plugin_url_available[ $store_hash ] ) { |
66
|
|
|
return; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$this->api_data = $_api_data; |
|
|
|
|
70
|
|
|
$this->name = plugin_basename( $_plugin_file ); |
71
|
|
|
$this->slug = basename( $_plugin_file, '.php' ); |
72
|
|
|
$this->version = $_api_data['version']; |
73
|
|
|
$this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false; |
74
|
|
|
$this->beta = ! empty( $this->api_data['beta'] ) ? true : false; |
75
|
|
|
$this->cache_key = 'edd_sl_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ); |
76
|
|
|
|
77
|
|
|
$edd_plugin_data[ $this->slug ] = $this->api_data; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Fires after the $edd_plugin_data is setup. |
81
|
|
|
* |
82
|
|
|
* @since x.x.x |
83
|
|
|
* |
84
|
|
|
* @param array $edd_plugin_data Array of EDD SL plugin data. |
85
|
|
|
*/ |
86
|
|
|
do_action( 'post_edd_sl_plugin_updater_setup', $edd_plugin_data ); |
87
|
|
|
|
88
|
|
|
// Set up hooks. |
89
|
|
|
$this->init(); |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Set up WordPress filters to hook into WP's update process. |
95
|
|
|
* |
96
|
|
|
* @uses add_filter() |
97
|
|
|
* |
98
|
|
|
* @return void |
99
|
|
|
*/ |
100
|
|
|
public function init() { |
101
|
|
|
|
102
|
|
|
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
103
|
|
|
add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
104
|
|
|
remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10 ); |
105
|
|
|
add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); |
106
|
|
|
add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
107
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Check for Updates at the defined API endpoint and modify the update array. |
112
|
|
|
* |
113
|
|
|
* This function dives into the update API just when WordPress creates its update array, |
114
|
|
|
* then adds a custom API call and injects the custom plugin data retrieved from the API. |
115
|
|
|
* It is reassembled from parts of the native WordPress plugin update code. |
116
|
|
|
* See wp-includes/update.php line 121 for the original wp_update_plugins() function. |
117
|
|
|
* |
118
|
|
|
* @uses api_request() |
119
|
|
|
* |
120
|
|
|
* @param array $_transient_data Update array build by WordPress. |
121
|
|
|
* @return array Modified update array with custom plugin data. |
122
|
|
|
*/ |
123
|
|
|
public function check_update( $_transient_data ) { |
124
|
|
|
|
125
|
|
|
global $pagenow; |
126
|
|
|
|
127
|
|
|
if ( ! is_object( $_transient_data ) ) { |
128
|
|
|
$_transient_data = new stdClass(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
if ( 'plugins.php' == $pagenow && is_multisite() ) { |
132
|
|
|
return $_transient_data; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) { |
136
|
|
|
return $_transient_data; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
$version_info = $this->get_cached_version_info(); |
140
|
|
|
|
141
|
|
View Code Duplication |
if ( false === $version_info ) { |
|
|
|
|
142
|
|
|
$version_info = $this->api_request( |
143
|
|
|
'plugin_latest_version', array( |
144
|
|
|
'slug' => $this->slug, |
145
|
|
|
'beta' => $this->beta, |
146
|
|
|
) |
147
|
|
|
); |
148
|
|
|
|
149
|
|
|
$this->set_version_info_cache( $version_info ); |
|
|
|
|
150
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
154
|
|
|
|
155
|
|
|
if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
156
|
|
|
|
157
|
|
|
$_transient_data->response[ $this->name ] = $version_info; |
158
|
|
|
|
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
$_transient_data->last_checked = time(); |
162
|
|
|
$_transient_data->checked[ $this->name ] = $this->version; |
163
|
|
|
|
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
return $_transient_data; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise! |
171
|
|
|
* |
172
|
|
|
* @param string $file |
173
|
|
|
* @param array $plugin |
174
|
|
|
*/ |
175
|
|
|
public function show_update_notification( $file, $plugin ) { |
176
|
|
|
|
177
|
|
|
if ( is_network_admin() ) { |
178
|
|
|
return; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
if ( ! current_user_can( 'update_plugins' ) ) { |
182
|
|
|
return; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
if ( ! is_multisite() ) { |
186
|
|
|
return; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
if ( $this->name != $file ) { |
190
|
|
|
return; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
// Remove our filter on the site transient |
194
|
|
|
remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 ); |
195
|
|
|
|
196
|
|
|
$update_cache = get_site_transient( 'update_plugins' ); |
197
|
|
|
|
198
|
|
|
$update_cache = is_object( $update_cache ) ? $update_cache : new stdClass(); |
199
|
|
|
|
200
|
|
|
if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { |
201
|
|
|
|
202
|
|
|
$version_info = $this->get_cached_version_info(); |
203
|
|
|
|
204
|
|
View Code Duplication |
if ( false === $version_info ) { |
|
|
|
|
205
|
|
|
$version_info = $this->api_request( |
206
|
|
|
'plugin_latest_version', array( |
207
|
|
|
'slug' => $this->slug, |
208
|
|
|
'beta' => $this->beta, |
209
|
|
|
) |
210
|
|
|
); |
211
|
|
|
|
212
|
|
|
$this->set_version_info_cache( $version_info ); |
|
|
|
|
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
if ( ! is_object( $version_info ) ) { |
216
|
|
|
return; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
220
|
|
|
|
221
|
|
|
$update_cache->response[ $this->name ] = $version_info; |
222
|
|
|
|
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
$update_cache->last_checked = time(); |
226
|
|
|
$update_cache->checked[ $this->name ] = $this->version; |
227
|
|
|
|
228
|
|
|
set_site_transient( 'update_plugins', $update_cache ); |
229
|
|
|
|
230
|
|
|
} else { |
231
|
|
|
|
232
|
|
|
$version_info = $update_cache->response[ $this->name ]; |
233
|
|
|
|
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
// Restore our filter |
237
|
|
|
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
238
|
|
|
|
239
|
|
|
if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { |
240
|
|
|
|
241
|
|
|
// build a plugin list row, with update notification |
242
|
|
|
$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
|
|
|
|
243
|
|
|
// <tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"> |
244
|
|
|
echo '<tr class="plugin-update-tr" id="' . $this->slug . '-update" data-slug="' . $this->slug . '" data-plugin="' . $this->slug . '/' . $file . '">'; |
|
|
|
|
245
|
|
|
echo '<td colspan="3" class="plugin-update colspanchange">'; |
246
|
|
|
echo '<div class="update-message notice inline notice-warning notice-alt">'; |
247
|
|
|
|
248
|
|
|
$changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); |
249
|
|
|
|
250
|
|
|
if ( empty( $version_info->download_link ) ) { |
251
|
|
|
printf( |
252
|
|
|
__( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s.', 'give' ), |
253
|
|
|
esc_html( $version_info->name ), |
254
|
|
|
'<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">', |
255
|
|
|
esc_html( $version_info->new_version ), |
256
|
|
|
'</a>' |
257
|
|
|
); |
258
|
|
|
} else { |
259
|
|
|
printf( |
260
|
|
|
__( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.', 'give' ), |
261
|
|
|
esc_html( $version_info->name ), |
262
|
|
|
'<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">', |
263
|
|
|
esc_html( $version_info->new_version ), |
264
|
|
|
'</a>', |
265
|
|
|
'<a href="' . esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) . '">', |
266
|
|
|
'</a>' |
267
|
|
|
); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
do_action( "in_plugin_update_message-{$file}", $plugin, $version_info ); |
271
|
|
|
|
272
|
|
|
echo '</div></td></tr>'; |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Updates information on the "View version x.x details" page with custom data. |
278
|
|
|
* |
279
|
|
|
* @uses api_request() |
280
|
|
|
* |
281
|
|
|
* @param mixed $_data |
282
|
|
|
* @param string $_action |
283
|
|
|
* @param object $_args |
284
|
|
|
* @return object $_data |
285
|
|
|
*/ |
286
|
|
|
public function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
287
|
|
|
|
288
|
|
|
if ( $_action != 'plugin_information' ) { |
|
|
|
|
289
|
|
|
|
290
|
|
|
return $_data; |
291
|
|
|
|
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { |
295
|
|
|
|
296
|
|
|
return $_data; |
297
|
|
|
|
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
$to_send = array( |
301
|
|
|
'slug' => $this->slug, |
302
|
|
|
'is_ssl' => is_ssl(), |
303
|
|
|
'fields' => array( |
304
|
|
|
'banners' => array(), |
305
|
|
|
'reviews' => false, |
306
|
|
|
), |
307
|
|
|
); |
308
|
|
|
|
309
|
|
|
$cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ); |
310
|
|
|
|
311
|
|
|
// Get the transient where we store the api request for this plugin for 24 hours |
312
|
|
|
$edd_api_request_transient = $this->get_cached_version_info( $cache_key ); |
313
|
|
|
|
314
|
|
|
// If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now. |
315
|
|
|
if ( empty( $edd_api_request_transient ) ) { |
316
|
|
|
|
317
|
|
|
$api_response = $this->api_request( 'plugin_information', $to_send ); |
318
|
|
|
|
319
|
|
|
// Expires in 3 hours |
320
|
|
|
$this->set_version_info_cache( $api_response, $cache_key ); |
|
|
|
|
321
|
|
|
|
322
|
|
|
if ( false !== $api_response ) { |
323
|
|
|
$_data = $api_response; |
324
|
|
|
} |
325
|
|
|
} else { |
326
|
|
|
$_data = $edd_api_request_transient; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
// Convert sections into an associative array, since we're getting an object, but Core expects an array. |
330
|
|
View Code Duplication |
if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) { |
|
|
|
|
331
|
|
|
$new_sections = array(); |
332
|
|
|
foreach ( $_data->sections as $key => $value ) { |
333
|
|
|
$new_sections[ $key ] = $value; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
$_data->sections = $new_sections; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
// Convert banners into an associative array, since we're getting an object, but Core expects an array. |
340
|
|
View Code Duplication |
if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) { |
|
|
|
|
341
|
|
|
$new_banners = array(); |
342
|
|
|
foreach ( $_data->banners as $key => $value ) { |
343
|
|
|
$new_banners[ $key ] = $value; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
$_data->banners = $new_banners; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
return $_data; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* Disable SSL verification in order to prevent download update failures |
354
|
|
|
* |
355
|
|
|
* @param array $args |
356
|
|
|
* @param string $url |
357
|
|
|
* @return object $array |
358
|
|
|
*/ |
359
|
|
|
public function http_request_args( $args, $url ) { |
360
|
|
|
|
361
|
|
|
$verify_ssl = $this->verify_ssl(); |
362
|
|
|
if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
|
|
|
|
363
|
|
|
$args['sslverify'] = $verify_ssl; |
364
|
|
|
} |
365
|
|
|
return $args; |
366
|
|
|
|
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* Calls the API and, if successfull, returns the object delivered by the API. |
371
|
|
|
* |
372
|
|
|
* @uses get_bloginfo() |
373
|
|
|
* @uses wp_remote_post() |
374
|
|
|
* @uses is_wp_error() |
375
|
|
|
* |
376
|
|
|
* @param string $_action The requested action. |
377
|
|
|
* @param array $_data Parameters for the API action. |
378
|
|
|
* @return false|object |
379
|
|
|
*/ |
380
|
|
|
private function api_request( $_action, $_data ) { |
|
|
|
|
381
|
|
|
|
382
|
|
|
global $wp_version; |
383
|
|
|
|
384
|
|
|
$data = array_merge( $this->api_data, $_data ); |
385
|
|
|
|
386
|
|
|
if ( $data['slug'] != $this->slug ) { |
387
|
|
|
return; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
if ( $this->api_url == trailingslashit( home_url() ) ) { |
391
|
|
|
return false; // Don't allow a plugin to ping itself |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
$api_params = array( |
395
|
|
|
'edd_action' => 'get_version', |
396
|
|
|
'license' => ! empty( $data['license'] ) ? $data['license'] : '', |
397
|
|
|
'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
398
|
|
|
'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
399
|
|
|
'version' => isset( $data['version'] ) ? $data['version'] : false, |
400
|
|
|
'slug' => $data['slug'], |
401
|
|
|
'author' => $data['author'], |
402
|
|
|
'url' => home_url(), |
403
|
|
|
'beta' => ! empty( $data['beta'] ), |
404
|
|
|
); |
405
|
|
|
|
406
|
|
|
$verify_ssl = $this->verify_ssl(); |
407
|
|
|
$request = wp_remote_post( |
408
|
|
|
$this->api_url, array( |
409
|
|
|
'timeout' => 15, |
410
|
|
|
'sslverify' => $verify_ssl, |
411
|
|
|
'body' => $api_params, |
412
|
|
|
) |
413
|
|
|
); |
414
|
|
|
|
415
|
|
|
if ( ! is_wp_error( $request ) ) { |
416
|
|
|
$request = json_decode( wp_remote_retrieve_body( $request ) ); |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
if ( $request && isset( $request->sections ) ) { |
420
|
|
|
$request->sections = maybe_unserialize( $request->sections ); |
421
|
|
|
} else { |
422
|
|
|
$request = false; |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
if ( $request && isset( $request->banners ) ) { |
426
|
|
|
$request->banners = maybe_unserialize( $request->banners ); |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
if ( ! empty( $request->sections ) ) { |
430
|
|
|
foreach ( $request->sections as $key => $section ) { |
431
|
|
|
$request->$key = (array) $section; |
432
|
|
|
} |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
return $request; |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
public function show_changelog() { |
439
|
|
|
|
440
|
|
|
global $edd_plugin_data; |
441
|
|
|
|
442
|
|
|
if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { |
|
|
|
|
443
|
|
|
return; |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
if ( empty( $_REQUEST['plugin'] ) ) { |
|
|
|
|
447
|
|
|
return; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
if ( empty( $_REQUEST['slug'] ) ) { |
|
|
|
|
451
|
|
|
return; |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
if ( ! current_user_can( 'update_plugins' ) ) { |
455
|
|
|
wp_die( __( 'You do not have permission to install plugin updates', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
$data = $edd_plugin_data[ $_REQUEST['slug'] ]; |
|
|
|
|
459
|
|
|
$beta = ! empty( $data['beta'] ) ? true : false; |
460
|
|
|
$cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $beta . '_version_info' ); |
|
|
|
|
461
|
|
|
$version_info = $this->get_cached_version_info( $cache_key ); |
462
|
|
|
|
463
|
|
|
if ( false === $version_info ) { |
464
|
|
|
|
465
|
|
|
$api_params = array( |
466
|
|
|
'edd_action' => 'get_version', |
467
|
|
|
'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
468
|
|
|
'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
469
|
|
|
'slug' => $_REQUEST['slug'], |
|
|
|
|
470
|
|
|
'author' => $data['author'], |
471
|
|
|
'url' => home_url(), |
472
|
|
|
'beta' => ! empty( $data['beta'] ), |
473
|
|
|
); |
474
|
|
|
|
475
|
|
|
$verify_ssl = $this->verify_ssl(); |
476
|
|
|
$request = wp_remote_post( |
477
|
|
|
$this->api_url, array( |
478
|
|
|
'timeout' => 15, |
479
|
|
|
'sslverify' => $verify_ssl, |
480
|
|
|
'body' => $api_params, |
481
|
|
|
) |
482
|
|
|
); |
483
|
|
|
|
484
|
|
|
if ( ! is_wp_error( $request ) ) { |
485
|
|
|
$version_info = json_decode( wp_remote_retrieve_body( $request ) ); |
486
|
|
|
} |
487
|
|
|
|
488
|
|
|
if ( ! empty( $version_info ) && isset( $version_info->sections ) ) { |
489
|
|
|
$version_info->sections = maybe_unserialize( $version_info->sections ); |
490
|
|
|
} else { |
491
|
|
|
$version_info = false; |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
if ( ! empty( $version_info ) ) { |
495
|
|
|
foreach ( $version_info->sections as $key => $section ) { |
496
|
|
|
$version_info->$key = (array) $section; |
497
|
|
|
} |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
$this->set_version_info_cache( $version_info, $cache_key ); |
501
|
|
|
|
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
if ( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) { |
505
|
|
|
echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>'; |
|
|
|
|
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
exit; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
public function get_cached_version_info( $cache_key = '' ) { |
512
|
|
|
|
513
|
|
|
if ( empty( $cache_key ) ) { |
514
|
|
|
$cache_key = $this->cache_key; |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
$cache = get_option( $cache_key ); |
518
|
|
|
|
519
|
|
|
if ( empty( $cache['timeout'] ) || time() > $cache['timeout'] ) { |
520
|
|
|
return false; // Cache is expired |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
return json_decode( $cache['value'] ); |
524
|
|
|
|
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
public function set_version_info_cache( $value = '', $cache_key = '' ) { |
528
|
|
|
|
529
|
|
|
if ( empty( $cache_key ) ) { |
530
|
|
|
$cache_key = $this->cache_key; |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
$data = array( |
534
|
|
|
'timeout' => strtotime( '+3 hours', time() ), |
535
|
|
|
'value' => json_encode( $value ), |
536
|
|
|
); |
537
|
|
|
|
538
|
|
|
update_option( $cache_key, $data, 'no' ); |
539
|
|
|
|
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
/** |
543
|
|
|
* Returns if the SSL of the store should be verified. |
544
|
|
|
* |
545
|
|
|
* @since 1.6.13 |
546
|
|
|
* @return bool |
547
|
|
|
*/ |
548
|
|
|
private function verify_ssl() { |
549
|
|
|
return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this ); |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
} |
553
|
|
|
|