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.
Built from https://develop.svn.wordpress.org/trunk@56571


git-svn-id: http://core.svn.wordpress.org/trunk@56083 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2023-09-14 01:13:20 +00:00
parent 0f4010bd49
commit 008a32110f
14 changed files with 186 additions and 117 deletions

View File

@ -239,21 +239,24 @@ class Custom_Background {
<div class="wrap" id="custom-background"> <div class="wrap" id="custom-background">
<h1><?php _e( 'Custom Background' ); ?></h1> <h1><?php _e( 'Custom Background' ); ?></h1>
<?php if ( current_user_can( 'customize' ) ) { ?> <?php
<div class="notice notice-info hide-if-no-customize"> if ( current_user_can( 'customize' ) ) {
<p> $message = sprintf(
<?php
printf(
/* translators: %s: URL to background image configuration in Customizer. */ /* translators: %s: URL to background image configuration in Customizer. */
__( 'You can now manage and live-preview Custom Backgrounds in the <a href="%s">Customizer</a>.' ), __( 'You can now manage and live-preview Custom Backgrounds in the <a href="%s">Customizer</a>.' ),
admin_url( 'customize.php?autofocus[control]=background_image' ) admin_url( 'customize.php?autofocus[control]=background_image' )
); );
?> wp_admin_notice(
</p> $message,
</div> array(
<?php } ?> 'type' => 'info',
'additional_classes' => array( 'hide-if-no-customize' ),
)
);
}
<?php if ( ! empty( $this->updated ) ) { ?> if ( ! empty( $this->updated ) ) {
?>
<div id="message" class="updated"> <div id="message" class="updated">
<p> <p>
<?php <?php

View File

@ -509,19 +509,22 @@ class Custom_Image_Header {
<div class="wrap"> <div class="wrap">
<h1><?php _e( 'Custom Header' ); ?></h1> <h1><?php _e( 'Custom Header' ); ?></h1>
<?php if ( current_user_can( 'customize' ) ) { ?> <?php
<div class="notice notice-info hide-if-no-customize"> if ( current_user_can( 'customize' ) ) {
<p> $message = sprintf(
<?php
printf(
/* translators: %s: URL to header image configuration in Customizer. */ /* translators: %s: URL to header image configuration in Customizer. */
__( 'You can now manage and live-preview Custom Header in the <a href="%s">Customizer</a>.' ), __( 'You can now manage and live-preview Custom Header in the <a href="%s">Customizer</a>.' ),
admin_url( 'customize.php?autofocus[control]=header_image' ) admin_url( 'customize.php?autofocus[control]=header_image' )
); );
?> wp_admin_notice(
</p> $message,
</div> array(
<?php } ?> 'type' => 'info',
'additional_classes' => array( 'hide-if-no-customize' ),
)
);
}
?>
<?php if ( ! empty( $this->updated ) ) { ?> <?php if ( ! empty( $this->updated ) ) { ?>
<div id="message" class="updated"> <div id="message" class="updated">

View File

@ -686,52 +686,59 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
<div class="plugin-card plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>"> <div class="plugin-card plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
<?php <?php
if ( ! $compatible_php || ! $compatible_wp ) { if ( ! $compatible_php || ! $compatible_wp ) {
echo '<div class="notice inline notice-error notice-alt"><p>'; $incompatible_notice_message = '';
if ( ! $compatible_php && ! $compatible_wp ) { 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' ) ) { 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. */ /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ), ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
self_admin_url( 'update-core.php' ), self_admin_url( 'update-core.php' ),
esc_url( wp_get_update_php_url() ) esc_url( wp_get_update_php_url() )
); );
wp_update_php_annotation( '</p><p><em>', '</em>' ); $incompatible_notice_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
} elseif ( current_user_can( 'update_core' ) ) { } elseif ( current_user_can( 'update_core' ) ) {
printf( $incompatible_notice_message .= sprintf(
/* translators: %s: URL to WordPress Updates screen. */ /* translators: %s: URL to WordPress Updates screen. */
' ' . __( '<a href="%s">Please update WordPress</a>.' ), ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
self_admin_url( 'update-core.php' ) self_admin_url( 'update-core.php' )
); );
} elseif ( current_user_can( 'update_php' ) ) { } elseif ( current_user_can( 'update_php' ) ) {
printf( $incompatible_notice_message .= sprintf(
/* translators: %s: URL to Update PHP page. */ /* translators: %s: URL to Update PHP page. */
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() ) esc_url( wp_get_update_php_url() )
); );
wp_update_php_annotation( '</p><p><em>', '</em>' ); $incompatible_notice_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
} }
} elseif ( ! $compatible_wp ) { } 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' ) ) { if ( current_user_can( 'update_core' ) ) {
printf( $incompatible_notice_message .= printf(
/* translators: %s: URL to WordPress Updates screen. */ /* translators: %s: URL to WordPress Updates screen. */
' ' . __( '<a href="%s">Please update WordPress</a>.' ), ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
self_admin_url( 'update-core.php' ) self_admin_url( 'update-core.php' )
); );
} }
} elseif ( ! $compatible_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' ) ) { if ( current_user_can( 'update_php' ) ) {
printf( $incompatible_notice_message .= sprintf(
/* translators: %s: URL to Update PHP page. */ /* translators: %s: URL to Update PHP page. */
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() ) esc_url( wp_get_update_php_url() )
); );
wp_update_php_annotation( '</p><p><em>', '</em>' ); $incompatible_notice_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
} }
} }
echo '</p></div>';
wp_admin_notice(
$incompatible_notice_message,
array(
'type' => 'error',
'additional_classes' => array( 'notice-alt', 'inline' ),
)
);
} }
?> ?>
<div class="plugin-card-top"> <div class="plugin-card-top">

