code' => $code, 'response' => $res, ] ); } /** * This will match: * - `2.3.4.5-beta1||1.2.3.4-beta2||||||||||||||||||||||||||||||||`: expired license. * - `2.3.4.5-beta1|https://wp-rocket.me/i-should-write-a-funny-thing-here/wp-rocket_1.2.3.4-beta2.zip|1.2.3.4-beta2`: valid license. */ if ( ! preg_match( '@^(?\d+(?:\.\d+){1,3}[^|]*)\|(?(?:http.+\.zip)?)\|(?\d+(?:\.\d+){1,3}[^|]*)(?:\|+)?$@', $res, $match ) ) { /** * If the response doesn’t have the right format, it is an error. */ return $this->get_request_error( $res ); } $obj = new \stdClass(); $obj->slug = $this->get_plugin_slug( $this->plugin_file ); $obj->plugin = plugin_basename( $this->plugin_file ); $obj->new_version = $match['user_version']; $obj->url = $this->vendor_url; $obj->package = $match['package']; /** * Filters the WP tested version value * * @since 3.10.7 * * @param string $wp_tested_version WP tested version value. */ $obj->tested = apply_filters( 'rocket_wp_tested_version', WP_ROCKET_WP_VERSION_TESTED ); if ( $this->icons && ! empty( $this->icons['1x'] ) ) { $obj->icons = $this->icons; } return $obj; } /** * Get the cached version of the latest WPR update data. * * @return \stdClass|\WP_Error { * A \WP_Error object on failure. An object on success: * * @type string $slug The plugin slug. * @type string $plugin The plugin base name. * @type string $new_version The plugin new version. * @type string $url URL to the plugin provider. * @type string $package URL to the zip file of the new version. * @type array $icons { * A list of plugin’s icon URLs. * * @type string $2x URL to the High-DPI size (png or jpg). Optional. * @type string $1x URL to the normal icon size (png or jpg). Mandatory. * @type string $svg URL to the svg version of the icon. Optional. * } * } */ public function get_cached_latest_version_data() { static $response; if ( isset( $response ) ) { // "force update" won’t bypass the static cache: only one http request by page load. return $response; } $force_update = is_string( filter_input( INPUT_GET, 'rocket_force_update' ) ); if ( ! $force_update ) { // No "force update": try to get the result from a transient. $response = get_site_transient( $this->cache_transient_name ); if ( $response && is_object( $response ) ) { // Got something in cache. return $response; } } // Get fresh data. $response = $this->get_latest_version_data(); $cache_duration = 12 * HOUR_IN_SECONDS; if ( is_wp_error( $response ) ) { $error_data = $response->get_error_data(); if ( ! empty( $error_data['error_code'] ) ) { // `wp_remote_get()` returned an internal error ('error_code' contains a WP_Error code ). $cache_duration = HOUR_IN_SECONDS; } elseif ( ! empty( $error_data['http_code'] ) && $error_data['http_code'] >= 400 ) { // We got a 4xx or 5xx HTTP error. $cache_duration = 2 * HOUR_IN_SECONDS; } } set_site_transient( $this->cache_transient_name, $response, $cache_duration ); return $response; } /** * Delete WP Rocket update data cache. */ public function delete_rocket_update_data_cache() { delete_site_transient( $this->cache_transient_name ); } }