From 530b24921a4e986499cb8ea6bb6cf085f40b9cab Mon Sep 17 00:00:00 2001 From: devinwalker Date: Wed, 14 Oct 2026 20:52:28 -0700 Subject: [PATCH] Plugins: Update the Plugins screen after updating a plugin from the details modal. Since WordPress 6.5, updating a plugin from the "View details" modal runs the update inside the modal's iframe. The modal shows "Updated!", but the screen behind it never finds out. The Plugins list keeps showing the old version and the update notice, and the update counts in the admin menu, Toolbar, and "Update Available" filter stay the same until the page is reloaded. The existing `updated-plugin` message sent to the parent window now includes the plugin file and the old and new versions. The parent uses it to update the plugin's row on the Plugins screen, the same way the inline "update now" link does, and to decrement the update counts on any screen. This also removes the click handler for `#plugin_update_from_iframe`, which has not matched any element since 6.5. See #62212. --- src/js/_enqueues/wp/updates.js | 67 +++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/src/js/_enqueues/wp/updates.js b/src/js/_enqueues/wp/updates.js index 6fb48411c52bd..906396bcdcd36 100644 --- a/src/js/_enqueues/wp/updates.js +++ b/src/js/_enqueues/wp/updates.js @@ -428,6 +428,7 @@ * Sends a message from a modal to the main screen to update buttons in plugin cards. * * @since 6.5.0 + * @since 7.2.0 Added the `oldVersion` and `newVersion` parameters. * * @param {Object} data An object of data to use for the button. * @param {string} data.slug The plugin's slug. @@ -439,6 +440,8 @@ * @param {string} [data.href] Optional. The button's URL. * @param {string} [data.pluginName] Optional. The plugin's name. * @param {string} [data.plugin] Optional. The plugin file, relative to the plugins directory. + * @param {string} [data.oldVersion] Optional. The plugin's version before an update. + * @param {string} [data.newVersion] Optional. The plugin's version after an update. */ wp.updates.setCardButtonStatus = function( data ) { var target = window.parent === window ? null : window.parent; @@ -604,6 +607,10 @@ { status: 'updated-plugin', slug: response.slug, + plugin: response.plugin, + pluginName: response.pluginName, + oldVersion: response.oldVersion, + newVersion: response.newVersion, removeClasses: 'updating-message', addClasses: 'button-disabled updated-message', text: buttonText, @@ -3206,41 +3213,12 @@ } } ); - /** - * Click handler for updating a plugin from the details modal on `plugin-install.php`. - * - * @since 4.2.0 - * - * @param {Event} event Event interface. - */ - $( '#plugin_update_from_iframe' ).on( 'click', function( event ) { - var target = window.parent === window ? null : window.parent, - update; - - $.support.postMessage = !! window.postMessage; - - if ( false === $.support.postMessage || null === target || -1 !== window.parent.location.pathname.indexOf( 'update-core.php' ) ) { - return; - } - - event.preventDefault(); - - update = { - action: 'update-plugin', - data: { - plugin: $( this ).data( 'plugin' ), - slug: $( this ).data( 'slug' ) - } - }; - - target.postMessage( JSON.stringify( update ), window.location.origin ); - } ); - /** * Handles postMessage events. * * @since 4.2.0 * @since 4.6.0 Switched `update-plugin` action to use the queue. + * @since 7.2.0 Updates the plugin's row and the update counts after an update from the plugin details modal. * * @param {Event} event Event interface. */ @@ -3295,6 +3273,35 @@ } $message.text( message.text ); + + /* + * The plugin was updated inside the plugin details modal, which shows its own + * result. Bring the screen behind the modal up to date as well. + */ + if ( 'updated-plugin' === message.status ) { + wp.updates.decrementCount( 'plugin' ); + + if ( ( 'plugins' === pagenow || 'plugins-network' === pagenow ) && message.plugin ) { + var $pluginRow = $( 'tr[data-plugin="' + message.plugin + '"]' ) + .removeClass( 'update is-enqueued' ) + .addClass( 'updated' ), + $pluginVersion = $pluginRow.find( '.plugin-version-author-uri' ); + + $pluginRow.find( '.update-message' ) + .removeClass( 'updating-message notice-warning' ) + .addClass( 'updated-message notice-success' ) + .find( 'p' ) + .attr( 'aria-label', message.ariaLabel ) + .text( message.text ); + + if ( message.oldVersion && message.newVersion && $pluginVersion.length ) { + $pluginVersion.html( $pluginVersion.html().replace( message.oldVersion, message.newVersion ) ); + } + + // Clear the "time to next auto-update" text. + $pluginRow.find( '.auto-update-time' ).empty(); + } + } } if ( 'undefined' === typeof message.action ) {