From 768f51f60c308a06492dcda163b80c1c3ff6ebb9 Mon Sep 17 00:00:00 2001 From: joedolson Date: Thu, 14 Sep 2023 02:15:17 +0000 Subject: [PATCH] Administration: Use `wp_admin_notice()` for `.updated`. Add usages of `wp_admin_notice()` and `wp_get_admin_notice()` on `.updated` in the root level of `/wp-admin/`. Ongoing task to implement new function across core. Props costdev, joedolson. See #57791. Built from https://develop.svn.wordpress.org/trunk@56573 git-svn-id: http://core.svn.wordpress.org/trunk@56085 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-comments.php | 10 ++- wp-admin/edit-link-form.php | 15 ++++- wp-admin/edit.php | 10 ++- wp-admin/link-manager.php | 12 +++- wp-admin/nav-menus.php | 66 ++++++++++++++++--- wp-admin/options-general.php | 38 +++++------ wp-admin/plugins.php | 119 ++++++++++++++++++----------------- wp-admin/themes.php | 97 ++++++++++++++++++++-------- wp-admin/upload.php | 63 ++++++++++++++----- wp-admin/user-edit.php | 41 ++++++------ wp-admin/user-new.php | 9 ++- wp-admin/users.php | 102 ++++++++++++++++++++++++++---- wp-admin/widgets-form.php | 28 ++++++--- wp-includes/version.php | 2 +- 14 files changed, 430 insertions(+), 182 deletions(-) diff --git a/wp-admin/edit-comments.php b/wp-admin/edit-comments.php index ffc1d58d8c..a39aa701de 100644 --- a/wp-admin/edit-comments.php +++ b/wp-admin/edit-comments.php @@ -411,9 +411,13 @@ if ( isset( $_REQUEST['approved'] ) } } - printf( - '

%s

', - implode( "
\n", $messages ) + wp_admin( + implode( "
\n", $messages ), + array( + 'id' => 'moderated', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) ); } } diff --git a/wp-admin/edit-link-form.php b/wp-admin/edit-link-form.php index f63f1a39b0..1bbb32d3a6 100644 --- a/wp-admin/edit-link-form.php +++ b/wp-admin/edit-link-form.php @@ -91,9 +91,18 @@ echo esc_html( $title );
- -

