Changeset 28126
- Timestamp:
- 04/15/2014 01:15:43 AM (10 years ago)
- Location:
- trunk/src/wp-admin
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/admin-ajax.php
r27419 r28126 59 59 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', 60 60 'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs', 61 'save-user-color-scheme', 'update-widget', 61 'save-user-color-scheme', 'update-widget', 'query-themes', 62 62 ); 63 63 -
trunk/src/wp-admin/includes/ajax-actions.php
r27823 r28126 2205 2205 wp_send_json_success(); 2206 2206 } 2207 2208 /** 2209 * Get themes from themes_api(). 2210 * 2211 * @since 3.9.0 2212 */ 2213 function wp_ajax_query_themes() { 2214 global $themes_allowedtags, $theme_field_defaults; 2215 2216 if ( ! current_user_can( 'install_themes' ) ) { 2217 wp_send_json_error(); 2218 } 2219 2220 $args = wp_parse_args( wp_unslash( $_REQUEST['request'] ), array( 2221 'per_page' => 20, 2222 'fields' => $theme_field_defaults 2223 ) ); 2224 2225 $old_filter = isset( $args['browse'] ) ? $args['browse'] : 'search'; 2226 2227 /** This filter is documented in wp-admin/includes/class-wp-theme-install-list-table.php */ 2228 $args = apply_filters( 'install_themes_table_api_args_' . $old_filter, $args ); 2229 2230 $api = themes_api( 'query_themes', $args ); 2231 2232 if ( is_wp_error( $api ) ) { 2233 wp_send_json_error(); 2234 } 2235 2236 $update_php = self_admin_url( 'update.php?action=install-theme' ); 2237 foreach ( $api->themes as &$theme ) { 2238 $theme->install_url = add_query_arg( array( 2239 'theme' => $theme->slug, 2240 '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ) 2241 ), $update_php ); 2242 2243 $theme->name = wp_kses( $theme->name, $themes_allowedtags ); 2244 $theme->author = wp_kses( $theme->author, $themes_allowedtags ); 2245 $theme->version = wp_kses( $theme->version, $themes_allowedtags ); 2246 $theme->description = wp_kses( $theme->description, $themes_allowedtags ); 2247 $theme->num_ratings = sprintf( _n( '(based on %s rating)', '(based on %s ratings)', $theme->num_ratings ), number_format_i18n( $theme->num_ratings ) ); 2248 } 2249 2250 wp_send_json_success( $api ); 2251 } -
trunk/src/wp-admin/includes/theme.php
r28037 r28126 347 347 348 348 if ( $ssl && is_wp_error( $request ) ) { 349 trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) . ' ' . '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)', headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE ); 349 if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) { 350 trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) . ' ' . '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)', headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE ); 351 } 350 352 $request = wp_remote_post( $http_url, $args ); 351 353 } -
trunk/src/wp-admin/js/theme.js
r28123 r28126 23 23 // Map `id` to `slug` for shared code 24 24 initialize: function() { 25 var install, description; 26 27 // Install url for the theme 28 // using the install nonce 29 install = { 30 action: 'install-theme', 31 theme: this.get( 'slug' ), 32 _wpnonce: themes.data.settings._nonceInstall 33 }; 34 35 // Build the url query 36 install = themes.data.settings.updateURI + '?' + $.param( install ); 25 var description; 37 26 38 27 // If theme is already installed, set an attribute. … … 43 32 // Set the attributes 44 33 this.set({ 45 installURI: ( this.get( 'slug' ) ) ? install : false,46 34 // slug is for installation, id is for existing. 47 35 id: this.get( 'slug' ) || this.get( 'id' ) … … 226 214 // When we are missing a cache object we fire an apiCall() 227 215 // which triggers events of `query:success` or `query:fail` 228 query: function( request , action) {216 query: function( request ) { 229 217 /** 230 218 * @static … … 255 243 // Otherwise, send a new API call and add it to the cache. 256 244 if ( ! query && ! isPaginated ) { 257 query = this.apiCall( request , action).done( function( data ) {245 query = this.apiCall( request ).done( function( data ) { 258 246 259 247 // Update the collection with the queried data. … … 263 251 // Store the results and the query request 264 252 queries.push( { themes: data.themes, request: request, total: count } ); 265 266 } else if ( action ) {267 self.reset( data );268 count = 1;269 self.trigger( 'query:theme' );270 253 } 271 254 … … 285 268 // If it's a paginated request we need to fetch more themes... 286 269 if ( isPaginated ) { 287 return this.apiCall( request, action,isPaginated ).done( function( data ) {270 return this.apiCall( request, isPaginated ).done( function( data ) { 288 271 // Add the new themes to the current collection 289 272 // @todo update counter … … 311 294 } 312 295 296 this.reset( query.themes ); 313 297 if ( ! query.total ) { 314 298 this.count = this.length; 315 299 } 316 300 317 this.reset( query.themes );318 301 this.trigger( 'update' ); 302 this.trigger( 'query:success', this.count ); 319 303 } 320 304 }, … … 330 314 331 315 // Send request to api.wordpress.org/themes 332 apiCall: function( request, action, paginated ) { 333 334 // Send tags (and fields) as comma-separated to keep the JSONP query string short. 335 if ( request.tag && _.isArray( request.tag ) ) { 336 request.tag = request.tag.join( ',' ); 337 } 338 339 // Set request action 340 if ( ! action ) { 341 action = 'query_themes' 342 } 343 344 // JSONP request to .org API 345 return $.ajax({ 346 url: 'https://api.wordpress.org/themes/info/1.1/?callback=?', 347 dataType: 'jsonp', 348 timeout: 15000, // 15 seconds 349 316 apiCall: function( request, paginated ) { 317 return wp.ajax.send( 'query-themes', { 318 data: { 350 319 // Request data 351 data: {352 action: action,353 320 request: _.extend({ 354 per_page: 72, 355 fields: 'description,tested,requires,rating,downloaded,downloadLink,last_updated,homepage,num_ratings' 321 per_page: 100, 322 fields: { 323 description: true, 324 tested: true, 325 requires: true, 326 rating: true, 327 downloaded: true, 328 downloadLink: true, 329 last_updated: true, 330 homepage: true, 331 num_ratings: true 332 } 356 333 }, request) 357 334 }, … … 1568 1545 }, 1569 1546 1570 backToFilters: function() { 1547 backToFilters: function( event ) { 1548 if ( event ) { 1549 event.preventDefault(); 1550 } 1551 1571 1552 $( 'body' ).removeClass( 'filters-applied' ); 1572 1553 }, … … 1635 1616 // Queries the API for the passed theme slug 1636 1617 themes.router.on( 'route:preview', function( slug ) { 1637 request. slug= slug;1638 self.view.collection.query( request , 'theme_information');1618 request.theme = slug; 1619 self.view.collection.query( request ); 1639 1620 }); 1640 1621 -
trunk/src/wp-admin/theme-install.php
r28123 r28126 47 47 'canInstall' => current_user_can( 'install_themes' ), 48 48 'installURI' => current_user_can( 'install_themes' ) ? self_admin_url( 'theme-install.php' ) : null, 49 'adminUrl' => parse_url( self_admin_url(), PHP_URL_PATH ), 50 'updateURI' => self_admin_url( 'update.php' ), 51 '_nonceInstall' => wp_create_nonce( 'install-theme' ) 49 'adminUrl' => parse_url( self_admin_url(), PHP_URL_PATH ) 52 50 ), 53 51 'l10n' => array( … … 57 55 'upload' => __( 'Upload Theme' ), 58 56 'back' => __( 'Back' ), 59 'error' => sprintf( __( 'An unexpected error occurred and we can᾿t reach WordPress.org. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), __( 'https://wordpress.org/support/' ))57 'error' => __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) 60 58 ), 61 59 'installedThemes' => array_keys( $installed_themes ), … … 200 198 201 199 <div class="theme-actions"> 202 <a class="button button-primary" href="{{ data.install URI}}"><?php esc_html_e( 'Install' ); ?></a>200 <a class="button button-primary" href="{{ data.install_url }}"><?php esc_html_e( 'Install' ); ?></a> 203 201 <a class="button button-secondary preview install-theme-preview" href="#"><?php esc_html_e( 'Preview' ); ?></a> 204 202 </div> … … 216 214 <a href="#" class="button button-primary theme-install disabled"><?php _e( 'Installed' ); ?></a> 217 215 <# } else { #> 218 <a href="{{ data.install URI}}" class="button button-primary theme-install"><?php _e( 'Install' ); ?></a>216 <a href="{{ data.install_url }}" class="button button-primary theme-install"><?php _e( 'Install' ); ?></a> 219 217 <# } #> 220 218 </div> … … 234 232 <span class="five"></span> 235 233 <# if ( data.num_ratings ) { #> 236 <p class="ratings"> ({{ data.num_ratings }})</p>234 <p class="ratings">{{ data.num_ratings }}</p> 237 235 <# } else { #> 238 236 <p class="ratings"><?php _e( 'No ratings.' ); ?></p> -
trunk/src/wp-admin/update.php
r27499 r28126 203 203 include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api.. 204 204 205 check_admin_referer( 'install-theme ');205 check_admin_referer( 'install-theme_' . $theme ); 206 206 $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth. 207 207
Note: See TracChangeset
for help on using the changeset viewer.