View File

@ -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 apply_filters( 'plugin_auto_update_setting_html', $html, $plugin_file, $plugin_data );
echo '<div class="notice notice-error notice-alt inline hidden"><p></p></div>'; wp_admin_notice(
'',
array(
'type' => 'error',
'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ),
)
);
echo '</td>'; echo '</td>';
break; break;

View File

@ -2076,9 +2076,16 @@ class WP_Posts_List_Table extends WP_List_Table {
<input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" /> <input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
<?php endif; ?> <?php endif; ?>
<div class="notice notice-error notice-alt inline hidden"> <?php
<p class="error"></p> wp_admin_notice(
</div> '<p class="error"></p>',
array(
'type' => 'error',
'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ),
'paragraph_wrap' => false,
)
);
?>
</div> </div>
</div> <!-- end of .inline-edit-wrapper --> </div> <!-- end of .inline-edit-wrapper -->

View File

@ -352,22 +352,20 @@ final class WP_Privacy_Policy_Content {
'after' 'after'
); );
} else { } else {
?> $message .= sprintf(
<div class="notice notice-warning inline wp-pp-notice"> ' <a href="%s" target="_blank">%s <span class="screen-reader-text">%s</span></a>',
<p> $url,
<?php $label,
echo $message; /* translators: Hidden accessibility text. */
printf( __( '(opens in a new tab)' )
' <a href="%s" target="_blank">%s <span class="screen-reader-text">%s</span></a>', );
$url, wp_admin_notice(
$label, $message,
/* translators: Hidden accessibility text. */ array(
__( '(opens in a new tab)' ) 'type' => 'warning',
); 'additional_classes' => array( 'inline', 'wp-pp-notice' ),
?> )
</p> );
</div>
<?php
} }
} }
@ -394,8 +392,14 @@ final class WP_Privacy_Policy_Content {
$badge_title = sprintf( __( 'Removed %s.' ), $date ); $badge_title = sprintf( __( 'Removed %s.' ), $date );
/* translators: %s: Date of plugin deactivation. */ /* translators: %s: Date of plugin deactivation. */
$removed = __( 'You deactivated this plugin on %s and may no longer need this policy.' ); $removed = sprintf( __( 'You deactivated this plugin on %s and may no longer need this policy.' ), $date );
$removed = '<div class="notice notice-info inline"><p>' . sprintf( $removed, $date ) . '</p></div>'; $removed = wp_get_admin_notice(
$removed,
array(
'type' => 'info',
'additional_classes' => array( 'inline' ),
)
);
} elseif ( ! empty( $section['updated'] ) ) { } elseif ( ! empty( $section['updated'] ) ) {
$badge_class = ' blue'; $badge_class = ' blue';
$date = date_i18n( $date_format, $section['updated'] ); $date = date_i18n( $date_format, $section['updated'] );

View File

@ -711,9 +711,16 @@ class WP_Terms_List_Table extends WP_List_Table {
<input type="hidden" name="taxonomy" value="<?php echo esc_attr( $this->screen->taxonomy ); ?>" /> <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $this->screen->taxonomy ); ?>" />
<input type="hidden" name="post_type" value="<?php echo esc_attr( $this->screen->post_type ); ?>" /> <input type="hidden" name="post_type" value="<?php echo esc_attr( $this->screen->post_type ); ?>" />
<div class="notice notice-error notice-alt inline hidden"> <?php
<p class="error"></p> wp_admin_notice(
</div> '<p class="error"></p>',
array(
'type' => 'error',
'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ),
'paragraph_wrap' => false,
)
);
?>
</div> </div>
</div> </div>

View File

@ -311,25 +311,24 @@ function post_submit_meta_box( $post, $args = array() ) {
endif; endif;
if ( 'draft' === $post->post_status && get_post_meta( $post_id, '_customize_changeset_uuid', true ) ) : if ( 'draft' === $post->post_status && get_post_meta( $post_id, '_customize_changeset_uuid', true ) ) :
?> $message = sprintf(
<div class="notice notice-info notice-alt inline"> /* translators: %s: URL to the Customizer. */
<p> __( 'This draft comes from your <a href="%s">unpublished customization changes</a>. You can edit, but there is no need to publish now. It will be published automatically with those changes.' ),
<?php esc_url(
printf( add_query_arg(
/* translators: %s: URL to the Customizer. */ 'changeset_uuid',
__( 'This draft comes from your <a href="%s">unpublished customization changes</a>. You can edit, but there is no need to publish now. It will be published automatically with those changes.' ), rawurlencode( get_post_meta( $post_id, '_customize_changeset_uuid', true ) ),
esc_url( admin_url( 'customize.php' )
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' ),
</p> )
</div> );
<?php
endif; endif;
/** /**

View File

@ -817,37 +817,54 @@ function install_plugin_information() {
$tested_wp = ( empty( $api->tested ) || version_compare( get_bloginfo( 'version' ), $api->tested, '<=' ) ); $tested_wp = ( empty( $api->tested ) || version_compare( get_bloginfo( 'version' ), $api->tested, '<=' ) );
if ( ! $compatible_php ) { if ( ! $compatible_php ) {
echo '<div class="notice notice-error notice-alt"><p>'; $compatible_php_notice_message = '<p>';
_e( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>.' ); $compatible_php_notice_message .= __( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>.' );
if ( current_user_can( 'update_php' ) ) { if ( current_user_can( 'update_php' ) ) {
printf( $compatible_php_notice_message .= sprintf(
/* translators: %s: URL to Update PHP page. */ /* translators: %s: URL to Update PHP page. */
' ' . __( '<a href="%s" target="_blank">Click here to learn more about updating PHP</a>.' ), ' ' . __( '<a href="%s" target="_blank">Click here to learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() ) esc_url( wp_get_update_php_url() )
); ) . wp_update_php_annotation( '</p><p><em>', '</em>', false );
wp_update_php_annotation( '</p><p><em>', '</em>' );
} else { } else {
echo '</p>'; $compatible_php_notice_message .= '</p>';
} }
echo '</div>';
wp_admin_notice(
$compatible_php_notice_message,
array(
'type' => 'error',
'additional_classes' => array( 'notice-alt' ),
'paragraph_wrap' => false,
)
);
} }
if ( ! $tested_wp ) { if ( ! $tested_wp ) {
echo '<div class="notice notice-warning notice-alt"><p>'; wp_admin_notice(
_e( '<strong>Warning:</strong> This plugin <strong>has not been tested</strong> with your current version of WordPress.' ); __( '<strong>Warning:</strong> This plugin <strong>has not been tested</strong> with your current version of WordPress.' ),
echo '</p></div>'; array(
'type' => 'warning',
'additional_classes' => array( 'notice-alt' ),
)
);
} elseif ( ! $compatible_wp ) { } elseif ( ! $compatible_wp ) {
echo '<div class="notice notice-error notice-alt"><p>'; $compatible_wp_notice_message = __( '<strong>Error:</strong> This plugin <strong>requires a newer version of WordPress</strong>.' );
_e( '<strong>Error:</strong> This plugin <strong>requires a newer version of WordPress</strong>.' );
if ( current_user_can( 'update_core' ) ) { if ( current_user_can( 'update_core' ) ) {
printf( $compatible_wp_notice_message .= sprintf(
/* translators: %s: URL to WordPress Updates screen. */ /* translators: %s: URL to WordPress Updates screen. */
' ' . __( '<a href="%s" target="_parent">Click here to update WordPress</a>.' ), ' ' . __( '<a href="%s" target="_parent">Click here to update WordPress</a>.' ),
esc_url( self_admin_url( 'update-core.php' ) ) esc_url( self_admin_url( 'update-core.php' ) )
); );
} }
echo '</p></div>';
wp_admin_notice(
$compatible_wp_notice_message,
array(
'type' => 'error',
'additional_classes' => array( 'notice-alt' ),
)
);
} }
foreach ( (array) $api->sections as $section_name => $content ) { foreach ( (array) $api->sections as $section_name => $content ) {

View File

@ -2497,13 +2497,17 @@ function paused_plugins_notice() {
return; return;
} }
printf( $message = sprintf(
'<div class="notice notice-error"><p><strong>%s</strong><br>%s</p><p><a href="%s">%s</a></p></div>', '<strong>%s</strong><br>%s</p><p><a href="%s">%s</a>',
__( 'One or more plugins failed to load properly.' ), __( 'One or more plugins failed to load properly.' ),
__( 'You can find more details and make changes on the Plugins screen.' ), __( 'You can find more details and make changes on the Plugins screen.' ),
esc_url( admin_url( 'plugins.php?plugin_status=paused' ) ), esc_url( admin_url( 'plugins.php?plugin_status=paused' ) ),
__( 'Go to the Plugins screen' ) __( 'Go to the Plugins screen' )
); );
wp_admin_notice(
$message,
array( 'type' => 'error' )
);
} }
/** /**
@ -2571,8 +2575,8 @@ function deactivated_plugins_notice() {
); );
} }
printf( $message = sprintf(
'<div class="notice notice-warning"><p><strong>%s</strong><br>%s</p><p><a href="%s">%s</a></p></div>', '<strong>%s</strong><br>%s</p><p><a href="%s">%s</a>',
sprintf( sprintf(
/* translators: %s: Name of deactivated plugin. */ /* translators: %s: Name of deactivated plugin. */
__( '%s plugin deactivated during WordPress upgrade.' ), __( '%s plugin deactivated during WordPress upgrade.' ),
@ -2582,6 +2586,7 @@ function deactivated_plugins_notice() {
esc_url( admin_url( 'plugins.php?plugin_status=inactive' ) ), esc_url( admin_url( 'plugins.php?plugin_status=inactive' ) ),
__( 'Go to the Plugins screen' ) __( 'Go to the Plugins screen' )
); );
wp_admin_notice( $message, array( 'type' => 'warning' ) );
} }
// Empty the options. // Empty the options.