- + 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); +} +?>
$count ) { } if ( $messages ) { - printf( - '

%s

', - implode( ' ', $messages ) + wp_admin_notice( + implode( ' ', $messages ), + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) ); } unset( $messages ); diff --git a/wp-admin/link-manager.php b/wp-admin/link-manager.php index 27389ac2fd..4ae6c4bcc9 100644 --- a/wp-admin/link-manager.php +++ b/wp-admin/link-manager.php @@ -119,11 +119,17 @@ if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {

'; $deleted = (int) $_REQUEST['deleted']; /* translators: %s: Number of links. */ - printf( _n( '%s link deleted.', '%s links deleted.', $deleted ), $deleted ); - echo '

'; + $deleted_message = sprintf( _n( '%s link deleted.', '%s links deleted.', $deleted ), $deleted ); + wp_admin_notice( + $deleted_message, + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'deleted' ), $_SERVER['REQUEST_URI'] ); } ?> diff --git a/wp-admin/nav-menus.php b/wp-admin/nav-menus.php index 3c535c9dbb..9634c2bf5c 100644 --- a/wp-admin/nav-menus.php +++ b/wp-admin/nav-menus.php @@ -281,7 +281,14 @@ switch ( $action ) { check_admin_referer( 'delete-menu_item_' . $menu_item_id ); if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) ) { - $messages[] = '

' . __( 'The menu item has been successfully deleted.' ) . '

'; + $messages[] = wp_get_admin_notice( + __( 'The menu item has been successfully deleted.' ), + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); } break; @@ -302,9 +309,23 @@ switch ( $action ) { } if ( is_wp_error( $deletion ) ) { - $messages[] = '

' . $deletion->get_error_message() . '

'; + $messages[] = wp_get_admin_notice( + $deletion->get_error_message(), + array( + 'id' => 'message', + 'additional_classes' => array( 'error' ), + 'dismissible' => true, + ) + ); } else { - $messages[] = '

' . __( 'The menu has been successfully deleted.' ) . '

'; + $messages[] = wp_get_admin_notice( + __( 'The menu has been successfully deleted.' ), + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); } break; @@ -320,13 +341,27 @@ switch ( $action ) { $deletion = wp_delete_nav_menu( $menu_id_to_delete ); if ( is_wp_error( $deletion ) ) { - $messages[] = '

' . $deletion->get_error_message() . '

'; + $messages[] = wp_get_admin_notice( + $deletion->get_error_message(), + array( + 'id' => 'message', + 'additional_classes' => array( 'error' ), + 'dismissible' => true, + ) + ); $deletion_error = true; } } if ( empty( $deletion_error ) ) { - $messages[] = '

' . __( 'Selected menus have been successfully deleted.' ) . '

'; + $messages[] = wp_get_admin_notice( + __( 'Selected menus have been successfully deleted.' ), + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); } break; @@ -431,7 +466,14 @@ switch ( $action ) { if ( is_wp_error( $_nav_menu_selected_id ) ) { $_menu_object = $_nav_menu_selected_id; - $messages[] = '

' . $_nav_menu_selected_id->get_error_message() . '

'; + $messages[] = wp_get_admin_notice( + $_nav_menu_selected_id->get_error_message(), + array( + 'id' => 'message', + 'additional_classes' => array( 'error' ), + 'dismissible' => true, + ) + ); } else { $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id ); $nav_menu_selected_title = $_menu_object->name; @@ -614,11 +656,19 @@ wp_nav_menu_setup(); wp_initial_nav_menu_meta_boxes(); if ( ! current_theme_supports( 'menus' ) && ! $num_locations ) { - $messages[] = '

' . sprintf( + $message_no_theme_support = sprintf( /* translators: %s: URL to Widgets screen. */ __( 'Your theme does not natively support menus, but you can use them in sidebars by adding a “Navigation Menu” widget on the Widgets screen.' ), admin_url( 'widgets.php' ) - ) . '

'; + ); + $messages[] = wp_get_admin_notice( + $message_no_theme_support, + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); } if ( ! $locations_screen ) : // Main tab. diff --git a/wp-admin/options-general.php b/wp-admin/options-general.php index c79851badc..9d0102f5ad 100644 --- a/wp-admin/options-general.php +++ b/wp-admin/options-general.php @@ -139,25 +139,25 @@ if ( ! is_multisite() ) {

The new address will not become active until confirmed.' ); ?>

-
-

- ' . esc_html( $new_admin_email ) . '' - ); - printf( - ' %2$s', - esc_url( wp_nonce_url( admin_url( 'options.php?dismiss=new_admin_email' ), 'dismiss-' . get_current_blog_id() . '-new_admin_email' ) ), - __( 'Cancel' ) - ); - ?> -

-
- +if ( $new_admin_email && get_option( 'admin_email' ) !== $new_admin_email ) { + $pending_admin_email_message = sprintf( + /* translators: %s: New admin email. */ + __( 'There is a pending change of the admin email to %s.' ), + '' . esc_html( $new_admin_email ) . '' + ); + $pending_admin_email_message .= sprintf( + ' %2$s', + esc_url( wp_nonce_url( admin_url( 'options.php?dismiss=new_admin_email' ), 'dismiss-' . get_current_blog_id() . '-new_admin_email' ) ), + __( 'Cancel' ) + ); + wp_admin_notice( + $pending_admin_email_message, + array( + 'additional_classes' => array( 'updated', 'inline' ), + ) + ); +} +?> diff --git a/wp-admin/plugins.php b/wp-admin/plugins.php index 92fa92a341..f80dda08ed 100644 --- a/wp-admin/plugins.php +++ b/wp-admin/plugins.php @@ -618,7 +618,7 @@ if ( ! empty( $invalid ) ) { } } -if ( isset( $_GET['error'] ) ) : +if ( isset( $_GET['error'] ) ) { if ( isset( $_GET['main'] ) ) { $errmsg = __( 'You cannot delete a plugin while it is active on the main site.' ); @@ -639,10 +639,6 @@ if ( isset( $_GET['error'] ) ) : $errmsg = __( 'Plugin could not be activated because it triggered a fatal error.' ); } - ?> -

- - - '; } - ?> -
- 'message', + 'additional_classes' => array( 'error' ), + ) + ); + +} elseif ( isset( $_GET['deleted'] ) ) { $delete_result = get_transient( 'plugins_delete_result_' . $user_ID ); // Delete it once we're done. delete_transient( 'plugins_delete_result_' . $user_ID ); - if ( is_wp_error( $delete_result ) ) : - ?> -
-

- get_error_message() ) - ); - ?> -

