Skip to content

Commit

Permalink
Merge branch 'trunk' into fix/31823-add-eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed May 2, 2024
2 parents fafd017 + e147f6d commit 4ca35f0
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 18 deletions.
71 changes: 60 additions & 11 deletions src/js/_enqueues/wp/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -1105,21 +1105,33 @@
*
* @since 6.5.0
*
* @param {Object} response Response from the server.
* @param {string} response.slug Slug of the activated plugin.
* @param {string} response.pluginName Name of the activated plugin.
* @param {string} response.plugin The plugin file, relative to the plugins directory.
* @param {Object} response Response from the server.
* @param {string} response.slug Slug of the activated plugin.
* @param {string} response.pluginName Name of the activated plugin.
* @param {string} response.plugin The plugin file, relative to the plugins directory.
*/
wp.updates.activatePluginSuccess = function( response ) {
var $message = $( '.plugin-card-' + response.slug + ', #plugin-information-footer' ).find( '.activating-message' ),
isInModal = 'plugin-information-footer' === $message.parent().attr( 'id' ),
buttonText = _x( 'Activated!', 'plugin' ),
ariaLabel = sprintf(
/* translators: %s: The plugin name. */
'%s activated successfully.',
response.pluginName
);
),
noticeData = {
id: 'plugin-activated-successfully',
className: 'notice-success',
message: sprintf(
/* translators: %s: The refresh link's attributes. */
__( 'Plugin activated. Some changes may not occur until you refresh the page. <a %s>Refresh Now</a>' ),
'href="#" class="button button-secondary refresh-page"'
),
slug: response.slug
},
noticeTarget;

wp.a11y.speak( __( 'Activation completed successfully.' ) );
wp.a11y.speak( __( 'Activation completed successfully. Some changes may not occur until you refresh the page.' ) );
$document.trigger( 'wp-plugin-activate-success', response );

$message
Expand All @@ -1128,7 +1140,7 @@
.attr( 'aria-label', ariaLabel )
.text( buttonText );

if ( 'plugin-information-footer' === $message.parent().attr( 'id' ) ) {
if ( isInModal ) {
wp.updates.setCardButtonStatus(
{
status: 'activated-plugin',
Expand All @@ -1139,13 +1151,26 @@
ariaLabel: ariaLabel
}
);

// Add a notice to the modal's footer.
$message.replaceWith( wp.updates.adminNotice( noticeData ) );

// Send notice information back to the parent screen.
noticeTarget = window.parent === window ? null : window.parent;
$.support.postMessage = !! window.postMessage;
if ( false !== $.support.postMessage && null !== noticeTarget && -1 === window.parent.location.pathname.indexOf( 'index.php' ) ) {
noticeTarget.postMessage(
JSON.stringify( noticeData ),
window.location.origin
);
}
} else {
// Add a notice to the top of the screen.
wp.updates.addAdminNotice( noticeData );
}

setTimeout( function() {
$message.removeClass( 'activated-message' )
.text( _x( 'Active', 'plugin' ) );

if ( 'plugin-information-footer' === $message.parent().attr( 'id' ) ) {
if ( isInModal ) {
wp.updates.setCardButtonStatus(
{
status: 'plugin-active',
Expand All @@ -1159,6 +1184,8 @@
)
}
);
} else {
$message.removeClass( 'activated-message' ).text( _x( 'Active', 'plugin' ) );
}
}, 1000 );
};
Expand Down Expand Up @@ -3258,6 +3285,11 @@
return;
}

if ( 'undefined' !== typeof message.id && 'plugin-activated-successfully' === message.id ) {
wp.updates.addAdminNotice( message );
return;
}

if (
'undefined' !== typeof message.status &&
'undefined' !== typeof message.slug &&
Expand Down Expand Up @@ -3490,5 +3522,22 @@
} );
}
);

/**
* Click handler for page refresh link.
*
* @since 6.5.3
*
* @param {Event} event Event interface.
*/
$document.on( 'click', '.refresh-page', function( event ) {
event.preventDefault();

if ( window.parent === window ) {
window.location.reload();
} else {
window.parent.location.reload();
}
} );
} );
})( jQuery, window.wp, window._wpUpdatesSettings );
19 changes: 19 additions & 0 deletions src/wp-admin/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,25 @@ div.error {
margin-top: -5px;
}

#plugin-information-footer #plugin-activated-successfully {
margin-bottom: 0;
}

#plugin-information-footer #plugin-activated-successfully p {
display: flex;
gap: 1em;
align-items: center;
justify-content: space-between;
margin: 0;
}

#plugin-information-footer #plugin-activated-successfully .refresh-page {
flex-grow: 0;
line-height: 2.15384615;
min-height: 0;
margin-bottom: 0;
}

.update-message p:before,
.updating-message p:before,
.updated-message p:before,
Expand Down
17 changes: 17 additions & 0 deletions src/wp-admin/includes/class-bulk-plugin-upgrader-skin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,38 @@ class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
* The Plugin_Upgrader::bulk_upgrade() method will fill this in
* with info retrieved from the get_plugin_data() function.
*
* @since 3.0.0
* @var array Plugin data. Values will be empty if not supplied by the plugin.
*/
public $plugin_info = array();