View File

@ -512,9 +512,16 @@ function wp_comment_reply( $position = 1, $checkbox = false, $mode = 'single', $
<button type="button" class="cancel button"><?php _e( 'Cancel' ); ?></button> <button type="button" class="cancel button"><?php _e( 'Cancel' ); ?></button>
<span class="waiting spinner"></span> <span class="waiting spinner"></span>
</p> </p>
<div class="notice notice-error notice-alt inline hidden"> <?php
<p class="error"></p> wp_admin_notice(
</div> '<p class="error"></p>',
array(
'type' => 'error',
'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ),
'paragraph_wrap' => false,
)
);
?>
</div> </div>
<input type="hidden" name="action" id="action" value="" /> <input type="hidden" name="action" id="action" value="" />
@ -2776,9 +2783,12 @@ function wp_star_rating( $args = array() ) {
* @since 4.2.0 * @since 4.2.0
*/ */
function _wp_posts_page_notice() { function _wp_posts_page_notice() {
printf( wp_admin_notice(
'<div class="notice notice-warning inline"><p>%s</p></div>', __( 'You are currently editing the page that shows your latest posts.' ),
__( 'You are currently editing the page that shows your latest posts.' ) array(
'type' => 'warning',
'additional_classes' => array( 'inline' ),
)
); );
} }

View File

@ -1224,11 +1224,18 @@ function paused_themes_notice() {
return; return;
} }
printf( $message = sprintf(
'<div class="notice notice-error"><p><strong>%s</strong><br>%s</p><p><a href="%s">%s</a></p></div>', '<p><strong>%s</strong><br>%s</p><p><a href="%s">%s</a></p>',
__( 'One or more themes failed to load properly.' ), __( 'One or more themes failed to load properly.' ),
__( 'You can find more details and make changes on the Themes screen.' ), __( 'You can find more details and make changes on the Themes screen.' ),
esc_url( admin_url( 'themes.php' ) ), esc_url( admin_url( 'themes.php' ) ),
__( 'Go to the Themes screen' ) __( 'Go to the Themes screen' )
); );
wp_admin_notice(
$message,
array(
'type' => 'error',
'paragraph_wrap' => false,
)
);
} }

View File

@ -1049,19 +1049,12 @@ function wp_recovery_mode_nag() {
$url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url ); $url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url );
$url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION ); $url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION );
?> $message = sprintf(
<div class="notice notice-info"> /* translators: %s: Recovery Mode exit link. */
<p> __( 'You are in recovery mode. This means there may be an error with a theme or plugin. To exit recovery mode, log out or use the Exit button. <a href="%s">Exit Recovery Mode</a>' ),
<?php esc_url( $url )
printf( );
/* translators: %s: Recovery Mode exit link. */ wp_admin_notice( $message, array( 'type' => 'info' ) );
__( 'You are in recovery mode. This means there may be an error with a theme or plugin. To exit recovery mode, log out or use the Exit button. <a href="%s">Exit Recovery Mode</a>' ),
esc_url( $url )
);
?>
</p>
</div>
<?php
} }
/** /**

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.4-alpha-56570'; $wp_version = '6.4-alpha-56571';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.