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
41 changes: 32 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,35 @@ 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>'
);

if ( response && response.errorData ) {
$error.append(
$( '<p></p>' ).append(
$( '<strong></strong>' ).text( wp.i18n.__( 'Error details:' ) + ' ' ),
document.createTextNode( response.errorData )
)
);
}

$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
11 changes: 10 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,16 @@ 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(
'errorMessage' => $api->get_error_message(),
);
Comment on lines +3644 to +3646

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are including errorMessage in the AJAX response, but the JavaScript doesn't currently use it. Could we either display this message or remove it from the response to avoid sending unused data?


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