/**
* Sets up the strings used in the update process.
*
* @since 3.0.0
*/
public function add_strings() {
parent::add_strings();
/* translators: 1: Plugin name, 2: Number of the plugin, 3: Total number of plugins being updated. */
$this->upgrader->strings['skin_before_update_header'] = __( 'Updating Plugin %1$s (%2$d/%3$d)' );
}

/**
* Performs an action before a bulk plugin update.
*
* @since 3.0.0
*
* @param string $title
*/
public function before( $title = '' ) {
parent::before( $this->plugin_info['Title'] );
}

/**
* Performs an action following a bulk plugin update.
*
* @since 3.0.0
*
* @param string $title
*/
public function after( $title = '' ) {
Expand All @@ -49,6 +63,9 @@ public function after( $title = '' ) {
}

/**
* Displays the footer following the bulk update process.
*
* @since 3.0.0
*/
public function bulk_footer() {
parent::bulk_footer();
Expand Down
17 changes: 17 additions & 0 deletions src/wp-admin/includes/class-bulk-theme-upgrader-skin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,38 @@ class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
* with info retrieved from the Theme_Upgrader::theme_info() method,
* which in turn calls the wp_get_theme() function.
*
* @since 3.0.0
* @var WP_Theme|false The theme's info object, or false.
*/
public $theme_info = false;

/**
* Sets up the strings used in the update process.
*
* @since 3.0.0
*/
public function add_strings() {
parent::add_strings();
/* translators: 1: Theme name, 2: Number of the theme, 3: Total number of themes being updated. */
$this->upgrader->strings['skin_before_update_header'] = __( 'Updating Theme %1$s (%2$d/%3$d)' );
}

/**
* Performs an action before a bulk theme update.
*
* @since 3.0.0
*
* @param string $title
*/
public function before( $title = '' ) {
parent::before( $this->theme_info->display( 'Name' ) );
}

/**
* Performs an action following a bulk theme update.
*
* @since 3.0.0
*
* @param string $title
*/
public function after( $title = '' ) {
Expand All @@ -50,6 +64,9 @@ public function after( $title = '' ) {
}

/**
* Displays the footer following the bulk update process.
*
* @since 3.0.0
*/
public function bulk_footer() {
parent::bulk_footer();
Expand Down
52 changes: 52 additions & 0 deletions src/wp-admin/includes/class-bulk-upgrader-skin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,30 @@
* @see WP_Upgrader_Skin
*/
class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {

/**
* Whether the bulk update process has started.
*
* @since 3.0.0
* @var bool
*/
public $in_loop = false;

/**
* Stores an error message about the update.
*
* @since 3.0.0
* @var string|false
*/
public $error = false;

/**
* Constructor.
*
* Sets up the generic skin for the Bulk Upgrader classes.
*
* @since 3.0.0
*
* @param array $args
*/
public function __construct( $args = array() ) {
Expand All @@ -36,6 +53,9 @@ public function __construct( $args = array() ) {
}

/**
* Sets up the strings used in the update process.
*
* @since 3.0.0
*/
public function add_strings() {
$this->upgrader->strings['skin_upgrade_start'] = __( 'The update process is starting. This process may take a while on some hosts, so please be patient.' );
Expand All @@ -49,6 +69,9 @@ public function add_strings() {
}

/**
* Displays a message about the update.
*
* @since 3.0.0
* @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support.
*
* @param string $feedback Message data.
Expand Down Expand Up @@ -77,18 +100,27 @@ public function feedback( $feedback, ...$args ) {
}

/**
* Displays the header before the update process.
*
* @since 3.0.0
*/
public function header() {
// Nothing. This will be displayed within an iframe.
}

/**
* Displays the footer following the update process.
*
* @since 3.0.0
*/
public function footer() {
// Nothing. This will be displayed within an iframe.
}

/**
* Displays an error message about the update.
*
* @since 3.0.0
* @since 5.9.0 Renamed `$error` to `$errors` for PHP 8 named parameter support.
*
* @param string|WP_Error $errors Errors.
Expand All @@ -113,18 +145,28 @@ public function error( $errors ) {
}

/**
* Displays the header before the bulk update process.
*
* @since 3.0.0
*/
public function bulk_header() {
$this->feedback( 'skin_upgrade_start' );
}

/**
* Displays the footer following the bulk update process.
*
* @since 3.0.0
*/
public function bulk_footer() {
$this->feedback( 'skin_upgrade_end' );
}

/**
* Performs an action before a bulk update.
*
* @since 3.0.0
*
* @param string $title
*/
public function before( $title = '' ) {
Expand All @@ -137,6 +179,10 @@ public function before( $title = '' ) {
}

/**
* Performs an action following a bulk update.
*
* @since 3.0.0
*
* @param string $title
*/
public function after( $title = '' ) {
Expand Down Expand Up @@ -172,13 +218,19 @@ public function after( $title = '' ) {
}

/**
* Resets the properties used in the update process.
*
* @since 3.0.0
*/
public function reset() {
$this->in_loop = false;
$this->error = false;
}

/**
* Flushes all output buffers.
*
* @since 3.0.0
*/
public function flush_output() {
wp_ob_end_flush_all();
Expand Down
Loading

0 comments on commit 4ca35f0

Please sign in to comment.