PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.40.0
Advanced Ads – Ad Manager & AdSense v1.40.0
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
Advanced_Ads_Modal.php 3 years ago EDD_SL_Plugin_Updater.php 4 years ago ad-ajax.php 3 years ago ad-debug.php 3 years ago ad-expiration.php 3 years ago ad-health-notices.php 3 years ago ad-model.php 3 years ago ad-select.php 3 years ago ad.php 3 years ago ad_ajax_callbacks.php 3 years ago ad_group.php 3 years ago ad_placements.php 3 years ago ad_type_abstract.php 3 years ago ad_type_content.php 3 years ago ad_type_dummy.php 3 years ago ad_type_group.php 3 years ago ad_type_image.php 3 years ago ad_type_plain.php 3 years ago checks.php 3 years ago compatibility.php 3 years ago display-conditions.php 3 years ago filesystem.php 3 years ago frontend-notices.php 3 years ago frontend_checks.php 3 years ago in-content-injector.php 3 years ago inline-css.php 3 years ago plugin.php 3 years ago upgrades.php 6 years ago utils.php 3 years ago visitor-conditions.php 3 years ago widget.php 3 years ago
EDD_SL_Plugin_Updater.php
644 lines
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.9.1
13 */
14 class ADVADS_SL_Plugin_Updater {
15
16 private $api_url = '';
17 private $api_data = array();
18 private $plugin_file = '';
19 private $name = '';
20 private $slug = '';
21 private $version = '';
22 private $wp_override = false;
23 private $beta = false;
24 private $failed_request_cache_key;
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;
39
40 $this->api_url = trailingslashit( $_api_url );
41 $this->api_data = $_api_data;
42 $this->plugin_file = $_plugin_file;
43 $this->name = plugin_basename( $_plugin_file );
44 $this->slug = basename( $_plugin_file, '.php' );
45 $this->version = $_api_data['version'];
46 $this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false;
47 $this->beta = ! empty( $this->api_data['beta'] ) ? true : false;
48 $this->failed_request_cache_key = 'edd_sl_failed_http_' . md5( $this->api_url );
49
50 $edd_plugin_data[ $this->slug ] = $this->api_data;
51
52 /**
53 * Fires after the $edd_plugin_data is setup.
54 *
55 * @since x.x.x
56 *
57 * @param array $edd_plugin_data Array of EDD SL plugin data.
58 */
59 do_action( 'post_edd_sl_plugin_updater_setup', $edd_plugin_data );
60
61 // Set up hooks.
62 $this->init();
63
64 }
65
66 /**
67 * Set up WordPress filters to hook into WP's update process.
68 *
69 * @uses add_filter()
70 *
71 * @return void
72 */
73 public function init() {
74
75 add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
76 add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
77 add_action( 'after_plugin_row', array( $this, 'show_update_notification' ), 10, 2 );
78 add_action( 'admin_init', array( $this, 'show_changelog' ) );
79
80 }
81
82 /**
83 * Check for Updates at the defined API endpoint and modify the update array.
84 *
85 * This function dives into the update API just when WordPress creates its update array,
86 * then adds a custom API call and injects the custom plugin data retrieved from the API.
87 * It is reassembled from parts of the native WordPress plugin update code.
88 * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
89 *
90 * @uses api_request()
91 *
92 * @param array $_transient_data Update array build by WordPress.
93 * @return array Modified update array with custom plugin data.
94 */
95 public function check_update( $_transient_data ) {
96
97 global $pagenow;
98
99 if ( ! is_object( $_transient_data ) ) {
100 $_transient_data = new stdClass();
101 }
102
103 if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) {
104 return $_transient_data;
105 }
106
107 $current = $this->get_repo_api_data();
108 if ( false !== $current && is_object( $current ) && isset( $current->new_version ) ) {
109 if ( version_compare( $this->version, $current->new_version, '<' ) ) {
110 $_transient_data->response[ $this->name ] = $current;
111 } else {
112 // Populating the no_update information is required to support auto-updates in WordPress 5.5.
113 $_transient_data->no_update[ $this->name ] = $current;
114 }
115 }
116 $_transient_data->last_checked = time();
117 $_transient_data->checked[ $this->name ] = $this->version;
118
119 return $_transient_data;
120 }
121
122 /**
123 * Get repo API data from store.
124 * Save to cache.
125 *
126 * @return \stdClass
127 */
128 public function get_repo_api_data() {
129 $version_info = $this->get_cached_version_info();
130
131 if ( false === $version_info ) {
132 $version_info = $this->api_request(
133 'plugin_latest_version',
134 array(
135 'slug' => $this->slug,
136 'beta' => $this->beta,
137 )
138 );
139 if ( ! $version_info ) {
140 return false;
141 }
142
143 // This is required for your plugin to support auto-updates in WordPress 5.5.
144 $version_info->plugin = $this->name;
145 $version_info->id = $this->name;
146
147 $this->set_version_info_cache( $version_info );
148 }
149
150 return $version_info;
151 }
152
153 /**
154 * Show the update notification on multisite subsites.
155 *
156 * @param string $file
157 * @param array $plugin
158 */
159 public function show_update_notification( $file, $plugin ) {
160
161 // Return early if in the network admin, or if this is not a multisite install.
162 if ( is_network_admin() || ! is_multisite() ) {
163 return;
164 }
165
166 // Allow single site admins to see that an update is available.
167 if ( ! current_user_can( 'activate_plugins' ) ) {
168 return;
169 }
170
171 if ( $this->name !== $file ) {
172 return;
173 }
174
175 // Do not print any message if update does not exist.
176 $update_cache = get_site_transient( 'update_plugins' );
177
178 if ( ! isset( $update_cache->response[ $this->name ] ) ) {
179 if ( ! is_object( $update_cache ) ) {
180 $update_cache = new stdClass();
181 }
182 $update_cache->response[ $this->name ] = $this->get_repo_api_data();
183 }
184
185 // Return early if this plugin isn't in the transient->response or if the site is running the current or newer version of the plugin.
186 if ( empty( $update_cache->response[ $this->name ] ) || version_compare( $this->version, $update_cache->response[ $this->name ]->new_version, '>=' ) ) {
187 return;
188 }
189
190 printf(
191 '<tr class="plugin-update-tr %3$s" id="%1$s-update" data-slug="%1$s" data-plugin="%2$s">',
192 $this->slug,
193 $file,
194 in_array( $this->name, $this->get_active_plugins(), true ) ? 'active' : 'inactive'
195 );
196
197 echo '<td colspan="3" class="plugin-update colspanchange">';
198 echo '<div class="update-message notice inline notice-warning notice-alt"><p>';
199
200 $changelog_link = '';
201 if ( ! empty( $update_cache->response[ $this->name ]->sections->changelog ) ) {
202 $changelog_link = add_query_arg(
203 array(
204 'edd_sl_action' => 'view_plugin_changelog',
205 'plugin' => urlencode( $this->name ),
206 'slug' => urlencode( $this->slug ),
207 'TB_iframe' => 'true',
208 'width' => 77,
209 'height' => 911,
210 ),
211 self_admin_url( 'index.php' )
212 );
213 }
214 $update_link = add_query_arg(
215 array(
216 'action' => 'upgrade-plugin',
217 'plugin' => urlencode( $this->name ),
218 ),
219 self_admin_url( 'update.php' )
220 );
221
222 printf(
223 /* translators: the plugin name. */
224 esc_html__( 'There is a new version of %1$s available.', 'advanced-ads' ),
225 esc_html( $plugin['Name'] )
226 );
227
228 if ( ! current_user_can( 'update_plugins' ) ) {
229 echo ' ';
230 esc_html_e( 'Contact your network administrator to install the update.', 'advanced-ads' );
231 } elseif ( empty( $update_cache->response[ $this->name ]->package ) && ! empty( $changelog_link ) ) {
232 echo ' ';
233 printf(
234 /* translators: 1. opening anchor tag, do not translate 2. the new plugin version 3. closing anchor tag, do not translate. */
235 __( '%1$sView version %2$s details%3$s.', 'advanced-ads' ),
236 '<a target="_blank" class="thickbox open-plugin-details-modal" href="' . esc_url( $changelog_link ) . '">',
237 esc_html( $update_cache->response[ $this->name ]->new_version ),
238 '</a>'
239 );
240 } elseif ( ! empty( $changelog_link ) ) {
241 echo ' ';
242 printf(
243 __( '%1$sView version %2$s details%3$s or %4$supdate now%5$s.', 'advanced-ads' ),
244 '<a target="_blank" class="thickbox open-plugin-details-modal" href="' . esc_url( $changelog_link ) . '">',
245 esc_html( $update_cache->response[ $this->name ]->new_version ),
246 '</a>',
247 '<a target="_blank" class="update-link" href="' . esc_url( wp_nonce_url( $update_link, 'upgrade-plugin_' . $file ) ) . '">',
248 '</a>'
249 );
250 } else {
251 printf(
252 ' %1$s%2$s%3$s',
253 '<a target="_blank" class="update-link" href="' . esc_url( wp_nonce_url( $update_link, 'upgrade-plugin_' . $file ) ) . '">',
254 esc_html__( 'Update now.', 'advanced-ads' ),
255 '</a>'
256 );
257 }
258
259 do_action( "in_plugin_update_message-{$file}", $plugin, $plugin );
260
261 echo '</p></div></td></tr>';
262 }
263
264 /**
265 * Gets the plugins active in a multisite network.
266 *
267 * @return array
268 */
269 private function get_active_plugins() {
270 $active_plugins = (array) get_option( 'active_plugins' );
271 $active_network_plugins = (array) get_site_option( 'active_sitewide_plugins' );
272
273 return array_merge( $active_plugins, array_keys( $active_network_plugins ) );
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 ( 'plugin_information' !== $_action ) {
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 'icons' => array(),
307 ),
308 );
309
310 // Get the transient where we store the api request for this plugin for 24 hours
311 $edd_api_request_transient = $this->get_cached_version_info();
312
313 //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.
314 if ( empty( $edd_api_request_transient ) ) {
315
316 $api_response = $this->api_request( 'plugin_information', $to_send );
317
318 // Expires in 3 hours
319 $this->set_version_info_cache( $api_response );
320
321 if ( false !== $api_response ) {
322 $_data = $api_response;
323 }
324 } else {
325 $_data = $edd_api_request_transient;
326 }
327
328 // Convert sections into an associative array, since we're getting an object, but Core expects an array.
329 if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) {
330 $_data->sections = $this->convert_object_to_array( $_data->sections );
331 }
332
333 // Convert banners into an associative array, since we're getting an object, but Core expects an array.
334 if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) {
335 $_data->banners = $this->convert_object_to_array( $_data->banners );
336 }
337
338 // Convert icons into an associative array, since we're getting an object, but Core expects an array.
339 if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) {
340 $_data->icons = $this->convert_object_to_array( $_data->icons );
341 }
342
343 // Convert contributors into an associative array, since we're getting an object, but Core expects an array.
344 if ( isset( $_data->contributors ) && ! is_array( $_data->contributors ) ) {
345 $_data->contributors = $this->convert_object_to_array( $_data->contributors );
346 }
347
348 if ( ! isset( $_data->plugin ) ) {
349 $_data->plugin = $this->name;
350 }
351
352 return $_data;
353 }
354
355 /**
356 * Convert some objects to arrays when injecting data into the update API
357 *
358 * Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON
359 * decoding, they are objects. This method allows us to pass in the object and return an associative array.
360 *
361 * @since 3.6.5
362 *
363 * @param stdClass $data
364 *
365 * @return array
366 */
367 private function convert_object_to_array( $data ) {
368 if ( ! is_array( $data ) && ! is_object( $data ) ) {
369 return array();
370 }
371 $new_data = array();
372 foreach ( $data as $key => $value ) {
373 $new_data[ $key ] = is_object( $value ) ? $this->convert_object_to_array( $value ) : $value;
374 }
375
376 return $new_data;
377 }
378
379 /**
380 * Disable SSL verification in order to prevent download update failures
381 *
382 * @param array $args
383 * @param string $url
384 * @return object $array
385 */
386 public function http_request_args( $args, $url ) {
387
388 if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
389 $args['sslverify'] = $this->verify_ssl();
390 }
391 return $args;
392
393 }
394
395 /**
396 * Calls the API and, if successfull, returns the object delivered by the API.
397 *
398 * @uses get_bloginfo()
399 * @uses wp_remote_post()
400 * @uses is_wp_error()
401 *
402 * @param string $_action The requested action.
403 * @param array $_data Parameters for the API action.
404 * @return false|object|void
405 */
406 private function api_request( $_action, $_data ) {
407 $data = array_merge( $this->api_data, $_data );
408
409 if ( $data['slug'] !== $this->slug ) {
410 return;
411 }
412
413 // Don't allow a plugin to ping itself
414 if ( trailingslashit( home_url() ) === $this->api_url ) {
415 return false;
416 }
417
418 if ( $this->request_recently_failed() ) {
419 return false;
420 }
421
422 return $this->get_version_from_remote();
423 }
424
425 /**
426 * Determines if a request has recently failed.
427 *
428 * @since 1.9.1
429 *
430 * @return bool
431 */
432 private function request_recently_failed() {
433 $failed_request_details = get_option( $this->failed_request_cache_key );
434
435 // Request has never failed.
436 if ( empty( $failed_request_details ) || ! is_numeric( $failed_request_details ) ) {
437 return false;
438 }
439
440 /*
441 * Request previously failed, but the timeout has expired.
442 * This means we're allowed to try again.
443 */
444 if ( time() > $failed_request_details ) {
445 delete_option( $this->failed_request_cache_key );
446
447 return false;
448 }
449
450 return true;
451 }
452
453 /**
454 * Logs a failed HTTP request for this API URL.
455 * We set a timestamp for 1 hour from now. This prevents future API requests from being
456 * made to this domain for 1 hour. Once the timestamp is in the past, API requests
457 * will be allowed again. This way if the site is down for some reason we don't bombard
458 * it with failed API requests.
459 *
460 * @see EDD_SL_Plugin_Updater::request_recently_failed
461 *
462 * @since 1.9.1
463 */
464 private function log_failed_request() {
465 update_option( $this->failed_request_cache_key, strtotime( '+1 hour' ) );
466 }
467
468 /**
469 * If available, show the changelog for sites in a multisite install.
470 */
471 public function show_changelog() {
472
473 if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' !== $_REQUEST['edd_sl_action'] ) {
474 return;
475 }
476
477 if ( empty( $_REQUEST['plugin'] ) ) {
478 return;
479 }
480
481 if ( empty( $_REQUEST['slug'] ) || $this->slug !== $_REQUEST['slug'] ) {
482 return;
483 }
484
485 if ( ! current_user_can( 'update_plugins' ) ) {
486 wp_die( esc_html__( 'You do not have permission to install plugin updates', 'advanced-ads' ), esc_html__( 'Error', 'advanced-ads' ), array( 'response' => 403 ) );
487 }
488
489 $version_info = $this->get_repo_api_data();
490 if ( isset( $version_info->sections ) ) {
491 $sections = $this->convert_object_to_array( $version_info->sections );
492 if ( ! empty( $sections['changelog'] ) ) {
493 echo '<div style="background:#fff;padding:10px;">' . wp_kses_post( $sections['changelog'] ) . '</div>';
494 }
495 }
496
497 exit;
498 }
499
500 /**
501 * Gets the current version information from the remote site.
502 *
503 * @return array|false
504 */
505 private function get_version_from_remote() {
506 $api_params = array(
507 'edd_action' => 'get_version',
508 'license' => ! empty( $this->api_data['license'] ) ? $this->api_data['license'] : '',
509 'item_name' => isset( $this->api_data['item_name'] ) ? $this->api_data['item_name'] : false,
510 'item_id' => isset( $this->api_data['item_id'] ) ? $this->api_data['item_id'] : false,
511 'version' => isset( $this->api_data['version'] ) ? $this->api_data['version'] : false,
512 'slug' => $this->slug,
513 'author' => $this->api_data['author'],
514 'url' => home_url(),
515 'beta' => $this->beta,
516 'php_version' => phpversion(),
517 'wp_version' => get_bloginfo( 'version' ),
518 );
519
520 /**
521 * Filters the parameters sent in the API request.
522 *
523 * @param array $api_params The array of data sent in the request.
524 * @param array $this->api_data The array of data set up in the class constructor.
525 * @param string $this->plugin_file The full path and filename of the file.
526 */
527 $api_params = apply_filters( 'edd_sl_plugin_updater_api_params', $api_params, $this->api_data, $this->plugin_file );
528
529 $request = wp_remote_post(
530 $this->api_url,
531 array(
532 'timeout' => 15,
533 'sslverify' => $this->verify_ssl(),
534 'body' => $api_params,
535 )
536 );
537
538 if ( is_wp_error( $request ) || ( 200 !== wp_remote_retrieve_response_code( $request ) ) ) {
539 $this->log_failed_request();
540
541 return false;
542 }
543
544 $request = json_decode( wp_remote_retrieve_body( $request ) );
545
546 if ( $request && isset( $request->sections ) ) {
547 $request->sections = maybe_unserialize( $request->sections );
548 } else {
549 $request = false;
550 }
551
552 if ( $request && isset( $request->banners ) ) {
553 $request->banners = maybe_unserialize( $request->banners );
554 }
555
556 if ( $request && isset( $request->icons ) ) {
557 $request->icons = maybe_unserialize( $request->icons );
558 }
559
560 if ( ! empty( $request->sections ) ) {
561 foreach ( $request->sections as $key => $section ) {
562 $request->$key = (array) $section;
563 }
564 }
565
566 return $request;
567 }
568
569 /**
570 * Get the version info from the cache, if it exists.
571 *
572 * @param string $cache_key
573 * @return object
574 */
575 public function get_cached_version_info( $cache_key = '' ) {
576
577 if ( empty( $cache_key ) ) {
578 $cache_key = $this->get_cache_key();
579 }
580
581 $cache = get_option( $cache_key );
582
583 // Cache is expired
584 if ( empty( $cache['timeout'] ) || time() > $cache['timeout'] ) {
585 return false;
586 }
587
588 // We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point.
589 $cache['value'] = json_decode( $cache['value'] );
590 if ( ! empty( $cache['value']->icons ) ) {
591 $cache['value']->icons = (array) $cache['value']->icons;
592 }
593
594 return $cache['value'];
595
596 }
597
598 /**
599 * Adds the plugin version information to the database.
600 *
601 * @param string $value
602 * @param string $cache_key
603 */
604 public function set_version_info_cache( $value = '', $cache_key = '' ) {
605
606 if ( empty( $cache_key ) ) {
607 $cache_key = $this->get_cache_key();
608 }
609
610 $data = array(
611 'timeout' => strtotime( '+3 hours', time() ),
612 'value' => wp_json_encode( $value ),
613 );
614
615 update_option( $cache_key, $data, 'no' );
616
617 // Delete the duplicate option
618 delete_option( 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ) );
619 }
620
621 /**
622 * Returns if the SSL of the store should be verified.
623 *
624 * @since 1.6.13
625 * @return bool
626 */
627 private function verify_ssl() {
628 return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this );
629 }
630
631 /**
632 * Gets the unique key (option name) for a plugin.
633 *
634 * @since 1.9.0
635 * @return string
636 */
637 private function get_cache_key() {
638 $string = $this->slug . $this->api_data['license'] . $this->beta;
639
640 return 'edd_sl_' . md5( serialize( $string ) );
641 }
642
643 }
644