From ce32693b3dde40b3293e9f6057c1857bc8899292 Mon Sep 17 00:00:00 2001 From: Colin Stewart Date: Sun, 17 Sep 2023 15:21:07 +0000 Subject: [PATCH] Administration: Use `wp_admin_notice()` more in `/wp-admin/includes/`. Adds further usages of `wp_admin_notice()` in `/wp-admin/includes/` on `.notice-error`, `.notice-warning`, `.error`, and `.updated`. Ongoing task to implement new function across core. Follow-up to [56408], [56409], [56410], [56518], [56570], [56571], [56572], [56573], [56576], [56589], [56590], [56597]. Props joedolson, mukesh27, costdev. See #57791. git-svn-id: https://develop.svn.wordpress.org/trunk@56599 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-bulk-upgrader-skin.php | 10 ++- .../includes/class-custom-background.php | 24 +++--- .../includes/class-custom-image-header.php | 26 +++--- .../class-wp-plugin-install-list-table.php | 15 +++- .../includes/class-wp-plugins-list-table.php | 34 +++++--- .../class-wp-privacy-policy-content.php | 27 +++--- src/wp-admin/includes/dashboard.php | 50 ++++++----- src/wp-admin/includes/file.php | 8 +- src/wp-admin/includes/ms.php | 13 ++- src/wp-admin/includes/nav-menu.php | 8 +- src/wp-admin/includes/network.php | 85 ++++++++++++++----- src/wp-admin/includes/template.php | 61 +++++++------ src/wp-admin/includes/update.php | 18 +++- src/wp-admin/includes/user.php | 46 +++++----- 14 files changed, 278 insertions(+), 147 deletions(-) diff --git a/src/wp-admin/includes/class-bulk-upgrader-skin.php b/src/wp-admin/includes/class-bulk-upgrader-skin.php index 8ce4a70ff7221..461311962d411 100644 --- a/src/wp-admin/includes/class-bulk-upgrader-skin.php +++ b/src/wp-admin/includes/class-bulk-upgrader-skin.php @@ -143,10 +143,16 @@ public function after( $title = '' ) { echo '

'; if ( $this->error || ! $this->result ) { if ( $this->error ) { - echo '

' . sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '' . $this->error . '' ) . '

'; + $after_error_message = sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '' . $this->error . '' ); } else { - echo '

' . sprintf( $this->upgrader->strings['skin_update_failed'], $title ) . '

'; + $after_error_message = sprintf( $this->upgrader->strings['skin_update_failed'], $title ); } + wp_admin_notice( + $after_error_message, + array( + 'additional_classes' => array( 'error' ), + ) + ); echo ''; } diff --git a/src/wp-admin/includes/class-custom-background.php b/src/wp-admin/includes/class-custom-background.php index a2be358e77f19..b818016b28931 100644 --- a/src/wp-admin/includes/class-custom-background.php +++ b/src/wp-admin/includes/class-custom-background.php @@ -256,16 +256,20 @@ public function admin_page() { } if ( ! empty( $this->updated ) ) { - ?> -
-

- Visit your site to see how it looks.' ), esc_url( home_url( '/' ) ) ); - ?> -

-
- + $updated_message = sprintf( + /* translators: %s: Home URL. */ + __( 'Background updated. Visit your site to see how it looks.' ), + esc_url( home_url( '/' ) ) + ); + wp_admin_notice( + $updated_message, + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + ) + ); + } + ?>

