diff --git a/src/js/_enqueues/wp/updates.js b/src/js/_enqueues/wp/updates.js index ef4b47e66093e..0d5386a66bd16 100644 --- a/src/js/_enqueues/wp/updates.js +++ b/src/js/_enqueues/wp/updates.js @@ -1545,7 +1545,7 @@ * decorated with an abort() method. */ wp.updates.updateTheme = function( args ) { - var $notice; + var $notice, $modalNotice; args = _.extend( { success: wp.updates.updateThemeSuccess, @@ -1567,7 +1567,8 @@ $notice = $notice.addClass( 'updating-message' ).find( 'p' ); } else { - $notice = $( '#update-theme' ).closest( '.notice' ).removeClass( 'notice-large' ); + $modalNotice = $( '.theme-info .notice[data-slug="' + args.slug + '"]' ); + $notice = $modalNotice.removeClass( 'notice-large' ); $notice.find( 'h3' ).remove(); @@ -1602,6 +1603,8 @@ wp.updates.updateThemeSuccess = function( response ) { var isModalOpen = $( 'body.modal-open' ).length, $theme = $( '[data-slug="' + response.slug + '"]' ), + $modalNotice = $( '.theme-info .notice[data-slug="' + response.slug + '"]' ), + isModalUpdate = $modalNotice.length, updatedMessage = { className: 'updated-message notice-success notice-alt', message: _x( 'Updated!', 'theme' ) @@ -1618,7 +1621,7 @@ $theme.html( newText ); } - $notice = $( '.theme-info .notice' ).add( wp.customize.control( 'installed_theme_' + response.slug ).container.find( '.theme' ).find( '.update-message' ) ); + $notice = $modalNotice.add( wp.customize.control( 'installed_theme_' + response.slug ).container.find( '.theme' ).find( '.update-message' ) ); } else if ( 'themes-network' === pagenow ) { $notice = $theme.find( '.update-message' ); @@ -1629,13 +1632,13 @@ // Clear the "time to next auto-update" text. $theme.find( '.auto-update-time' ).empty(); } else { - $notice = $( '.theme-info .notice' ).add( $theme.find( '.update-message' ) ); + $notice = $modalNotice.add( $theme.find( '.update-message' ) ); // Focus on Customize button after updating. - if ( isModalOpen ) { + if ( isModalOpen && isModalUpdate ) { $( '.load-customize:visible' ).trigger( 'focus' ); $( '.theme-info .theme-autoupdate' ).find( '.auto-update-time' ).empty(); - } else { + } else if ( ! isModalOpen ) { $theme.find( '.load-customize' ).trigger( 'focus' ); } } @@ -1648,7 +1651,7 @@ $document.trigger( 'wp-theme-update-success', response ); // Show updated message after modal re-rendered. - if ( isModalOpen && 'customize' !== pagenow ) { + if ( isModalOpen && isModalUpdate && 'customize' !== pagenow && ! $( '.theme-info .updated-message' ).length ) { $( '.theme-info .theme-author' ).after( wp.updates.adminNotice( updatedMessage ) ); } }; @@ -1664,7 +1667,9 @@ * @param {string} response.errorMessage The error that occurred. */ wp.updates.updateThemeError = function( response ) { - var $theme = $( '[data-slug="' + response.slug + '"]' ), + var isModalOpen = $( 'body.modal-open' ).length, + $theme = $( '[data-slug="' + response.slug + '"]' ), + $modalNotice = $( '.theme-info .notice[data-slug="' + response.slug + '"]' ), errorMessage = sprintf( /* translators: %s: Error string for a failed update. */ __( 'Update failed: %s' ), @@ -1687,9 +1692,13 @@ if ( 'themes-network' === pagenow ) { $notice = $theme.find( '.update-message ' ); } else { - $notice = $( '.theme-info .notice' ).add( $theme.find( '.notice' ) ); + $notice = $modalNotice.add( $theme.find( '.notice' ) ); - $( 'body.modal-open' ).length ? $( '.load-customize:visible' ).trigger( 'focus' ) : $theme.find( '.load-customize' ).trigger( 'focus'); + if ( isModalOpen && $modalNotice.length ) { + $( '.load-customize:visible' ).trigger( 'focus' ); + } else if ( ! isModalOpen ) { + $theme.find( '.load-customize' ).trigger( 'focus' ); + } } wp.updates.addAdminNotice( { diff --git a/src/wp-admin/themes.php b/src/wp-admin/themes.php index ca9f52b2a164f..2a8c83be12be1 100644 --- a/src/wp-admin/themes.php +++ b/src/wp-admin/themes.php @@ -1153,12 +1153,12 @@ function wp_theme_auto_update_setting_template() { <# if ( data.hasUpdate ) { #> <# if ( data.updateResponse.compatibleWP && data.updateResponse.compatiblePHP ) { #> -
<# if ( ! data.updateResponse.compatibleWP && ! data.updateResponse.compatiblePHP ) { #> diff --git a/tests/qunit/wp-admin/js/updates.js b/tests/qunit/wp-admin/js/updates.js index 9d3948811abfd..aa6b3955d03b0 100644 --- a/tests/qunit/wp-admin/js/updates.js +++ b/tests/qunit/wp-admin/js/updates.js @@ -158,6 +158,62 @@ jQuery( function( $ ) { assert.equal( jQuery.ajax.getCall( 0 ).args[0].data.slug, 'twentyeleven' ); } ); + QUnit.test( 'Starting a theme update should not change unrelated theme details modal notices', function( assert ) { + var $fixture = $( '#qunit-fixture' ); + + $fixture.append( + '
Different theme update
Different theme update