PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.24.1
Advanced Ads – Ad Manager & AdSense v1.24.1
2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / classes / EDD_SL_Plugin_Updater.php
advanced-ads / classes Last commit date
EDD_SL_Plugin_Updater.php 5 years ago ad-ajax.php 5 years ago ad-debug.php 6 years ago ad-health-notices.php 6 years ago ad-model.php 5 years ago ad-select.php 9 years ago ad.php 5 years ago ad_ajax_callbacks.php 5 years ago ad_group.php 5 years ago ad_placements.php 5 years ago ad_type_abstract.php 5 years ago ad_type_content.php 5 years ago ad_type_dummy.php 5 years ago ad_type_group.php 5 years ago ad_type_image.php 5 years ago ad_type_plain.php 5 years ago checks.php 5 years ago compatibility.php 5 years ago display-conditions.php 5 years ago filesystem.php 8 years ago frontend-notices.php 6 years ago frontend_checks.php 5 years ago plugin.php 5 years ago upgrades.php 6 years ago utils.php 5 years ago visitor-conditions.php 6 years ago widget.php 6 years ago
EDD_SL_Plugin_Updater.php
617 lines
1 <?php
2
3 // Exit if accessed directly
4 if ( ! defined( 'ABSPATH' ) ) exit;
5
6 /**
7 * Allows plugins to use their own update API.
8 *
9 * @author Easy Digital Downloads
10 * @version 1.8.0
11 */
12 class ADVADS_SL_Plugin_Updater {
13
14 private $api_url = '';
15 private $api_data = array();
16 private $name = '';
17 private $slug = '';
18 private $version = '';
19 private $wp_override = false;
20 private $cache_key = '';
21
22 private $health_check_timeout = 5;
23
24 /**
25 * Class constructor.
26 *
27 * @uses plugin_basename()
28 * @uses hook()
29 *
30 * @param string $_api_url The URL pointing to the custom API endpoint.
31 * @param string $_plugin_file Path to the plugin file.
32 * @param array $_api_data Optional data to send with API calls.
33 */
34 public function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
35
36 global $edd_plugin_data;
37
38 $this->api_url = trailingslashit( $_api_url );
39 $this->api_data = $_api_data;
40 $this->name = plugin_basename( $_plugin_file );
41 $this->slug = basename( $_plugin_file, '.php' );
42 $this->version = $_api_data['version'];
43 $this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false;
44 $this->beta = ! empty( $this->api_data['beta'] ) ? true : false;
45 $this->cache_key = 'edd_sl_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
46
47 $edd_plugin_data[ $this->slug ] = $this->api_data;
48
49 /**
50 * Fires after the $edd_plugin_data is setup.
51 *
52 * @since x.x.x
53 *
54 * @param array $edd_plugin_data Array of EDD SL plugin data.
55 */
56 do_action( 'post_edd_sl_plugin_updater_setup', $edd_plugin_data );
57
58 // Set up hooks.
59 $this->init();
60
61 }
62
63 /**
64 * Set up WordPress filters to hook into WP's update process.
65 *
66 * @uses add_filter()
67 *
68 * @return void
69 */
70 public function init() {
71
72 add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
73 add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
74 remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10 );
75 add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
76 add_action( 'admin_init', array( $this, 'show_changelog' ) );
77
78 }
79
80 /**
81 * Check for Updates at the defined API endpoint and modify the update array.
82 *
83 * This function dives into the update API just when WordPress creates its update array,
84 * then adds a custom API call and injects the custom plugin data retrieved from the API.
85 * It is reassembled from parts of the native WordPress plugin update code.
86 * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
87 *
88 * @uses api_request()
89 *
90 * @param array $_transient_data Update array build by WordPress.
91 * @return array Modified update array with custom plugin data.
92 */
93 public function check_update( $_transient_data ) {
94
95 global $pagenow;
96
97 if ( ! is_object( $_transient_data ) ) {
98 $_transient_data = new stdClass;
99 }
100
101 if ( 'plugins.php' == $pagenow && is_multisite() ) {
102 return $_transient_data;
103 }
104
105 if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) {
106 return $_transient_data;
107 }
108
109 $current = $this->get_repo_api_data();
110 if ( false !== $current && is_object( $current ) && isset( $current->new_version ) ) {
111 if ( version_compare( $this->version, $current->new_version, '<' ) ) {
112 $_transient_data->response[ $this->name ] = $current;
113 } else {
114 // Populating the no_update information is required to support auto-updates in WordPress 5.5.
115 $_transient_data->no_update[ $this->name ] = $current;
116 }
117 }
118 $_transient_data->last_checked = time();
119 $_transient_data->checked[ $this->name ] = $this->version;
120
121 return $_transient_data;
122 }
123
124 /**
125 * Get repo API data from store.
126 * Save to cache.
127 *
128 * @return stdClass
129 */
130 public function get_repo_api_data() {
131 $version_info = $this->get_cached_version_info();
132
133 if ( false === $version_info ) {
134 $version_info = $this->api_request(
135 'plugin_latest_version',
136 array(
137 'slug' => $this->slug,
138 'beta' => $this->beta,
139 )
140 );
141 if ( ! $version_info ) {
142 return false;
143 }
144
145 // This is required for your plugin to support auto-updates in WordPress 5.5.
146 $version_info->plugin = $this->name;
147 $version_info->id = $this->name;
148
149 $this->set_version_info_cache( $version_info );
150 }
151
152 return $version_info;
153 }
154
155 /**
156 * Show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise!
157 *
158 * @param string $file needs to be explained by EDD.
159 * @param array $plugin needs to be explained by EDD.
160 */
161 public function show_update_notification( $file, $plugin ) {
162
163 if ( is_network_admin() ) {
164 return;
165 }
166
167 if( ! current_user_can( 'update_plugins' ) ) {
168 return;
169 }
170
171 if( ! is_multisite() ) {
172 return;
173 }
174
175 if ( $this->name != $file ) {
176 return;
177 }
178
179 // Remove our filter on the site transient
180 remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
181
182 $update_cache = get_site_transient( 'update_plugins' );
183
184 $update_cache = is_object( $update_cache ) ? $update_cache : new stdClass();
185
186 if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
187
188 $version_info = $this->get_repo_api_data();
189
190 if ( false === $version_info ) {
191 $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
192
193 // Since we disabled our filter for the transient, we aren't running our object conversion on banners, sections, or icons. Do this now:
194 if ( isset( $version_info->banners ) && ! is_array( $version_info->banners ) ) {
195 $version_info->banners = $this->convert_object_to_array( $version_info->banners );
196 }
197
198 if ( isset( $version_info->sections ) && ! is_array( $version_info->sections ) ) {
199 $version_info->sections = $this->convert_object_to_array( $version_info->sections );
200 }
201
202 if ( isset( $version_info->icons ) && ! is_array( $version_info->icons ) ) {
203 $version_info->icons = $this->convert_object_to_array( $version_info->icons );
204 }
205
206 if ( isset( $version_info->contributors ) && ! is_array( $version_info->contributors ) ) {
207 $version_info->contributors = $this->convert_object_to_array( $version_info->contributors );
208 }
209
210 $this->set_version_info_cache( $version_info );
211 }
212
213 if ( ! is_object( $version_info ) ) {
214 return;
215 }
216
217 if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
218 $update_cache->response[ $this->name ] = $version_info;
219 } else {
220 $update_cache->no_update[ $this->name ] = $version_info;
221 }
222
223 $update_cache->last_checked = time();
224 $update_cache->checked[ $this->name ] = $this->version;
225
226 set_site_transient( 'update_plugins', $update_cache );
227
228 } else {
229
230 $version_info = $update_cache->response[ $this->name ];
231
232 }
233
234 // Restore our filter
235 add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
236
237 if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) {
238
239 // build a plugin list row, with update notification
240 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
241 # <tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
242 echo '<tr class="plugin-update-tr" id="' . $this->slug . '-update" data-slug="' . $this->slug . '" data-plugin="' . $this->slug . '/' . $file . '">';
243 echo '<td colspan="3" class="plugin-update colspanchange">';
244 echo '<div class="update-message notice inline notice-warning notice-alt">';
245
246 $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' );
247
248 if ( empty( $version_info->download_link ) ) {
249 printf(
250 __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s.', 'advanced-ads' ),
251 esc_html( $version_info->name ),
252 '<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">',
253 esc_html( $version_info->new_version ),
254 '</a>'
255 );
256 } else {
257 printf(
258 __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.', 'advanced-ads' ),
259 esc_html( $version_info->name ),
260 '<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">',
261 esc_html( $version_info->new_version ),
262 '</a>',
263 '<a href="' . esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) .'">',
264 '</a>'
265 );
266 }
267
268 do_action( "in_plugin_update_message-{$file}", $plugin, $version_info );
269
270 echo '</div></td></tr>';
271 }
272 }
273
274 /**
275 * Updates information on the "View version x.x details" page with custom data.
276 *
277 * @uses api_request()
278 *
279 * @param mixed $_data needs to be explained by EDD.
280 * @param string $_action needs to be explained by EDD.
281 * @param object $_args needs to be explained by EDD.
282 * @return object $_data
283 */
284 public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
285
286 if ( $_action != 'plugin_information' ) {
287
288 return $_data;
289
290 }
291
292 if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
293
294 return $_data;
295
296 }
297
298 $to_send = array(
299 'slug' => $this->slug,
300 'is_ssl' => is_ssl(),
301 'fields' => array(
302 'banners' => array(),
303 'reviews' => false,
304 'icons' => array(),
305 )
306 );
307
308 // Get the transient where we store the api request for this plugin for 24 hours
309 $edd_api_request_transient = $this->get_cached_version_info();
310
311 //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.
312 if ( empty( $edd_api_request_transient ) ) {
313
314 $api_response = $this->api_request( 'plugin_information', $to_send );
315
316 // Expires in 3 hours
317 $this->set_version_info_cache( $api_response );
318
319 if ( false !== $api_response ) {
320 $_data = $api_response;
321 }
322
323 } else {
324 $_data = $edd_api_request_transient;
325 }
326
327 // Convert sections into an associative array, since we're getting an object, but Core expects an array.
328 if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) {
329 $_data->sections = $this->convert_object_to_array( $_data->sections );
330 }
331
332 // Convert banners into an associative array, since we're getting an object, but Core expects an array.
333 if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) {
334 $_data->banners = $this->convert_object_to_array( $_data->banners );
335 }
336
337 // Convert icons into an associative array, since we're getting an object, but Core expects an array.
338 if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) {
339 $_data->icons = $this->convert_object_to_array( $_data->icons );
340 }
341
342 // Convert contributors into an associative array, since we're getting an object, but Core expects an array.
343 if ( isset( $_data->contributors ) && ! is_array( $_data->contributors ) ) {
344 $_data->contributors = $this->convert_object_to_array( $_data->contributors );
345 }
346
347 if( ! isset( $_data->plugin ) ) {
348 $_data->plugin = $this->name;
349 }
350
351 return $_data;
352 }
353
354 /**
355 * Convert some objects to arrays when injecting data into the update API
356 *
357 * Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON
358 * decoding, they are objects. This method allows us to pass in the object and return an associative array.
359 *
360 * @since 3.6.5
361 *
362 * @param stdClass $data
363 *
364 * @return array
365 */
366 private function convert_object_to_array( $data ) {
367 $new_data = array();
368 foreach ( $data as $key => $value ) {
369 $new_data[ $key ] = is_object( $value ) ? $this->convert_object_to_array( $value ) : $value;
370 }
371
372 return $new_data;
373 }
374
375 /**
376 * Disable SSL verification in order to prevent download update failures
377 *
378 * @param array $args
379 * @param string $url
380 * @return object $array
381 */
382 public function http_request_args( $args, $url ) {
383
384 $verify_ssl = $this->verify_ssl();
385 if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
386 $args['sslverify'] = $verify_ssl;
387 }
388 return $args;
389
390 }
391
392 /**
393 * Calls the API and, if successfull, returns the object delivered by the API.
394 *
395 * @uses get_bloginfo()
396 * @uses wp_remote_post()
397 * @uses is_wp_error()
398 *
399 * @param string $_action The requested action.
400 * @param array $_data Parameters for the API action.
401 * @return false|object
402 */
403 private function api_request( $_action, $_data ) {
404
405 global $wp_version, $edd_plugin_url_available;
406
407 $verify_ssl = $this->verify_ssl();
408
409 // Do a quick status check on this domain if we haven't already checked it.
410 $store_hash = md5( $this->api_url );
411 if ( ! is_array( $edd_plugin_url_available ) || ! isset( $edd_plugin_url_available[ $store_hash ] ) ) {
412 $test_url_parts = parse_url( $this->api_url );
413
414 $scheme = ! empty( $test_url_parts['scheme'] ) ? $test_url_parts['scheme'] : 'http';
415 $host = ! empty( $test_url_parts['host'] ) ? $test_url_parts['host'] : '';
416 $port = ! empty( $test_url_parts['port'] ) ? ':' . $test_url_parts['port'] : '';
417
418 if ( empty( $host ) ) {
419 $edd_plugin_url_available[ $store_hash ] = false;
420 } else {
421 $test_url = $scheme . '://' . $host . $port;
422 $response = wp_remote_get( $test_url, array( 'timeout' => $this->health_check_timeout, 'sslverify' => $verify_ssl ) );
423 $edd_plugin_url_available[ $store_hash ] = is_wp_error( $response ) ? false : true;
424 }
425 }
426
427 if ( false === $edd_plugin_url_available[ $store_hash ] ) {
428 return false;
429 }
430
431 $data = array_merge( $this->api_data, $_data );
432
433 if ( $data['slug'] != $this->slug ) {
434 return false;
435 }
436
437 if( $this->api_url == trailingslashit ( home_url() ) ) {
438 return false; // Don't allow a plugin to ping itself
439 }
440
441 $api_params = array(
442 'edd_action' => 'get_version',
443 'license' => ! empty( $data['license'] ) ? $data['license'] : '',
444 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
445 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
446 'version' => isset( $data['version'] ) ? $data['version'] : false,
447 'slug' => $data['slug'],
448 'author' => $data['author'],
449 'url' => home_url(),
450 'beta' => ! empty( $data['beta'] ),
451 );
452
453 $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) );
454
455 if ( ! is_wp_error( $request ) ) {
456 $request = json_decode( wp_remote_retrieve_body( $request ) );
457 }
458
459 if ( $request && isset( $request->sections ) ) {
460 $request->sections = maybe_unserialize( $request->sections );
461 } else {
462 $request = false;
463 }
464
465 if ( $request && isset( $request->banners ) ) {
466 $request->banners = maybe_unserialize( $request->banners );
467 }
468
469 if ( $request && isset( $request->icons ) ) {
470 $request->icons = maybe_unserialize( $request->icons );
471 }
472
473 if ( ! empty( $request->sections ) ) {
474 foreach( $request->sections as $key => $section ) {
475 $request->$key = (array) $section;
476 }
477 }
478
479 return $request;
480 }
481
482 /**
483 * If available, show the changelog for sites in a multisite install.
484 */
485 public function show_changelog() {
486
487 global $edd_plugin_data;
488
489 if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
490 return;
491 }
492
493 if( empty( $_REQUEST['plugin'] ) ) {
494 return;
495 }
496
497 if( empty( $_REQUEST['slug'] ) ) {
498 return;
499 }
500
501 if( ! current_user_can( 'update_plugins' ) ) {
502 wp_die( __( 'You do not have permission to install plugin updates', 'advanced-ads' ), __( 'Error', 'advanced-ads' ), array( 'response' => 403 ) );
503 }
504
505 $data = $edd_plugin_data[ $_REQUEST['slug'] ];
506 $version_info = $this->get_cached_version_info();
507
508 if( false === $version_info ) {
509
510 $api_params = array(
511 'edd_action' => 'get_version',
512 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
513 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
514 'slug' => $_REQUEST['slug'],
515 'author' => $data['author'],
516 'url' => home_url(),
517 'beta' => ! empty( $data['beta'] )
518 );
519
520 $verify_ssl = $this->verify_ssl();
521 $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) );
522
523 if ( ! is_wp_error( $request ) ) {
524 $version_info = json_decode( wp_remote_retrieve_body( $request ) );
525 }
526
527 if ( ! empty( $version_info ) && isset( $version_info->sections ) ) {
528 $version_info->sections = maybe_unserialize( $version_info->sections );
529 } else {
530 $version_info = false;
531 }
532
533 if( ! empty( $version_info ) ) {
534 foreach( $version_info->sections as $key => $section ) {
535 $version_info->$key = (array) $section;
536 }
537 }
538
539 $this->set_version_info_cache( $version_info );
540
541 // Delete the unneeded option
542 delete_option( md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $this->beta . '_version_info' ) );
543 }
544
545 if ( isset( $version_info->sections ) ) {
546 $sections = $this->convert_object_to_array( $version_info->sections );
547 if ( ! empty( $sections['changelog'] ) ) {
548 echo '<div style="background:#fff;padding:10px;">' . wp_kses_post( $sections['changelog'] ) . '</div>';
549 }
550 }
551
552 exit;
553 }
554
555 /**
556 * Gets the plugin's cached version information from the database.
557 *
558 * @param string $cache_key needs to be explained by EDD.
559 * @return boolean|string
560 */
561 public function get_cached_version_info( $cache_key = '' ) {
562
563 if( empty( $cache_key ) ) {
564 $cache_key = $this->cache_key;
565 }
566
567 $cache = get_option( $cache_key );
568
569 if( empty( $cache['timeout'] ) || time() > $cache['timeout'] ) {
570 return false; // Cache is expired
571 }
572
573 // We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point.
574 $cache['value'] = json_decode( $cache['value'] );
575 if ( ! empty( $cache['value']->icons ) ) {
576 $cache['value']->icons = (array) $cache['value']->icons;
577 }
578
579 return $cache['value'];
580
581 }
582
583 /**
584 * Adds the plugin version information to the database.
585 *
586 * @param string $value needs to be explained by EDD.
587 * @param string $cache_key needs to be explained by EDD.
588 */
589 public function set_version_info_cache( $value = '', $cache_key = '' ) {
590
591 if( empty( $cache_key ) ) {
592 $cache_key = $this->cache_key;
593 }
594
595 $data = array(
596 'timeout' => strtotime( '+3 hours', time() ),
597 'value' => json_encode( $value )
598 );
599
600 update_option( $cache_key, $data, 'no' );
601
602 // Delete the duplicate option
603 delete_option( 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ) );
604 }
605
606 /**
607 * Returns if the SSL of the store should be verified.
608 *
609 * @since 1.6.13
610 * @return bool
611 */
612 private function verify_ssl() {
613 return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this );
614 }
615
616 }
617