-
- -
-

- -

-
- - -

- -

- -

- -

- -

- -

- -

- -

- -

- -

- + if ( is_wp_error( $delete_result ) ) { + $plugin_not_deleted_message = sprintf( + /* translators: %s: Error message. */ + __( 'Plugin could not be deleted due to an error: %s' ), + esc_html( $delete_result->get_error_message() ) + ); + wp_admin_notice( + $plugin_not_deleted_message, + array( + 'id' => 'message', + 'additional_classes' => array( 'error' ), + 'dismissible' => true, + ) + ); + } else { + $updated_args = array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ); + if ( 1 === (int) $_GET['deleted'] ) { + $plugins_deleted_message = __( 'The selected plugin has been deleted.' ); + } else { + $plugins_deleted_message = __( 'The selected plugins have been deleted.' ); + } + wp_admin_notice( $plugins_deleted_message, $updated_args ); + } +} elseif ( isset( $_GET['activate'] ) ) { + wp_admin_notice( __( 'Plugin activated.' ), $updated_args ); +} elseif ( isset( $_GET['activate-multi'] ) ) { + wp_admin_notice( __( 'Selected plugins activated.' ), $updated_args ); +} elseif ( isset( $_GET['deactivate'] ) ) { + wp_admin_notice( __( 'Plugin deactivated.' ), $updated_args ); +} elseif ( isset( $_GET['deactivate-multi'] ) ) { + wp_admin_notice( __( 'Selected plugins deactivated.' ), $updated_args ); +} elseif ( 'update-selected' === $action ) { + wp_admin_notice( __( 'All selected plugins are up to date.' ), $updated_args ); +} elseif ( isset( $_GET['resume'] ) ) { + wp_admin_notice( __( 'Plugin resumed.' ), $updated_args ); +} elseif ( isset( $_GET['enabled-auto-update'] ) ) { + wp_admin_notice( __( 'Plugin will be auto-updated.' ), $updated_args ); +} elseif ( isset( $_GET['disabled-auto-update'] ) ) { + wp_admin_notice( __( 'Plugin will no longer be auto-updated.' ), $updated_args ); +} elseif ( isset( $_GET['enabled-auto-update-multi'] ) ) { + wp_admin_notice( __( 'Selected plugins will be auto-updated.' ), $updated_args ); +} elseif ( isset( $_GET['disabled-auto-update-multi'] ) ) { + wp_admin_notice( __( 'Selected plugins will no longer be auto-updated.' ), $updated_args ); +} +?>

diff --git a/wp-admin/themes.php b/wp-admin/themes.php index aced47d8b1..9fb3701a12 100644 --- a/wp-admin/themes.php +++ b/wp-admin/themes.php @@ -260,43 +260,86 @@ require_once ABSPATH . 'wp-admin/admin-header.php';
-

