Changeset 4566
- Timestamp:
- 12/22/2016 01:54:34 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api.php
r4560 r4566 71 71 if ( 200 != $response->status ) { 72 72 $response = array( 'error' => 'Plugin not found.' ); 73 wp_cache_set( $cache_key, $response, self::CACHE_GROUP, 60*60 ); // 1 hour TTL for 404's?73 wp_cache_set( $cache_key, $response, self::CACHE_GROUP, 15*60 ); // shorter TTL for missing/erroring plugins. 74 74 } else { 75 75 $response = $response->data; … … 82 82 } 83 83 84 // Backwards compatibility; the API returns null in case of error.. 85 if ( isset( $response['error'] ) ) { 86 $this->output( null ); 87 return; 88 } 89 90 84 91 // Only include the fields requested. 85 $response = $this->remove_unexpected_fields( $response, $request, 'plugin_information' ); 92 if ( ! isset( $response['error'] ) ) { 93 $response = $this->remove_unexpected_fields( $response, $request, 'plugin_information' ); 94 } 86 95 87 96 $this->output( (object) $response ); … … 148 157 $response = $this->internal_rest_api_call( 'plugins/v1/query-plugins', $request->query_plugins_params_for_query() ); 149 158 if ( 200 != $response->status ) { 150 $ this->output( (object) array( 'error' => 'Query Failed.' ));151 return;159 $response = array( 'error' => 'Query Failed.' ); 160 wp_cache_set( $cache_key, $response, self::CACHE_GROUP, 30 ); // Short expiry for when we've got issues 152 161 } else { 153 162 $response = $response->data; … … 156 165 } 157 166 167 if ( isset( $response['error'] ) ) { 168 $this->output( $response ); 169 return; 170 } 171 158 172 // Fill in the plugin details 159 173 foreach ( $response['plugins'] as $i => $plugin_slug ) { 160 $response['plugins'][ $i ] = $this->plugin_information( new Plugins_Info_API_Request( array( 'slug' => $plugin_slug, 'locale' => $request->locale ) ), true ); 174 $plugin = $this->plugin_information( new Plugins_Info_API_Request( array( 'slug' => $plugin_slug, 'locale' => $request->locale ) ), true ); 175 if ( isset( $plugin['error'] ) ) { 176 unset( $response['plugins'][ $i ] ); 177 continue; 178 } 179 180 $response['plugins'][ $i ] = $plugin; 161 181 } 162 182 … … 185 205 if ( 200 != $response->status ) { 186 206 $response = array( 'error' => 'Temporarily Unavailable' ); 207 wp_cache_set( $cache_key, $response, self::CACHE_GROUP, 30 ); // Short expiry for when we've got issues 187 208 } else { 188 209 $response = $response->data; 189 210 wp_cache_set( $cache_key, $response, self::CACHE_GROUP, self::CACHE_EXPIRY ); 190 211 } 212 } 213 214 if ( isset( $response['error'] ) ) { 215 $this->output( (object) $response ); 216 return; 191 217 } 192 218
Note: See TracChangeset
for help on using the changeset viewer.