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 ) { #> -
+

{{{ data.update }}}
<# } else { #> -
+

<# 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

' + + '
' + + '
' + + '

Update now

' + + '
' + ); + + wp.updates.updateTheme( { slug: 'twentyeleven' } ); + + assert.equal( $fixture.find( '.theme-info .notice[data-slug="twentytwelve"] p' ).text(), 'Different theme update' ); + assert.equal( $fixture.find( '.theme[data-slug="twentyeleven"] .update-message p' ).text(), 'Updating...' ); + } ); + + QUnit.test( 'A successful theme update should not add notices to an unrelated theme details modal', function( assert ) { + var $fixture = $( '#qunit-fixture' ), + originalAdminNotice = wp.updates.adminNotice, + addAdminNotice = sinon.stub( wp.updates, 'addAdminNotice' ), + decrementCount = sinon.stub( wp.updates, 'decrementCount' ); + + wp.updates.adminNotice = sinon.stub().returns( '

Updated!

' ); + $( 'body' ).addClass( 'modal-open' ); + + $fixture.append( + '
' + + '

By the WordPress team

' + + '

Different theme update

' + + '
' + + '
' + + '

Update now

' + + 'Live Preview' + + '
' + ); + + try { + wp.updates.updateThemeSuccess( { + slug: 'twentyeleven', + oldVersion: '1.0', + newVersion: '1.1' + } ); + + assert.strictEqual( addAdminNotice.firstCall.args[0].selector.length, 1 ); + assert.strictEqual( addAdminNotice.firstCall.args[0].selector[0], $fixture.find( '.theme[data-slug="twentyeleven"] .update-message' )[0] ); + assert.equal( $fixture.find( '.theme-info .updated-message' ).length, 0 ); + } finally { + addAdminNotice.restore(); + decrementCount.restore(); + wp.updates.adminNotice = originalAdminNotice; + $( 'body' ).removeClass( 'modal-open' ); + } + } ); + QUnit.test( 'Installing a theme should call the API', function( assert ) { wp.updates.installTheme( { slug: 'twentyeleven' } ); assert.ok( jQuery.ajax.calledOnce );