- 'message1', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); } elseif ( isset( $_GET['activated'] ) ) { if ( isset( $_GET['previewed'] ) ) { - ?> -

- ' . __( 'Visit site' ) . '', + array( + 'id' => 'message2', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); } else { - ?> -

- ' . __( 'Visit site' ) . '', + array( + 'id' => 'message2', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); } } elseif ( isset( $_GET['deleted'] ) ) { - ?> -

- 'message3', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); } elseif ( isset( $_GET['delete-active-child'] ) ) { - ?> -

- 'message4', + 'additional_classes' => array( 'error' ), + ) + ); } elseif ( isset( $_GET['resumed'] ) ) { - ?> -

- 'message5', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); } elseif ( isset( $_GET['error'] ) && 'resuming' === $_GET['error'] ) { - ?> -

fatal error.' ); ?>

- fatal error.' ), + array( + 'id' => 'message6', + 'additional_classes' => array( 'error' ), + ) + ); } elseif ( isset( $_GET['enabled-auto-update'] ) ) { - ?> -

- 'message7', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); } elseif ( isset( $_GET['disabled-auto-update'] ) ) { - ?> -

- 'message8', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); } $current_theme = wp_get_theme(); diff --git a/wp-admin/upload.php b/wp-admin/upload.php index 6d8c8462b7..f679eb9d67 100644 --- a/wp-admin/upload.php +++ b/wp-admin/upload.php @@ -218,21 +218,41 @@ if ( 'grid' === $mode ) {
- -

- - -
-

- Switch to the list view.' ), - 'upload.php?mode=list' + 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) ); - ?> -

-
+ } + + if ( ! empty( $message ) ) { + wp_admin_notice( + $message, + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); + } + + $js_required_message = sprintf( + /* translators: %s: List view URL. */ + __( 'The grid view for the Media Library requires JavaScript. Switch to the list view.' ), + 'upload.php?mode=list' + ); + wp_admin_notice( + $js_required_message, + array( + additional_classes( 'error', 'hide-if-js' ), + ) + ); + ?>

- -

- + 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); +} +?> diff --git a/wp-admin/user-edit.php b/wp-admin/user-edit.php index 554b21ad29..f89e4e5ea0 100644 --- a/wp-admin/user-edit.php +++ b/wp-admin/user-edit.php @@ -545,25 +545,28 @@ switch ( $action ) {

- ID, '_new_email', true ); ?> - user_email && $profile_user->ID === $current_user->ID ) : ?> -
-

- ' . esc_html( $new_email['newemail'] ) . '' - ); - printf( - ' %2$s', - esc_url( wp_nonce_url( self_admin_url( 'profile.php?dismiss=' . $current_user->ID . '_new_email' ), 'dismiss-' . $current_user->ID . '_new_email' ) ), - __( 'Cancel' ) - ); - ?> -

