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
22 changes: 15 additions & 7 deletions src/js/_enqueues/wp/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,14 @@
}

$document.trigger( 'wp-plugin-update-success', response );

if ( response.activateUrl ) {
setTimeout( function() {
wp.updates.checkPluginDependencies( {
slug: response.slug
} );
}, 1000 );
}
};

/**
Expand Down Expand Up @@ -953,12 +961,12 @@
* @param {string} response.activateUrl URL to activate the just checked plugin.
*/
wp.updates.checkPluginDependenciesSuccess = function( response ) {
var $message = $( '.plugin-card-' + response.slug + ', #plugin-information-footer' ).find( '.install-now' ),
var $message = $( '.plugin-card-' + response.slug + ', #plugin-information-footer' ).find( '.install-now, .update-now' ),
buttonText, ariaLabel;

// Transform the 'Install' button into an 'Activate' button.
// Transform the 'Install' or 'Update' button into an 'Activate' button.
$message
.removeClass( 'install-now installed button-disabled updated-message' )
.removeClass( 'install-now update-now installed button-disabled updated-message' )
.addClass( 'activate-now button-primary' )
.attr( 'href', response.activateUrl );

Expand Down Expand Up @@ -997,7 +1005,7 @@
{
status: 'dependencies-check-success',
slug: response.slug,
removeClasses: 'install-now installed button-disabled updated-message',
removeClasses: 'install-now update-now installed button-disabled updated-message',
addClasses: 'activate-now button-primary',
text: buttonText,
ariaLabel: ariaLabel,
Expand All @@ -1021,7 +1029,7 @@
* @param {string} response.errorMessage The error that occurred.
*/
wp.updates.checkPluginDependenciesError = function( response ) {
var $message = $( '.plugin-card-' + response.slug + ', #plugin-information-footer' ).find( '.install-now' ),
var $message = $( '.plugin-card-' + response.slug + ', #plugin-information-footer' ).find( '.install-now, .update-now' ),
buttonText = _x( 'Activate', 'plugin' ),
ariaLabel = sprintf(
/* translators: 1: Plugin name, 2. The reason the plugin cannot be activated. */
Expand All @@ -1045,7 +1053,7 @@
$document.trigger( 'wp-check-plugin-dependencies-error', response );

$message
.removeClass( 'install-now installed updated-message' )
.removeClass( 'install-now update-now installed updated-message' )
.addClass( 'activate-now button-primary' )
.attr( 'aria-label', ariaLabel )
.text( buttonText );
Expand All @@ -1055,7 +1063,7 @@
{
status: 'dependencies-check-failed',
slug: response.slug,
removeClasses: 'install-now installed updated-message',
removeClasses: 'install-now update-now installed updated-message',
addClasses: 'activate-now button-primary',
text: buttonText,
ariaLabel: ariaLabel
Expand Down
20 changes: 20 additions & 0 deletions src/wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4721,6 +4721,26 @@ function wp_ajax_update_plugin() {
$status['newVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
}

$pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : '';

// If update request is coming from import page, do not return network activation link.
$plugins_url = ( 'import' === $pagenow ) ? admin_url( 'plugins.php' ) : network_admin_url( 'plugins.php' );

if ( current_user_can( 'activate_plugin', $plugin ) && is_plugin_inactive( $plugin ) ) {
$status['activateUrl'] = add_query_arg(
array(
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin ),
'action' => 'activate',
'plugin' => $plugin,
),
$plugins_url
);

if ( is_multisite() && current_user_can( 'manage_network_plugins' ) && 'import' !== $pagenow ) {
$status['activateUrl'] = add_query_arg( array( 'networkwide' => 1 ), $status['activateUrl'] );
}
}

wp_send_json_success( $status );
} elseif ( false === $result ) {
global $wp_filesystem;
Expand Down
Loading