| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 3 | +// uncomment this line for testing | |
| 4 | +//set_site_transient( 'update_plugins', null ); | |
| 5 | + | |
| 6 | 6 | // Exit if accessed directly |
| 7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | 8 | exit; |
| 9 | 9 | } |
| @@ -9,25 +9,20 @@ | ||
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Allows plugins to use their own update API. |
| 13 | - * Modified version with 'polylang' text domain and comments for translators. | |
| 13 | + * Modified version with 'polylang' text domain and comments for translators | |
| 14 | 14 | * |
| 15 | - * @author Easy Digital Downloads | |
| 16 | - * @version 1.8.0 | |
| 15 | + * @author Pippin Williamson | |
| 16 | + * @version 1.6.3 | |
| 17 | 17 | */ |
| 18 | 18 | class PLL_Plugin_Updater { |
| 19 | + private $api_url = ''; | |
| 20 | + private $api_data = array(); | |
| 21 | + private $name = ''; | |
| 22 | + private $slug = ''; | |
| 23 | + private $version = ''; | |
| 19 | 24 | |
| 20 | - private $api_url = ''; | |
| 21 | - private $api_data = array(); | |
| 22 | - private $name = ''; | |
| 23 | - private $slug = ''; | |
| 24 | - private $version = ''; | |
| 25 | - private $wp_override = false; | |
| 26 | - private $cache_key = ''; | |
| 27 | - | |
| 28 | - private $health_check_timeout = 5; | |
| 29 | - | |
| 30 | 25 | /** |
| 31 | 26 | * Class constructor. |
| 32 | 27 | * |
| 33 | 28 | * @uses plugin_basename() |
| @@ -40,28 +35,16 @@ | ||
| 40 | 35 | public function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
| 41 | 36 | |
| 42 | 37 | global $edd_plugin_data; |
| 43 | 38 | |
| 44 | - $this->api_url = trailingslashit( $_api_url ); | |
| 45 | - $this->api_data = $_api_data; | |
| 46 | - $this->name = plugin_basename( $_plugin_file ); | |
| 47 | - $this->slug = basename( $_plugin_file, '.php' ); | |
| 48 | - $this->version = $_api_data['version']; | |
| 49 | - $this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false; | |
| 50 | - $this->beta = ! empty( $this->api_data['beta'] ) ? true : false; | |
| 51 | - $this->cache_key = 'edd_sl_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ); | |
| 39 | + $this->api_url = trailingslashit( $_api_url ); | |
| 40 | + $this->api_data = $_api_data; | |
| 41 | + $this->name = plugin_basename( $_plugin_file ); | |
| 42 | + $this->slug = basename( $_plugin_file, '.php' ); | |
| 43 | + $this->version = $_api_data['version']; | |
| 52 | 44 | |
| 53 | 45 | $edd_plugin_data[ $this->slug ] = $this->api_data; |
| 54 | 46 | |
| 55 | - /** | |
| 56 | - * Fires after the $edd_plugin_data is setup. | |
| 57 | - * | |
| 58 | - * @since x.x.x | |
| 59 | - * | |
| 60 | - * @param array $edd_plugin_data Array of EDD SL plugin data. | |
| 61 | - */ | |
| 62 | - do_action( 'post_edd_sl_plugin_updater_setup', $edd_plugin_data ); | |
| 63 | - | |
| 64 | 47 | // Set up hooks. |
| 65 | 48 | $this->init(); |
| 66 | 49 | |
| 67 | 50 | } |
| @@ -76,9 +59,9 @@ | ||
| 76 | 59 | public function init() { |
| 77 | 60 | |
| 78 | 61 | add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
| 79 | 62 | add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
| 80 | - remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10 ); | |
| 63 | + remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10, 2 ); | |
| 81 | 64 | add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); |
| 82 | 65 | add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
| 83 | 66 | |
| 84 | 67 | } |
| @@ -107,56 +90,28 @@ | ||
| 107 | 90 | if ( 'plugins.php' == $pagenow && is_multisite() ) { |
| 108 | 91 | return $_transient_data; |
| 109 | 92 | } |
| 110 | 93 | |
| 111 | - if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) { | |
| 112 | - return $_transient_data; | |
| 113 | - } | |
| 94 | + if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { | |
| 114 | 95 | |
| 115 | - $current = $this->get_repo_api_data(); | |
| 116 | - if ( false !== $current && is_object( $current ) && isset( $current->new_version ) ) { | |
| 117 | - if ( version_compare( $this->version, $current->new_version, '<' ) ) { | |
| 118 | - $_transient_data->response[ $this->name ] = $current; | |
| 119 | - } else { | |
| 120 | - // Populating the no_update information is required to support auto-updates in WordPress 5.5. | |
| 121 | - $_transient_data->no_update[ $this->name ] = $current; | |
| 122 | - } | |
| 123 | - } | |
| 124 | - $_transient_data->last_checked = time(); | |
| 125 | - $_transient_data->checked[ $this->name ] = $this->version; | |
| 96 | + $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); | |
| 126 | 97 | |
| 127 | - return $_transient_data; | |
| 128 | - } | |
| 98 | + if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { | |
| 129 | 99 | |
| 130 | - /** | |
| 131 | - * Get repo API data from store. | |
| 132 | - * Save to cache. | |
| 133 | - * | |
| 134 | - * @return \stdClass | |
| 135 | - */ | |
| 136 | - public function get_repo_api_data() { | |
| 137 | - $version_info = $this->get_cached_version_info(); | |
| 100 | + if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { | |
| 138 | 101 | |
| 139 | - if ( false === $version_info ) { | |
| 140 | - $version_info = $this->api_request( | |
| 141 | - 'plugin_latest_version', | |
| 142 | - array( | |
| 143 | - 'slug' => $this->slug, | |
| 144 | - 'beta' => $this->beta, | |
| 145 | - ) | |
| 146 | - ); | |
| 147 | - if ( ! $version_info ) { | |
| 148 | - return false; | |
| 102 | + $_transient_data->response[ $this->name ] = $version_info; | |
| 103 | + | |
| 104 | + } | |
| 105 | + | |
| 106 | + $_transient_data->last_checked = time(); | |
| 107 | + $_transient_data->checked[ $this->name ] = $this->version; | |
| 108 | + | |
| 149 | 109 | } |
| 150 | 110 | |
| 151 | - // This is required for your plugin to support auto-updates in WordPress 5.5. | |
| 152 | - $version_info->plugin = $this->name; | |
| 153 | - $version_info->id = $this->name; | |
| 154 | - | |
| 155 | - $this->set_version_info_cache( $version_info ); | |
| 156 | 111 | } |
| 157 | 112 | |
| 158 | - return $version_info; | |
| 113 | + return $_transient_data; | |
| 159 | 114 | } |
| 160 | 115 | |
| 161 | 116 | /** |
| 162 | 117 | * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise! |
| @@ -165,20 +120,16 @@ | ||
| 165 | 120 | * @param array $plugin |
| 166 | 121 | */ |
| 167 | 122 | public function show_update_notification( $file, $plugin ) { |
| 168 | 123 | |
| 169 | - if ( is_network_admin() ) { | |
| 124 | + if ( ! current_user_can( 'update_plugins' ) ) { | |
| 170 | 125 | return; |
| 171 | 126 | } |
| 172 | 127 | |
| 173 | - if( ! current_user_can( 'update_plugins' ) ) { | |
| 128 | + if ( ! is_multisite() ) { | |
| 174 | 129 | return; |
| 175 | 130 | } |
| 176 | 131 | |
| 177 | - if( ! is_multisite() ) { | |
| 178 | - return; | |
| 179 | - } | |
| 180 | - | |
| 181 | 132 | if ( $this->name != $file ) { |
| 182 | 133 | return; |
| 183 | 134 | } |
| 184 | 135 | |
| @@ -190,31 +141,16 @@ | ||
| 190 | 141 | $update_cache = is_object( $update_cache ) ? $update_cache : new stdClass(); |
| 191 | 142 | |
| 192 | 143 | if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { |
| 193 | 144 | |
| 194 | - $version_info = $this->get_repo_api_data(); | |
| 145 | + $cache_key = md5( 'edd_plugin_' . sanitize_key( $this->name ) . '_version_info' ); | |
| 146 | + $version_info = get_transient( $cache_key ); | |
| 195 | 147 | |
| 196 | 148 | if ( false === $version_info ) { |
| 197 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) ); | |
| 198 | 149 | |
| 199 | - // Since we disabled our filter for the transient, we aren't running our object conversion on banners, sections, or icons. Do this now: | |
| 200 | - if ( isset( $version_info->banners ) && ! is_array( $version_info->banners ) ) { | |
| 201 | - $version_info->banners = $this->convert_object_to_array( $version_info->banners ); | |
| 202 | - } | |
| 150 | + $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); | |
| 203 | 151 | |
| 204 | - if ( isset( $version_info->sections ) && ! is_array( $version_info->sections ) ) { | |
| 205 | - $version_info->sections = $this->convert_object_to_array( $version_info->sections ); | |
| 206 | - } | |
| 207 | - | |
| 208 | - if ( isset( $version_info->icons ) && ! is_array( $version_info->icons ) ) { | |
| 209 | - $version_info->icons = $this->convert_object_to_array( $version_info->icons ); | |
| 210 | - } | |
| 211 | - | |
| 212 | - if ( isset( $version_info->contributors ) && ! is_array( $version_info->contributors ) ) { | |
| 213 | - $version_info->contributors = $this->convert_object_to_array( $version_info->contributors ); | |
| 214 | - } | |
| 215 | - | |
| 216 | - $this->set_version_info_cache( $version_info ); | |
| 152 | + set_transient( $cache_key, $version_info, 3600 ); | |
| 217 | 153 | } |
| 218 | 154 | |
| 219 | 155 | if ( ! is_object( $version_info ) ) { |
| 220 | 156 | return; |
| @@ -220,14 +156,14 @@ | ||
| 220 | 156 | return; |
| 221 | 157 | } |
| 222 | 158 | |
| 223 | 159 | if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
| 160 | + | |
| 224 | 161 | $update_cache->response[ $this->name ] = $version_info; |
| 225 | - } else { | |
| 226 | - $update_cache->no_update[ $this->name ] = $version_info; | |
| 162 | + | |
| 227 | 163 | } |
| 228 | 164 | |
| 229 | - $update_cache->last_checked = time(); | |
| 165 | + $update_cache->last_checked = time(); | |
| 230 | 166 | $update_cache->checked[ $this->name ] = $this->version; |
| 231 | 167 | |
| 232 | 168 | set_site_transient( 'update_plugins', $update_cache ); |
| 233 | 169 | |
| @@ -243,19 +179,16 @@ | ||
| 243 | 179 | if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { |
| 244 | 180 | |
| 245 | 181 | // build a plugin list row, with update notification |
| 246 | 182 | $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
| 247 | - # <tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"> | |
| 248 | - echo '<tr class="plugin-update-tr" id="' . $this->slug . '-update" data-slug="' . $this->slug . '" data-plugin="' . $this->slug . '/' . $file . '">'; | |
| 249 | - echo '<td colspan="3" class="plugin-update colspanchange">'; | |
| 250 | - echo '<div class="update-message notice inline notice-warning notice-alt">'; | |
| 183 | + echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; | |
| 251 | 184 | |
| 252 | 185 | $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' ); |
| 253 | 186 | |
| 254 | 187 | if ( empty( $version_info->download_link ) ) { |
| 255 | 188 | printf( |
| 256 | - /* translators: %1$s plugin name, %3$s plugin version, %2$s is link start tag, %4$s is link end tag. */ | |
| 257 | - __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s.', 'polylang' ), | |
| 189 | + /* translators: %1$s plugin name, %3$s plugin version, %2$s and %4$s are html tags */ | |
| 190 | + esc_html__( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s.', 'polylang' ), | |
| 258 | 191 | esc_html( $version_info->name ), |
| 259 | 192 | '<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">', |
| 260 | 193 | esc_html( $version_info->new_version ), |
| 261 | 194 | '</a>' |
| @@ -261,10 +194,10 @@ | ||
| 261 | 194 | '</a>' |
| 262 | 195 | ); |
| 263 | 196 | } else { |
| 264 | 197 | printf( |
| 265 | - /* translators: %1$s plugin name, %3$s plugin version, %2$s and %5$s are link start tags, %4$s and %6$s are link end tags. */ | |
| 266 | - __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.', 'polylang' ), | |
| 198 | + /* translators: %1$s plugin name, %3$s plugin version, %2$s, %4$s, %5$s and %6$s are html tags */ | |
| 199 | + esc_html__( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.', 'polylang' ), | |
| 267 | 200 | esc_html( $version_info->name ), |
| 268 | 201 | '<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">', |
| 269 | 202 | esc_html( $version_info->new_version ), |
| 270 | 203 | '</a>', |
| @@ -278,8 +211,9 @@ | ||
| 278 | 211 | echo '</div></td></tr>'; |
| 279 | 212 | } |
| 280 | 213 | } |
| 281 | 214 | |
| 215 | + | |
| 282 | 216 | /** |
| 283 | 217 | * Updates information on the "View version x.x details" page with custom data. |
| 284 | 218 | * |
| 285 | 219 | * @uses api_request() |
| @@ -290,8 +224,9 @@ | ||
| 290 | 224 | * @return object $_data |
| 291 | 225 | */ |
| 292 | 226 | public function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
| 293 | 227 | |
| 228 | + | |
| 294 | 229 | if ( $_action != 'plugin_information' ) { |
| 295 | 230 | |
| 296 | 231 | return $_data; |
| 297 | 232 | |
| @@ -306,81 +241,23 @@ | ||
| 306 | 241 | $to_send = array( |
| 307 | 242 | 'slug' => $this->slug, |
| 308 | 243 | 'is_ssl' => is_ssl(), |
| 309 | 244 | 'fields' => array( |
| 310 | - 'banners' => array(), | |
| 311 | - 'reviews' => false, | |
| 312 | - 'icons' => array(), | |
| 245 | + 'banners' => false, // These will be supported soon hopefully | |
| 246 | + 'reviews' => false | |
| 313 | 247 | ) |
| 314 | 248 | ); |
| 315 | 249 | |
| 316 | - // Get the transient where we store the api request for this plugin for 24 hours | |
| 317 | - $edd_api_request_transient = $this->get_cached_version_info(); | |
| 250 | + $api_response = $this->api_request( 'plugin_information', $to_send ); | |
| 318 | 251 | |
| 319 | - //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. | |
| 320 | - if ( empty( $edd_api_request_transient ) ) { | |
| 321 | - | |
| 322 | - $api_response = $this->api_request( 'plugin_information', $to_send ); | |
| 323 | - | |
| 324 | - // Expires in 3 hours | |
| 325 | - $this->set_version_info_cache( $api_response ); | |
| 326 | - | |
| 327 | - if ( false !== $api_response ) { | |
| 328 | - $_data = $api_response; | |
| 329 | - } | |
| 330 | - | |
| 331 | - } else { | |
| 332 | - $_data = $edd_api_request_transient; | |
| 252 | + if ( false !== $api_response ) { | |
| 253 | + $_data = $api_response; | |
| 333 | 254 | } |
| 334 | 255 | |
| 335 | - // Convert sections into an associative array, since we're getting an object, but Core expects an array. | |
| 336 | - if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) { | |
| 337 | - $_data->sections = $this->convert_object_to_array( $_data->sections ); | |
| 338 | - } | |
| 339 | - | |
| 340 | - // Convert banners into an associative array, since we're getting an object, but Core expects an array. | |
| 341 | - if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) { | |
| 342 | - $_data->banners = $this->convert_object_to_array( $_data->banners ); | |
| 343 | - } | |
| 344 | - | |
| 345 | - // Convert icons into an associative array, since we're getting an object, but Core expects an array. | |
| 346 | - if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) { | |
| 347 | - $_data->icons = $this->convert_object_to_array( $_data->icons ); | |
| 348 | - } | |
| 349 | - | |
| 350 | - // Convert contributors into an associative array, since we're getting an object, but Core expects an array. | |
| 351 | - if ( isset( $_data->contributors ) && ! is_array( $_data->contributors ) ) { | |
| 352 | - $_data->contributors = $this->convert_object_to_array( $_data->contributors ); | |
| 353 | - } | |
| 354 | - | |
| 355 | - if( ! isset( $_data->plugin ) ) { | |
| 356 | - $_data->plugin = $this->name; | |
| 357 | - } | |
| 358 | - | |
| 359 | 256 | return $_data; |
| 360 | 257 | } |
| 361 | 258 | |
| 362 | - /** | |
| 363 | - * Convert some objects to arrays when injecting data into the update API | |
| 364 | - * | |
| 365 | - * Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON | |
| 366 | - * decoding, they are objects. This method allows us to pass in the object and return an associative array. | |
| 367 | - * | |
| 368 | - * @since 3.6.5 | |
| 369 | - * | |
| 370 | - * @param stdClass $data | |
| 371 | - * | |
| 372 | - * @return array | |
| 373 | - */ | |
| 374 | - private function convert_object_to_array( $data ) { | |
| 375 | - $new_data = array(); | |
| 376 | - foreach ( $data as $key => $value ) { | |
| 377 | - $new_data[ $key ] = is_object( $value ) ? $this->convert_object_to_array( $value ) : $value; | |
| 378 | - } | |
| 379 | 259 | |
| 380 | - return $new_data; | |
| 381 | - } | |
| 382 | - | |
| 383 | 260 | /** |
| 384 | 261 | * Disable SSL verification in order to prevent download update failures |
| 385 | 262 | * |
| 386 | 263 | * @param array $args |
| @@ -387,15 +264,13 @@ | ||
| 387 | 264 | * @param string $url |
| 388 | 265 | * @return object $array |
| 389 | 266 | */ |
| 390 | 267 | public function http_request_args( $args, $url ) { |
| 391 | - | |
| 392 | - $verify_ssl = $this->verify_ssl(); | |
| 268 | + // If it is an https request and we are performing a package download, disable ssl verification | |
| 393 | 269 | if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
| 394 | - $args['sslverify'] = $verify_ssl; | |
| 270 | + $args['sslverify'] = false; | |
| 395 | 271 | } |
| 396 | 272 | return $args; |
| 397 | - | |
| 398 | 273 | } |
| 399 | 274 | |
| 400 | 275 | /** |
| 401 | 276 | * Calls the API and, if successfull, returns the object delivered by the API. |
| @@ -409,41 +284,17 @@ | ||
| 409 | 284 | * @return false|object |
| 410 | 285 | */ |
| 411 | 286 | private function api_request( $_action, $_data ) { |
| 412 | 287 | |
| 413 | - global $wp_version, $edd_plugin_url_available; | |
| 288 | + global $wp_version; | |
| 414 | 289 | |
| 415 | - $verify_ssl = $this->verify_ssl(); | |
| 416 | - | |
| 417 | - // Do a quick status check on this domain if we haven't already checked it. | |
| 418 | - $store_hash = md5( $this->api_url ); | |
| 419 | - if ( ! is_array( $edd_plugin_url_available ) || ! isset( $edd_plugin_url_available[ $store_hash ] ) ) { | |
| 420 | - $test_url_parts = parse_url( $this->api_url ); | |
| 421 | - | |
| 422 | - $scheme = ! empty( $test_url_parts['scheme'] ) ? $test_url_parts['scheme'] : 'http'; | |
| 423 | - $host = ! empty( $test_url_parts['host'] ) ? $test_url_parts['host'] : ''; | |
| 424 | - $port = ! empty( $test_url_parts['port'] ) ? ':' . $test_url_parts['port'] : ''; | |
| 425 | - | |
| 426 | - if ( empty( $host ) ) { | |
| 427 | - $edd_plugin_url_available[ $store_hash ] = false; | |
| 428 | - } else { | |
| 429 | - $test_url = $scheme . '://' . $host . $port; | |
| 430 | - $response = wp_remote_get( $test_url, array( 'timeout' => $this->health_check_timeout, 'sslverify' => $verify_ssl ) ); | |
| 431 | - $edd_plugin_url_available[ $store_hash ] = is_wp_error( $response ) ? false : true; | |
| 432 | - } | |
| 433 | - } | |
| 434 | - | |
| 435 | - if ( false === $edd_plugin_url_available[ $store_hash ] ) { | |
| 436 | - return false; | |
| 437 | - } | |
| 438 | - | |
| 439 | 290 | $data = array_merge( $this->api_data, $_data ); |
| 440 | 291 | |
| 441 | 292 | if ( $data['slug'] != $this->slug ) { |
| 442 | - return false; | |
| 293 | + return; | |
| 443 | 294 | } |
| 444 | 295 | |
| 445 | - if ( $this->api_url == trailingslashit ( home_url() ) ) { | |
| 296 | + if ( $this->api_url == home_url() ) { | |
| 446 | 297 | return false; // Don't allow a plugin to ping itself |
| 447 | 298 | } |
| 448 | 299 | |
| 449 | 300 | $api_params = array( |
| @@ -450,16 +301,14 @@ | ||
| 450 | 301 | 'edd_action' => 'get_version', |
| 451 | 302 | 'license' => ! empty( $data['license'] ) ? $data['license'] : '', |
| 452 | 303 | 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
| 453 | 304 | 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
| 454 | - 'version' => isset( $data['version'] ) ? $data['version'] : false, | |
| 455 | 305 | 'slug' => $data['slug'], |
| 456 | 306 | 'author' => $data['author'], |
| 457 | - 'url' => home_url(), | |
| 458 | - 'beta' => ! empty( $data['beta'] ), | |
| 307 | + 'url' => home_url() | |
| 459 | 308 | ); |
| 460 | 309 | |
| 461 | - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) ); | |
| 310 | + $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); | |
| 462 | 311 | |
| 463 | 312 | if ( ! is_wp_error( $request ) ) { |
| 464 | 313 | $request = json_decode( wp_remote_retrieve_body( $request ) ); |
| 465 | 314 | } |
| @@ -469,52 +318,36 @@ | ||
| 469 | 318 | } else { |
| 470 | 319 | $request = false; |
| 471 | 320 | } |
| 472 | 321 | |
| 473 | - if ( $request && isset( $request->banners ) ) { | |
| 474 | - $request->banners = maybe_unserialize( $request->banners ); | |
| 475 | - } | |
| 476 | - | |
| 477 | - if ( $request && isset( $request->icons ) ) { | |
| 478 | - $request->icons = maybe_unserialize( $request->icons ); | |
| 479 | - } | |
| 480 | - | |
| 481 | - if ( ! empty( $request->sections ) ) { | |
| 482 | - foreach( $request->sections as $key => $section ) { | |
| 483 | - $request->$key = (array) $section; | |
| 484 | - } | |
| 485 | - } | |
| 486 | - | |
| 487 | 322 | return $request; |
| 488 | 323 | } |
| 489 | 324 | |
| 490 | - /** | |
| 491 | - * If available, show the changelog for sites in a multisite install. | |
| 492 | - */ | |
| 493 | 325 | public function show_changelog() { |
| 494 | 326 | |
| 495 | 327 | global $edd_plugin_data; |
| 496 | 328 | |
| 497 | - if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { | |
| 329 | + if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { | |
| 498 | 330 | return; |
| 499 | 331 | } |
| 500 | 332 | |
| 501 | - if( empty( $_REQUEST['plugin'] ) ) { | |
| 333 | + if ( empty( $_REQUEST['plugin'] ) ) { | |
| 502 | 334 | return; |
| 503 | 335 | } |
| 504 | 336 | |
| 505 | - if( empty( $_REQUEST['slug'] ) ) { | |
| 337 | + if ( empty( $_REQUEST['slug'] ) ) { | |
| 506 | 338 | return; |
| 507 | 339 | } |
| 508 | 340 | |
| 509 | - if( ! current_user_can( 'update_plugins' ) ) { | |
| 341 | + if ( ! current_user_can( 'update_plugins' ) ) { | |
| 510 | 342 | wp_die( __( 'You do not have permission to install plugin updates', 'polylang' ), __( 'Error', 'polylang' ), array( 'response' => 403 ) ); |
| 511 | 343 | } |
| 512 | 344 | |
| 513 | 345 | $data = $edd_plugin_data[ $_REQUEST['slug'] ]; |
| 514 | - $version_info = $this->get_cached_version_info(); | |
| 346 | + $cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_version_info' ); | |
| 347 | + $version_info = get_transient( $cache_key ); | |
| 515 | 348 | |
| 516 | - if( false === $version_info ) { | |
| 349 | + if ( false === $version_info ) { | |
| 517 | 350 | |
| 518 | 351 | $api_params = array( |
| 519 | 352 | 'edd_action' => 'get_version', |
| 520 | 353 | 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
| @@ -520,14 +353,12 @@ | ||
| 520 | 353 | 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
| 521 | 354 | 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
| 522 | 355 | 'slug' => $_REQUEST['slug'], |
| 523 | 356 | 'author' => $data['author'], |
| 524 | - 'url' => home_url(), | |
| 525 | - 'beta' => ! empty( $data['beta'] ) | |
| 357 | + 'url' => home_url() | |
| 526 | 358 | ); |
| 527 | 359 | |
| 528 | - $verify_ssl = $this->verify_ssl(); | |
| 529 | - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) ); | |
| 360 | + $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); | |
| 530 | 361 | |
| 531 | 362 | if ( ! is_wp_error( $request ) ) { |
| 532 | 363 | $version_info = json_decode( wp_remote_retrieve_body( $request ) ); |
| 533 | 364 | } |
| @@ -537,88 +368,16 @@ | ||
| 537 | 368 | } else { |
| 538 | 369 | $version_info = false; |
| 539 | 370 | } |
| 540 | 371 | |
| 541 | - if( ! empty( $version_info ) ) { | |
| 542 | - foreach( $version_info->sections as $key => $section ) { | |
| 543 | - $version_info->$key = (array) $section; | |
| 544 | - } | |
| 545 | - } | |
| 372 | + set_transient( $cache_key, $version_info, 3600 ); | |
| 546 | 373 | |
| 547 | - $this->set_version_info_cache( $version_info ); | |
| 548 | - | |
| 549 | - // Delete the unneeded option | |
| 550 | - delete_option( md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $this->beta . '_version_info' ) ); | |
| 551 | 374 | } |
| 552 | 375 | |
| 553 | - if ( isset( $version_info->sections ) ) { | |
| 554 | - $sections = $this->convert_object_to_array( $version_info->sections ); | |
| 555 | - if ( ! empty( $sections['changelog'] ) ) { | |
| 556 | - echo '<div style="background:#fff;padding:10px;">' . wp_kses_post( $sections['changelog'] ) . '</div>'; | |
| 557 | - } | |
| 376 | + if ( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) { | |
| 377 | + echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>'; | |
| 558 | 378 | } |
| 559 | 379 | |
| 560 | 380 | exit; |
| 561 | - } | |
| 562 | - | |
| 563 | - /** | |
| 564 | - * Gets the plugin's cached version information from the database. | |
| 565 | - * | |
| 566 | - * @param string $cache_key | |
| 567 | - * @return boolean|string | |
| 568 | - */ | |
| 569 | - public function get_cached_version_info( $cache_key = '' ) { | |
| 570 | - | |
| 571 | - if( empty( $cache_key ) ) { | |
| 572 | - $cache_key = $this->cache_key; | |
| 573 | - } | |
| 574 | - | |
| 575 | - $cache = get_option( $cache_key ); | |
| 576 | - | |
| 577 | - if( empty( $cache['timeout'] ) || time() > $cache['timeout'] ) { | |
| 578 | - return false; // Cache is expired | |
| 579 | - } | |
| 580 | - | |
| 581 | - // We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point. | |
| 582 | - $cache['value'] = json_decode( $cache['value'] ); | |
| 583 | - if ( ! empty( $cache['value']->icons ) ) { | |
| 584 | - $cache['value']->icons = (array) $cache['value']->icons; | |
| 585 | - } | |
| 586 | - | |
| 587 | - return $cache['value']; | |
| 588 | - | |
| 589 | - } | |
| 590 | - | |
| 591 | - /** | |
| 592 | - * Adds the plugin version information to the database. | |
| 593 | - * | |
| 594 | - * @param string $value | |
| 595 | - * @param string $cache_key | |
| 596 | - */ | |
| 597 | - public function set_version_info_cache( $value = '', $cache_key = '' ) { | |
| 598 | - | |
| 599 | - if( empty( $cache_key ) ) { | |
| 600 | - $cache_key = $this->cache_key; | |
| 601 | - } | |
| 602 | - | |
| 603 | - $data = array( | |
| 604 | - 'timeout' => strtotime( '+3 hours', time() ), | |
| 605 | - 'value' => json_encode( $value ) | |
| 606 | - ); | |
| 607 | - | |
| 608 | - update_option( $cache_key, $data, 'no' ); | |
| 609 | - | |
| 610 | - // Delete the duplicate option | |
| 611 | - delete_option( 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ) ); | |
| 612 | - } | |
| 613 | - | |
| 614 | - /** | |
| 615 | - * Returns if the SSL of the store should be verified. | |
| 616 | - * | |
| 617 | - * @since 1.6.13 | |
| 618 | - * @return bool | |
| 619 | - */ | |
| 620 | - private function verify_ssl() { | |
| 621 | - return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this ); | |
| 622 | 381 | } |
| 623 | 382 | |
| 624 | 383 | } |