-
- + ID, '_new_email', true ); + if ( $new_email && $new_email['newemail'] !== $current_user->user_email && $profile_user->ID === $current_user->ID ) : + + $pending_change_message = sprintf( + /* translators: %s: New email. */ + __( 'There is a pending change of your email to %s.' ), + '' . esc_html( $new_email['newemail'] ) . '' + ); + $pending_change_message .= sprintf( + ' %2$s', + esc_url( wp_nonce_url( self_admin_url( 'profile.php?dismiss=' . $current_user->ID . '_new_email' ), 'dismiss-' . $current_user->ID . '_new_email' ) ), + __( 'Cancel' ) + ); + wp_admin_notice( + $pending_change_message, + array( + 'additional_classes' => array( 'updated', 'inline' ), + ) + ); + endif; + ?> diff --git a/wp-admin/user-new.php b/wp-admin/user-new.php index 901f2b7352..b516f4f460 100644 --- a/wp-admin/user-new.php +++ b/wp-admin/user-new.php @@ -396,7 +396,14 @@ endif; if ( ! empty( $messages ) ) { foreach ( $messages as $msg ) { - echo '

' . $msg . '

'; + wp_admin_notice( + $msg, + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); } } ?> diff --git a/wp-admin/users.php b/wp-admin/users.php index 97b96a7b1a..717f487c5c 100644 --- a/wp-admin/users.php +++ b/wp-admin/users.php @@ -610,11 +610,18 @@ switch ( $wp_list_table->current_action() ) { /* translators: %s: Number of users. */ $message = _n( '%s user deleted.', '%s users deleted.', $delete_count ); } - $messages[] = '

' . sprintf( $message, number_format_i18n( $delete_count ) ) . '

'; + $message = sprintf( $message, number_format_i18n( $delete_count ) ); + $messages[] = wp_get_admin_notice( + $message, + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); break; case 'add': $message = __( 'New user created.' ); - $user_id = isset( $_GET['id'] ) ? $_GET['id'] : false; if ( $user_id && current_user_can( 'edit_user', $user_id ) ) { $message .= sprintf( @@ -630,7 +637,14 @@ switch ( $wp_list_table->current_action() ) { ); } - $messages[] = '

' . $message . '

'; + $messages[] = wp_get_admin_notice( + $message, + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); break; case 'resetpassword': $reset_count = isset( $_GET['reset_count'] ) ? (int) $_GET['reset_count'] : 0; @@ -640,25 +654,89 @@ switch ( $wp_list_table->current_action() ) { /* translators: %s: Number of users. */ $message = _n( 'Password reset links sent to %s user.', 'Password reset links sent to %s users.', $reset_count ); } - $messages[] = '

' . sprintf( $message, number_format_i18n( $reset_count ) ) . '

'; + $message = sprintf( $message, number_format_i18n( $reset_count ) ); + $messages[] = wp_get_admin_notice( + $message, + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); break; case 'promote': - $messages[] = '

' . __( 'Changed roles.' ) . '

'; + $messages[] = wp_get_admin_notice( + __( 'Changed roles.' ), + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); break; case 'err_admin_role': - $messages[] = '

' . __( 'The current user’s role must have user editing capabilities.' ) . '

'; - $messages[] = '

' . __( 'Other user roles have been changed.' ) . '

'; + $messages[] = wp_get_admin_notice( + __( 'The current user’s role must have user editing capabilities.' ), + array( + 'id' => 'message', + 'additional_classes' => array( 'error' ), + 'dismissible' => true, + ) + ); + $messages[] = wp_get_admin_notice( + __( 'Other user roles have been changed.' ), + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); break; case 'err_admin_del': - $messages[] = '

' . __( 'You cannot delete the current user.' ) . '

'; - $messages[] = '

' . __( 'Other users have been deleted.' ) . '

'; + $messages[] = wp_get_admin_notice( + __( 'You cannot delete the current user.' ), + array( + 'id' => 'message', + 'additional_classes' => array( 'error' ), + 'dismissible' => true, + ) + ); + $messages[] = wp_get_admin_notice( + __( 'Other users have been deleted.' ), + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); break; case 'remove': - $messages[] = '

' . __( 'User removed from this site.' ) . '

'; + $messages[] = wp_get_admin_notice( + __( 'User removed from this site.' ), + array( + 'id' => 'message', + 'additional_classes' => array( 'updated', 'fade' ), + 'dismissible' => true, + ) + ); break; case 'err_admin_remove': - $messages[] = '

' . __( 'You cannot remove the current user.' ) . '

'; - $messages[] = '

' . __( 'Other users have been removed.' ) . '

'; + $messages[] = wp_get_admin_notice( + __( 'You cannot remove the current user.' ), + array( + 'id' => 'message', + 'additional_classes' => array( 'error' ), + 'dismissible' => true, + ) + ); + $messages[] = wp_get_admin_notice( + __( 'Other users have been removed.' ), + array( + 'id' => 'message', + 'additional_classes' => array( 'updated', 'fade' ), + 'dismissible' => true, + ) + ); break; } endif; diff --git a/wp-admin/widgets-form.php b/wp-admin/widgets-form.php index aa01798856..0c88a8559f 100644 --- a/wp-admin/widgets-form.php +++ b/wp-admin/widgets-form.php @@ -403,14 +403,28 @@ $nonce = wp_create_nonce( 'widgets-access' );
- -

- - -

- - 'message', + 'additional_classes' => array( 'updated' ), + 'dismissible' => true, + ) + ); +} +if ( isset( $_GET['error'] ) && isset( $errors[ $_GET['error'] ] ) ) { + wp_admin_notice( + $errors[ $_GET['error'] ], + array( + 'id' => 'message', + 'additional_classes' => array( 'error' ), + 'dismissible' => true, + ) + ); +} + /** * Fires before the Widgets administration page content loads. * diff --git a/wp-includes/version.php b/wp-includes/version.php index be78d73df6..7a9eaef592 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56572'; +$wp_version = '6.4-alpha-56573'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.