From fa21528a9aff81fb62d18bbee8f68ad009bee36e Mon Sep 17 00:00:00 2001 From: Joe Dolson Date: Thu, 14 Sep 2023 01:11:29 +0000 Subject: [PATCH] Administration: Use `wp_admin_notice()` in `/wp-admin/includes`. Add usages of `wp_admin_notice()` and `wp_get_admin_notice()` on `.notice-[type]` in the root level of `/wp-admin/includes`. Ongoing task to implement new function across core. Props costdev, joedolson. See #57791. git-svn-id: https://develop.svn.wordpress.org/trunk@56571 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-custom-background.php | 23 +++++---- .../includes/class-custom-image-header.php | 21 +++++---- .../class-wp-plugin-install-list-table.php | 33 ++++++++----- .../includes/class-wp-plugins-list-table.php | 9 +++- .../includes/class-wp-posts-list-table.php | 13 +++-- .../class-wp-privacy-policy-content.php | 40 +++++++++------- .../includes/class-wp-terms-list-table.php | 13 +++-- src/wp-admin/includes/meta-boxes.php | 37 +++++++-------- src/wp-admin/includes/plugin-install.php | 47 +++++++++++++------ src/wp-admin/includes/plugin.php | 13 +++-- src/wp-admin/includes/template.php | 22 ++++++--- src/wp-admin/includes/theme.php | 11 ++++- src/wp-admin/includes/update.php | 19 +++----- 13 files changed, 185 insertions(+), 116 deletions(-) diff --git a/src/wp-admin/includes/class-custom-background.php b/src/wp-admin/includes/class-custom-background.php index e8aee43c2e..a2be358e77 100644 --- a/src/wp-admin/includes/class-custom-background.php +++ b/src/wp-admin/includes/class-custom-background.php @@ -239,21 +239,24 @@ class Custom_Background {

- -
-

- Customizer.' ), admin_url( 'customize.php?autofocus[control]=background_image' ) ); - ?> -

