Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 45 additions & 9 deletions src/js/_enqueues/wp/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ themes.Collection = Backbone.Collection.extend({
self.trigger( 'query:empty' );
}

}).fail( function() {
self.trigger( 'query:fail' );
}).fail( function(response) {
self.trigger( 'query:fail', response);
});
} else {
// If it's a paginated request we need to fetch more themes...
Expand All @@ -333,8 +333,8 @@ themes.Collection = Backbone.Collection.extend({
// We are done loading themes for now.
self.loadingThemes = false;

}).fail( function() {
self.trigger( 'query:fail' );
}).fail( function(response) {
self.trigger( 'query:fail', response);
});
}

Expand Down Expand Up @@ -1728,12 +1728,48 @@ themes.view.Installer = themes.view.Appearance.extend({
$( '.theme-browser' ).find( 'div.error' ).remove();
});

this.listenTo( this.collection, 'query:fail', function() {
this.listenTo( this.collection, 'query:fail', function( response ) {
var $error = $( '<div class="notice notice-error"></div>' );

$( 'body' ).removeClass( 'loading-content' );
$( '.theme-browser' ).find( 'div.error' ).remove();
/* translators: %s: Support forums URL. */
$( '.theme-browser' ).find( 'div.themes' ).before( '<div class="notice notice-error"><p>' + wp.i18n.sprintf( wp.i18n.__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), wp.i18n.__( 'https://wordpress.org/support/forums/' ) ) + '</p><p><button class="button try-again">' + wp.i18n.__( 'Try Again' ) + '</button></p></div>' );
$( '.theme-browser .error .try-again' ).on( 'click', function( e ) {
$( '.theme-browser' ).find( 'div.error, div.notice-error' ).remove();

$error.append(
'<p>' +
wp.i18n.sprintf(
/* translators: %s: Support forums URL. */
wp.i18n.__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
wp.i18n.__( 'https://wordpress.org/support/forums/' )
) +
'</p>'
);

var details = '';

if ( response && response.errorData ) {
// Error payload sent by wp_ajax_query_themes().
details = response.errorData;
} else if ( response && response.status && 200 !== response.status ) {
// HTTP-level failure, e.g. 500, 502, or 504.
details = response.status + ( response.statusText ? ' ' + response.statusText : '' );
} else if ( response && response.responseText ) {
// A 200 response that could not be parsed as JSON.
details = wp.i18n.__( 'The server response was not valid JSON.' );
}

if ( details ) {
$error.append(
$( '<p></p>' ).append(
$( '<strong></strong>' ).text( wp.i18n.__( 'Error details:' ) + ' ' ),
Comment thread
Mimitrz marked this conversation as resolved.
Resolved
document.createTextNode( details )
)
);
}

$error.append( '<p><button class="button try-again">' + wp.i18n.__( 'Try Again' ) + '</button></p>' );

$( '.theme-browser' ).find( 'div.themes' ).before( $error );
$( '.theme-browser .notice-error .try-again' ).on( 'click', function( e ) {
e.preventDefault();
$( 'input.wp-filter-search' ).trigger( 'input' );
} );
Expand Down
9 changes: 8 additions & 1 deletion src/wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3640,7 +3640,14 @@ function wp_ajax_query_themes() {
$api = themes_api( 'query_themes', $args );

if ( is_wp_error( $api ) ) {
wp_send_json_error();
$error_data = $api->get_error_data();
$response = array();

if ( is_string( $error_data ) && '' !== trim( $error_data ) ) {
$response['errorData'] = wp_strip_all_tags( $error_data );
}

wp_send_json_error( $response );
}

$update_php = network_admin_url( 'update.php?action=install-theme' );
Expand Down
Loading