diff --git a/src/wp-admin/includes/class-custom-image-header.php b/src/wp-admin/includes/class-custom-image-header.php index 5d0260b1c3b6b..9df725af0cb06 100644 --- a/src/wp-admin/includes/class-custom-image-header.php +++ b/src/wp-admin/includes/class-custom-image-header.php @@ -524,18 +524,22 @@ public function step_1() { ) ); } - ?> - updated ) ) { ?> -
-

- Visit your site to see how it looks.' ), esc_url( home_url( '/' ) ) ); - ?> -

-
- + if ( ! empty( $this->updated ) ) { + $updated_message = sprintf( + /* translators: %s: Home URL. */ + __( 'Header updated. Visit your site to see how it looks.' ), + esc_url( home_url( '/' ) ) + ); + wp_admin_notice( + $updated_message, + array( + 'id' => 'message', + 'additional_classes' => array( 'updated' ), + ) + ); + } + ?>

diff --git a/src/wp-admin/includes/class-wp-plugin-install-list-table.php b/src/wp-admin/includes/class-wp-plugin-install-list-table.php index 330a35e624333..7823f00b70996 100644 --- a/src/wp-admin/includes/class-wp-plugin-install-list-table.php +++ b/src/wp-admin/includes/class-wp-plugin-install-list-table.php @@ -290,10 +290,17 @@ public function prepare_items() { /** */ public function no_items() { - if ( isset( $this->error ) ) { ?> -

error->get_error_message(); ?>

-

-
+ if ( isset( $this->error ) ) { + $error_message = '

' . $this->error->get_error_message() . '

'; + $error_message .= '

'; + wp_admin_notice( + $error_message, + array( + 'additional_classes' => array( 'inline', 'error' ), + 'paragraph_wrap' => false, + ) + ); + ?>
' . '' . - '

', esc_attr( $this->get_column_count() ) ); + $incompatible_message = ''; if ( ! $compatible_php && ! $compatible_wp ) { - _e( 'This plugin does not work with your versions of WordPress and PHP.' ); + $incompatible_message .= __( 'This plugin does not work with your versions of WordPress and PHP.' ); if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) { - printf( + $incompatible_message .= sprintf( /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */ ' ' . __( 'Please update WordPress, and then learn more about updating PHP.' ), self_admin_url( 'update-core.php' ), esc_url( wp_get_update_php_url() ) ); - wp_update_php_annotation( '

', '' ); + $incompatible_message .= wp_update_php_annotation( '

', '', false ); } elseif ( current_user_can( 'update_core' ) ) { - printf( + $incompatible_message .= sprintf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( 'Please update WordPress.' ), self_admin_url( 'update-core.php' ) ); } elseif ( current_user_can( 'update_php' ) ) { - printf( + $incompatible_message .= sprintf( /* translators: %s: URL to Update PHP page. */ ' ' . __( 'Learn more about updating PHP.' ), esc_url( wp_get_update_php_url() ) ); - wp_update_php_annotation( '

', '' ); + $incompatible_message .= wp_update_php_annotation( '

', '', false ); } } elseif ( ! $compatible_wp ) { - _e( 'This plugin does not work with your version of WordPress.' ); + $incompatible_message .= __( 'This plugin does not work with your version of WordPress.' ); if ( current_user_can( 'update_core' ) ) { - printf( + $incompatible_message .= sprintf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( 'Please update WordPress.' ), self_admin_url( 'update-core.php' ) ); } } elseif ( ! $compatible_php ) { - _e( 'This plugin does not work with your version of PHP.' ); + $incompatible_message .= __( 'This plugin does not work with your version of PHP.' ); if ( current_user_can( 'update_php' ) ) { - printf( + $incompatible_message .= sprintf( /* translators: %s: URL to Update PHP page. */ ' ' . __( 'Learn more about updating PHP.' ), esc_url( wp_get_update_php_url() ) ); - wp_update_php_annotation( '

', '' ); + $incompatible_message .= wp_update_php_annotation( '

', '', false ); } } - echo '

'; + wp_admin_notice( + $incompatible_message, + array( + 'type' => 'error', + 'additional_classes' => array( 'notice-alt', 'inline', 'update-message' ), + ) + ); + + echo ''; } /** diff --git a/src/wp-admin/includes/class-wp-privacy-policy-content.php b/src/wp-admin/includes/class-wp-privacy-policy-content.php index 31f776f09c756..a64d043233356 100644 --- a/src/wp-admin/includes/class-wp-privacy-policy-content.php +++ b/src/wp-admin/includes/class-wp-privacy-policy-content.php @@ -138,19 +138,20 @@ public static function policy_text_changed_notice() { return; } - ?> -
-

- review the guide and update your privacy policy.' ), - esc_url( admin_url( 'privacy-policy-guide.php?tab=policyguide' ) ) - ); - ?> -

-
- review the guide and update your privacy policy.' ), + esc_url( admin_url( 'privacy-policy-guide.php?tab=policyguide' ) ) + ); + + wp_admin_notice( + $privacy_message, + array( + 'type' => 'warning', + 'additional_classes' => array( 'policy-text-updated' ), + 'dismissible' => true, + ) + ); } /** diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php index a92b684818690..f74b408881856 100644 --- a/src/wp-admin/includes/dashboard.php +++ b/src/wp-admin/includes/dashboard.php @@ -573,9 +573,16 @@ function wp_dashboard_quick_press( $error_msg = false ) {
- -
- + array( 'error' ), + ) + ); + } + ?>
'; require_once ABSPATH . 'wp-admin/admin-footer.php'; die(); @@ -142,7 +151,13 @@ function network_step1( $errors = false ) { $hostname = get_clean_basedomain(); $has_ports = strstr( $hostname, ':' ); if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ), true ) ) ) { - echo '

' . __( 'Error:' ) . ' ' . __( 'You cannot install a network of sites with your server address.' ) . '

'; + wp_admin_notice( + '' . __( 'Error:' ) . ' ' . __( 'You cannot install a network of sites with your server address.' ), + array( + 'additional_classes' => array( 'error' ), + ) + ); + echo '

' . sprintf( /* translators: %s: Port number. */ __( 'You cannot use port numbers such as %s.' ), @@ -160,11 +175,17 @@ function network_step1( $errors = false ) { $error_codes = array(); if ( is_wp_error( $errors ) ) { - echo '

' . __( 'Error: The network could not be created.' ) . '

'; + $network_created_error_message = '

' . __( 'Error: The network could not be created.' ) . '

'; foreach ( $errors->get_error_messages() as $error ) { - echo "

$error

"; + $network_created_error_message .= "

$error

"; } - echo '
'; + wp_admin_notice( + $network_created_error_message, + array( + 'additional_classes' => array( 'error' ), + 'paragraph_wrap' => false, + ) + ); $error_codes = $errors->get_error_codes(); } @@ -195,33 +216,39 @@ function network_step1( $errors = false ) { $subdomain_install = false; $got_mod_rewrite = got_mod_rewrite(); if ( $got_mod_rewrite ) { // Dangerous assumptions. - echo '

' . __( 'Note:' ) . ' '; - printf( + $message_class = 'updated'; + $message = '

' . __( 'Warning:' ) . ' '; + $message .= '

' . sprintf( /* translators: %s: mod_rewrite */ __( 'Please make sure the Apache %s module is installed as it will be used at the end of this installation.' ), 'mod_rewrite' - ); - echo '

'; + ) . '

'; } elseif ( $is_apache ) { - echo '

' . __( 'Warning:' ) . ' '; - printf( + $message_class = 'error'; + $message = '

' . __( 'Warning:' ) . ' '; + $message .= sprintf( /* translators: %s: mod_rewrite */ __( 'It looks like the Apache %s module is not installed.' ), 'mod_rewrite' - ); - echo '

'; + ) . '

'; } if ( $got_mod_rewrite || $is_apache ) { // Protect against mod_rewrite mimicry (but ! Apache). - echo '

'; - printf( + $message .= '

' . sprintf( /* translators: 1: mod_rewrite, 2: mod_rewrite documentation URL, 3: Google search for mod_rewrite. */ __( 'If %1$s is disabled, ask your administrator to enable that module, or look at the Apache documentation or elsewhere for help setting it up.' ), 'mod_rewrite', 'https://httpd.apache.org/docs/mod/mod_rewrite.html', 'https://www.google.com/search?q=apache+mod_rewrite' + ) . '

'; + + wp_admin_notice( + $message, + array( + 'additional_classes' => array( $message_class, 'inline' ), + 'paragraph_wrap' => false, + ) ); - echo '

'; } } @@ -263,7 +290,14 @@ function network_step1( $errors = false ) { endif; if ( WP_CONTENT_DIR !== ABSPATH . 'wp-content' && ( allow_subdirectory_install() || ! allow_subdomain_install() ) ) { - echo '

' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '

'; + $subdirectory_warning_message = '' . __( 'Warning:' ) . ' '; + $subdirectory_warning_message .= __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ); + wp_admin_notice( + $subdirectory_warning_message, + array( + 'additional_classes' => array( 'error', 'inline' ), + ) + ); } $is_www = str_starts_with( $hostname, 'www.' ); @@ -409,7 +443,12 @@ function network_step2( $errors = false ) { // Wildcard DNS message. if ( is_wp_error( $errors ) ) { - echo '
' . $errors->get_error_message() . '
'; + wp_admin_notice( + $errors->get_error_message(), + array( + 'additional_classes' => array( 'error' ), + ) + ); } if ( $_POST ) { @@ -426,8 +465,14 @@ function network_step2( $errors = false ) { get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" ); + + wp_admin_notice( + '' . __( 'Warning:' ) . ' ' . __( 'An existing WordPress network was detected.' ), + array( + 'additional_classes' => array( 'error' ), + ) + ); ?> -

-

-

- ' . __( 'Before you can upload your import file, you will need to fix the following error:' ) . '

'; + $upload_directory_error .= '

' . $upload_dir['error'] . '

'; + wp_admin_notice( + $upload_directory_error, + array( + 'additonal_classes' => array( 'error' ), + 'paragraph_wrap' => false, + ) + ); else : ?> @@ -1434,16 +1439,17 @@ function do_meta_boxes( $screen, $context, $data_object ) { if ( WP_DEBUG && ! $block_compatible && 'edit' === $screen->parent_base && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-loader'] ) ) { $plugin = _get_plugin_from_callback( $box['callback'] ); if ( $plugin ) { - ?> -
-

- {$plugin['Name']}" ); - ?> -

-
- {$plugin['Name']}" + ); + wp_admin_notice( + $meta_box_not_compatible_message, + array( + 'additional_classes' => array( 'error', 'inline' ), + ) + ); } } @@ -2695,17 +2701,22 @@ function convert_to_screen( $hook_name ) { * @access private */ function _local_storage_notice() { - ?> - - '; + $local_storage_message .= __( 'The backup of this post in your browser is different from the version below.' ); + $local_storage_message .= '

'; + $local_storage_message .= '

'; + $local_storage_message .= __( 'This will replace the current editor content with the last backup version. You can use undo and redo in the editor to get the old content back or to return to the restored version.' ); + $local_storage_message .= '

'; + + wp_admin_notice( + $local_storage_message, + array( + 'id' => 'local-storage-notice', + 'additional_classes' => array( 'hidden' ), + 'dismissible' => true, + 'paragraph_wrap' => false, + ) + ); } /** diff --git a/src/wp-admin/includes/update.php b/src/wp-admin/includes/update.php index d4628f531ff9a..2d3ccfbbb3e0f 100644 --- a/src/wp-admin/includes/update.php +++ b/src/wp-admin/includes/update.php @@ -342,7 +342,14 @@ function update_nag() { ); } - echo "
$msg
"; + wp_admin_notice( + $msg, + array( + 'type' => 'warning', + 'additonal_classes' => array( 'update-nag', 'inline' ), + 'paragraph_wrap' => false, + ) + ); } /** @@ -884,7 +891,14 @@ function maintenance_nag() { $msg = __( 'An automated WordPress update has failed to complete! Please notify the site administrator.' ); } - echo "
$msg
"; + wp_admin_notice( + $msg, + array( + 'type' => 'warning', + 'additional_classes' => array( 'update-nag', 'inline' ), + 'paragraph_wrap' => false, + ) + ); } /** diff --git a/src/wp-admin/includes/user.php b/src/wp-admin/includes/user.php index 1d2d919348c79..e19727401d89d 100644 --- a/src/wp-admin/includes/user.php +++ b/src/wp-admin/includes/user.php @@ -535,28 +535,30 @@ function default_password_nag() { if ( 'profile.php' === $pagenow || ! get_user_option( 'default_password_nag' ) ) { return; } - ?> -
-

- - -

-

- %2$s | ', - esc_url( get_edit_profile_url() . '#password' ), - __( 'Yes, take me to my profile page' ) - ); - printf( - '%2$s', - '?default_password_nag=0', - __( 'No thanks, do not remind me again' ) - ); - ?> -

-
- %1$s %2$s

', + __( 'Notice:' ), + __( 'You are using the auto-generated password for your account. Would you like to change it?' ) + ); + $default_password_nag_message .= sprintf( + '

%2$s | ', + esc_url( get_edit_profile_url() . '#password' ), + __( 'Yes, take me to my profile page' ) + ); + $default_password_nag_message .= sprintf( + '%2$s

', + '?default_password_nag=0', + __( 'No thanks, do not remind me again' ) + ); + + wp_admin_notice( + $default_password_nag_message, + array( + 'additional_classes' => array( 'error', 'default-password-nag' ), + 'paragraph_wrap' => false, + ) + ); } /**