-
- + wp_admin_notice( + $message, + array( + 'type' => 'info', + 'additional_classes' => array( 'hide-if-no-customize' ), + ) + ); + } - updated ) ) { ?> + if ( ! empty( $this->updated ) ) { + ?>

- -
-

- Customizer.' ), admin_url( 'customize.php?autofocus[control]=header_image' ) ); - ?> -

-
- + wp_admin_notice( + $message, + array( + 'type' => 'info', + 'additional_classes' => array( 'hide-if-no-customize' ), + ) + ); + } + ?> 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 ee744dec9d..330a35e624 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 @@ -686,52 +686,59 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {

'; + $incompatible_notice_message = ''; if ( ! $compatible_php && ! $compatible_wp ) { - _e( 'This plugin does not work with your versions of WordPress and PHP.' ); + $incompatible_notice_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_notice_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_notice_message .= wp_update_php_annotation( '

', '', false ); } elseif ( current_user_can( 'update_core' ) ) { - printf( + $incompatible_notice_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_notice_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_notice_message .= wp_update_php_annotation( '

', '', false ); } } elseif ( ! $compatible_wp ) { - _e( 'This plugin does not work with your version of WordPress.' ); + $incompatible_notice_message .= __( 'This plugin does not work with your version of WordPress.' ); if ( current_user_can( 'update_core' ) ) { - printf( + $incompatible_notice_message .= printf( /* 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_notice_message .= __( 'This plugin does not work with your version of PHP.' ); if ( current_user_can( 'update_php' ) ) { - printf( + $incompatible_notice_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_notice_message .= wp_update_php_annotation( '

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

'; + + wp_admin_notice( + $incompatible_notice_message, + array( + 'type' => 'error', + 'additional_classes' => array( 'notice-alt', 'inline' ), + ) + ); } ?>
diff --git a/src/wp-admin/includes/class-wp-plugins-list-table.php b/src/wp-admin/includes/class-wp-plugins-list-table.php index b633fcd116..008387678b 100644 --- a/src/wp-admin/includes/class-wp-plugins-list-table.php +++ b/src/wp-admin/includes/class-wp-plugins-list-table.php @@ -1243,7 +1243,14 @@ class WP_Plugins_List_Table extends WP_List_Table { */ echo apply_filters( 'plugin_auto_update_setting_html', $html, $plugin_file, $plugin_data ); - echo ''; + wp_admin_notice( + '', + array( + 'type' => 'error', + 'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ), + ) + ); + echo ''; break; diff --git a/src/wp-admin/includes/class-wp-posts-list-table.php b/src/wp-admin/includes/class-wp-posts-list-table.php index abb305f8e4..74867e2bf3 100644 --- a/src/wp-admin/includes/class-wp-posts-list-table.php +++ b/src/wp-admin/includes/class-wp-posts-list-table.php @@ -2076,9 +2076,16 @@ class WP_Posts_List_Table extends WP_List_Table { - +

', + array( + 'type' => 'error', + 'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ), + 'paragraph_wrap' => false, + ) + ); + ?>
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 aa72b21aa7..31f776f09c 100644 --- a/src/wp-admin/includes/class-wp-privacy-policy-content.php +++ b/src/wp-admin/includes/class-wp-privacy-policy-content.php @@ -352,22 +352,20 @@ final class WP_Privacy_Policy_Content { 'after' ); } else { - ?> -
-

- %s %s', - $url, - $label, - /* translators: Hidden accessibility text. */ - __( '(opens in a new tab)' ) - ); - ?> -

-
- %s %s', + $url, + $label, + /* translators: Hidden accessibility text. */ + __( '(opens in a new tab)' ) + ); + wp_admin_notice( + $message, + array( + 'type' => 'warning', + 'additional_classes' => array( 'inline', 'wp-pp-notice' ), + ) + ); } } @@ -394,8 +392,14 @@ final class WP_Privacy_Policy_Content { $badge_title = sprintf( __( 'Removed %s.' ), $date ); /* translators: %s: Date of plugin deactivation. */ - $removed = __( 'You deactivated this plugin on %s and may no longer need this policy.' ); - $removed = '

' . sprintf( $removed, $date ) . '

'; + $removed = sprintf( __( 'You deactivated this plugin on %s and may no longer need this policy.' ), $date ); + $removed = wp_get_admin_notice( + $removed, + array( + 'type' => 'info', + 'additional_classes' => array( 'inline' ), + ) + ); } elseif ( ! empty( $section['updated'] ) ) { $badge_class = ' blue'; $date = date_i18n( $date_format, $section['updated'] ); diff --git a/src/wp-admin/includes/class-wp-terms-list-table.php b/src/wp-admin/includes/class-wp-terms-list-table.php index 8778e54200..8d2b0519a3 100644 --- a/src/wp-admin/includes/class-wp-terms-list-table.php +++ b/src/wp-admin/includes/class-wp-terms-list-table.php @@ -711,9 +711,16 @@ class WP_Terms_List_Table extends WP_List_Table { - +

', + array( + 'type' => 'error', + 'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ), + 'paragraph_wrap' => false, + ) + ); + ?>
diff --git a/src/wp-admin/includes/meta-boxes.php b/src/wp-admin/includes/meta-boxes.php index 0584a2edc4..c63474b29a 100644 --- a/src/wp-admin/includes/meta-boxes.php +++ b/src/wp-admin/includes/meta-boxes.php @@ -311,25 +311,24 @@ function post_submit_meta_box( $post, $args = array() ) { endif; if ( 'draft' === $post->post_status && get_post_meta( $post_id, '_customize_changeset_uuid', true ) ) : - ?> -
-

- unpublished customization changes. You can edit, but there is no need to publish now. It will be published automatically with those changes.' ), - esc_url( - add_query_arg( - 'changeset_uuid', - rawurlencode( get_post_meta( $post_id, '_customize_changeset_uuid', true ) ), - admin_url( 'customize.php' ) - ) - ) - ); - ?> -

-
- unpublished customization changes. You can edit, but there is no need to publish now. It will be published automatically with those changes.' ), + esc_url( + add_query_arg( + 'changeset_uuid', + rawurlencode( get_post_meta( $post_id, '_customize_changeset_uuid', true ) ), + admin_url( 'customize.php' ) + ) + ) + ); + wp_admin_notice( + $message, + array( + 'type' => 'info', + 'additional_classes' => array( 'notice-alt', 'inline' ), + ) + ); endif; /** diff --git a/src/wp-admin/includes/plugin-install.php b/src/wp-admin/includes/plugin-install.php index 8bb1b61072..7662076581 100644 --- a/src/wp-admin/includes/plugin-install.php +++ b/src/wp-admin/includes/plugin-install.php @@ -817,37 +817,54 @@ function install_plugin_information() { $tested_wp = ( empty( $api->tested ) || version_compare( get_bloginfo( 'version' ), $api->tested, '<=' ) ); if ( ! $compatible_php ) { - echo '

'; - _e( 'Error: This plugin requires a newer version of PHP.' ); + $compatible_php_notice_message = '

'; + $compatible_php_notice_message .= __( 'Error: This plugin requires a newer version of PHP.' ); + if ( current_user_can( 'update_php' ) ) { - printf( + $compatible_php_notice_message .= sprintf( /* translators: %s: URL to Update PHP page. */ ' ' . __( 'Click here to learn more about updating PHP.' ), esc_url( wp_get_update_php_url() ) - ); - - wp_update_php_annotation( '

', '' ); + ) . wp_update_php_annotation( '

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

'; + $compatible_php_notice_message .= '

'; } - echo '
'; + + wp_admin_notice( + $compatible_php_notice_message, + array( + 'type' => 'error', + 'additional_classes' => array( 'notice-alt' ), + 'paragraph_wrap' => false, + ) + ); } if ( ! $tested_wp ) { - echo '

'; - _e( 'Warning: This plugin has not been tested with your current version of WordPress.' ); - echo '

'; + wp_admin_notice( + __( 'Warning: This plugin has not been tested with your current version of WordPress.' ), + array( + 'type' => 'warning', + 'additional_classes' => array( 'notice-alt' ), + ) + ); } elseif ( ! $compatible_wp ) { - echo '

'; - _e( 'Error: This plugin requires a newer version of WordPress.' ); + $compatible_wp_notice_message = __( 'Error: This plugin requires a newer version of WordPress.' ); if ( current_user_can( 'update_core' ) ) { - printf( + $compatible_wp_notice_message .= sprintf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( 'Click here to update WordPress.' ), esc_url( self_admin_url( 'update-core.php' ) ) ); } - echo '

'; + + wp_admin_notice( + $compatible_wp_notice_message, + array( + 'type' => 'error', + 'additional_classes' => array( 'notice-alt' ), + ) + ); } foreach ( (array) $api->sections as $section_name => $content ) { diff --git a/src/wp-admin/includes/plugin.php b/src/wp-admin/includes/plugin.php index d5e62ed06f..f55bbd80eb 100644 --- a/src/wp-admin/includes/plugin.php +++ b/src/wp-admin/includes/plugin.php @@ -2497,13 +2497,17 @@ function paused_plugins_notice() { return; } - printf( - '

%s
%s

%s

', + $message = sprintf( + '%s
%s

%s', __( 'One or more plugins failed to load properly.' ), __( 'You can find more details and make changes on the Plugins screen.' ), esc_url( admin_url( 'plugins.php?plugin_status=paused' ) ), __( 'Go to the Plugins screen' ) ); + wp_admin_notice( + $message, + array( 'type' => 'error' ) + ); } /** @@ -2571,8 +2575,8 @@ function deactivated_plugins_notice() { ); } - printf( - '

%s
%s

%s

', + $message = sprintf( + '%s
%s

%s', sprintf( /* translators: %s: Name of deactivated plugin. */ __( '%s plugin deactivated during WordPress upgrade.' ), @@ -2582,6 +2586,7 @@ function deactivated_plugins_notice() { esc_url( admin_url( 'plugins.php?plugin_status=inactive' ) ), __( 'Go to the Plugins screen' ) ); + wp_admin_notice( $message, array( 'type' => 'warning' ) ); } // Empty the options. diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php index 0a3699672d..2f28397ec9 100644 --- a/src/wp-admin/includes/template.php +++ b/src/wp-admin/includes/template.php @@ -512,9 +512,16 @@ function wp_comment_reply( $position = 1, $checkbox = false, $mode = 'single', $

- +

', + array( + 'type' => 'error', + 'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ), + 'paragraph_wrap' => false, + ) + ); + ?> @@ -2776,9 +2783,12 @@ function wp_star_rating( $args = array() ) { * @since 4.2.0 */ function _wp_posts_page_notice() { - printf( - '

%s

', - __( 'You are currently editing the page that shows your latest posts.' ) + wp_admin_notice( + __( 'You are currently editing the page that shows your latest posts.' ), + array( + 'type' => 'warning', + 'additional_classes' => array( 'inline' ), + ) ); } diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index b0b3c6d768..6bb450ee1b 100644 --- a/src/wp-admin/includes/theme.php +++ b/src/wp-admin/includes/theme.php @@ -1224,11 +1224,18 @@ function paused_themes_notice() { return; } - printf( - '

%s
%s

%s

', + $message = sprintf( + '

%s
%s

%s

', __( 'One or more themes failed to load properly.' ), __( 'You can find more details and make changes on the Themes screen.' ), esc_url( admin_url( 'themes.php' ) ), __( 'Go to the Themes screen' ) ); + wp_admin_notice( + $message, + array( + 'type' => 'error', + 'paragraph_wrap' => false, + ) + ); } diff --git a/src/wp-admin/includes/update.php b/src/wp-admin/includes/update.php index 78ca061f2e..d4628f531f 100644 --- a/src/wp-admin/includes/update.php +++ b/src/wp-admin/includes/update.php @@ -1049,19 +1049,12 @@ function wp_recovery_mode_nag() { $url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url ); $url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION ); - ?> -
-

- Exit Recovery Mode' ), - esc_url( $url ) - ); - ?> -

-
- Exit Recovery Mode' ), + esc_url( $url ) + ); + wp_admin_notice( $message, array( 'type' => 'info' ) ); } /**