Administration: Apply admin notice functions in multisite.

Use `wp_get_admin_notice` and `wp_admin_notice` to handle multisite settings notices.

Props costdev.
See #57791.
Built from https://develop.svn.wordpress.org/trunk@56409


git-svn-id: http://core.svn.wordpress.org/trunk@55921 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2023-08-17 21:03:19 +00:00
parent d5f3b7feab
commit 82417a694f
14 changed files with 250 additions and 110 deletions

View File

@ -859,7 +859,13 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
*/ */
echo apply_filters( 'theme_auto_update_setting_html', $html, $stylesheet, $theme ); echo apply_filters( 'theme_auto_update_setting_html', $html, $stylesheet, $theme );
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' ),
)
);
} }
/** /**

View File

@ -125,11 +125,14 @@ function network_step1( $errors = false ) {
$active_plugins = get_option( 'active_plugins' ); $active_plugins = get_option( 'active_plugins' );
if ( ! empty( $active_plugins ) ) { if ( ! empty( $active_plugins ) ) {
echo '<div class="notice notice-warning"><p><strong>' . __( 'Warning:' ) . '</strong> ' . sprintf( wp_admin_notice(
/* translators: %s: URL to Plugins screen. */ '<strong>' . __( 'Warning:' ) . '</strong> ' . sprintf(
__( 'Please <a href="%s">deactivate your plugins</a> before enabling the Network feature.' ), /* translators: %s: URL to Plugins screen. */
admin_url( 'plugins.php?plugin_status=active' ) __( 'Please <a href="%s">deactivate your plugins</a> before enabling the Network feature.' ),
) . '</p></div>'; admin_url( 'plugins.php?plugin_status=active' )
),
array( 'type' => 'warning' )
);
echo '<p>' . __( 'Once the network is created, you may reactivate your plugins.' ) . '</p>'; echo '<p>' . __( 'Once the network is created, you may reactivate your plugins.' ) . '</p>';
echo '</div>'; echo '</div>';
require_once ABSPATH . 'wp-admin/admin-footer.php'; require_once ABSPATH . 'wp-admin/admin-footer.php';
@ -438,35 +441,36 @@ function network_step2( $errors = false ) {
?> ?>
<h3><?php esc_html_e( 'Enabling the Network' ); ?></h3> <h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
<p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p> <p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
<div class="notice notice-warning inline"><p>
<?php <?php
$notice_message = '<strong>' . __( 'Caution:' ) . '</strong> ';
$notice_args = array(
'type' => 'warning',
'additional_classes' => 'inline',
);
if ( file_exists( $home_path . '.htaccess' ) ) { if ( file_exists( $home_path . '.htaccess' ) ) {
echo '<strong>' . __( 'Caution:' ) . '</strong> '; $notice_message .= sprintf(
printf(
/* translators: 1: wp-config.php, 2: .htaccess */ /* translators: 1: wp-config.php, 2: .htaccess */
__( 'You should back up your existing %1$s and %2$s files.' ), __( 'You should back up your existing %1$s and %2$s files.' ),
'<code>wp-config.php</code>', '<code>wp-config.php</code>',
'<code>.htaccess</code>' '<code>.htaccess</code>'
); );
} elseif ( file_exists( $home_path . 'web.config' ) ) { } elseif ( file_exists( $home_path . 'web.config' ) ) {
echo '<strong>' . __( 'Caution:' ) . '</strong> '; $notice_message .= sprintf(
printf(
/* translators: 1: wp-config.php, 2: web.config */ /* translators: 1: wp-config.php, 2: web.config */
__( 'You should back up your existing %1$s and %2$s files.' ), __( 'You should back up your existing %1$s and %2$s files.' ),
'<code>wp-config.php</code>', '<code>wp-config.php</code>',
'<code>web.config</code>' '<code>web.config</code>'
); );
} else { } else {
echo '<strong>' . __( 'Caution:' ) . '</strong> '; $notice_message .= sprintf(
printf(
/* translators: %s: wp-config.php */ /* translators: %s: wp-config.php */
__( 'You should back up your existing %s file.' ), __( 'You should back up your existing %s file.' ),
'<code>wp-config.php</code>' '<code>wp-config.php</code>'
); );
} }
?>
</p></div> wp_admin_notice( $notice_message, $notice_args );
<?php
} }
?> ?>
<ol> <ol>

View File

@ -55,9 +55,17 @@ get_current_screen()->set_help_sidebar(
require_once ABSPATH . 'wp-admin/admin-header.php'; require_once ABSPATH . 'wp-admin/admin-header.php';
if ( $updated ) { ?> if ( $updated ) {
<div id="message" class="notice notice-success is-dismissible"><p><strong><?php _e( 'Settings saved.' ); ?></strong></p></div> wp_admin_notice(
<?php } ?> '<strong>' . __( 'Settings saved.' ) . '</strong>',
array(
'type' => 'success',
'dismissible' => true,
'id' => 'message',
)
);
}
?>
<div class="wrap"> <div class="wrap">
<h1 class="wp-heading-inline"> <h1 class="wp-heading-inline">
@ -74,8 +82,14 @@ if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ), true )
} }
if ( empty( $blogs ) ) : if ( empty( $blogs ) ) :
wp_admin_notice(
'<strong>' . __( 'You must be a member of at least one site to use this page.' ) . '</strong>',
array(
'type' => 'error',
'dismissible' => true,
)
);
?> ?>
<div class="notice notice-error is-dismissible"><p><strong><?php _e( 'You must be a member of at least one site to use this page.' ); ?></strong></p></div>
<?php <?php
else : else :
?> ?>

View File

@ -138,9 +138,14 @@ if ( $_POST ) {
require_once ABSPATH . 'wp-admin/admin-header.php'; require_once ABSPATH . 'wp-admin/admin-header.php';
if ( isset( $_GET['updated'] ) ) { if ( isset( $_GET['updated'] ) ) {
?> wp_admin_notice(
<div id="message" class="notice notice-success is-dismissible"><p><?php _e( 'Settings saved.' ); ?></p></div> __( 'Settings saved.' ),
<?php array(
'type' => 'success',
'dismissible' => true,
'id' => 'message',
)
);
} }
?> ?>
@ -167,24 +172,28 @@ if ( isset( $_GET['updated'] ) ) {
<?php <?php
$new_admin_email = get_site_option( 'new_admin_email' ); $new_admin_email = get_site_option( 'new_admin_email' );
if ( $new_admin_email && get_site_option( 'admin_email' ) !== $new_admin_email ) : if ( $new_admin_email && get_site_option( 'admin_email' ) !== $new_admin_email ) :
?> $notice_message = sprintf(
<div class="notice notice-warning is-dismissible inline"> /* translators: %s: New network admin email. */
<p> __( 'There is a pending change of the network admin email to %s.' ),
<?php '<code>' . esc_html( $new_admin_email ) . '</code>'
printf( );
/* translators: %s: New network admin email. */
__( 'There is a pending change of the network admin email to %s.' ), $notice_message .= sprintf(
'<code>' . esc_html( $new_admin_email ) . '</code>' ' <a href="%1$s">%2$s</a>',
); esc_url( wp_nonce_url( network_admin_url( 'settings.php?dismiss=new_network_admin_email' ), 'dismiss_new_network_admin_email' ) ),
printf( __( 'Cancel' )
' <a href="%1$s">%2$s</a>', );
esc_url( wp_nonce_url( network_admin_url( 'settings.php?dismiss=new_network_admin_email' ), 'dismiss_new_network_admin_email' ) ),
__( 'Cancel' ) wp_admin_notice(
); $notice_message,
?> array(
</p> 'type' => 'warning',
</div> 'dismissible' => true,
<?php endif; ?> 'additional_classes' => array( 'inline' ),
)
);
endif;
?>
</td> </td>
</tr> </tr>
</table> </table>

View File

@ -146,8 +146,14 @@ network_edit_site_nav(
); );
if ( ! empty( $messages ) ) { if ( ! empty( $messages ) ) {
$notice_args = array(
'type' => 'success',
'dismissible' => true,
'id' => 'message',
);
foreach ( $messages as $msg ) { foreach ( $messages as $msg ) {
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . $msg . '</p></div>'; wp_admin_notice( $msg, $notice_args );
} }
} }
?> ?>

View File

@ -192,8 +192,14 @@ require_once ABSPATH . 'wp-admin/admin-header.php';
<h1 id="add-new-site"><?php _e( 'Add New Site' ); ?></h1> <h1 id="add-new-site"><?php _e( 'Add New Site' ); ?></h1>
<?php <?php
if ( ! empty( $messages ) ) { if ( ! empty( $messages ) ) {
$notice_args = array(
'type' => 'success',
'dismissible' => true,
'id' => 'message',
);
foreach ( $messages as $msg ) { foreach ( $messages as $msg ) {
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . $msg . '</p></div>'; wp_admin_notice( $msg, $notice_args );
} }
} }
?> ?>

View File

@ -104,8 +104,14 @@ network_edit_site_nav(
); );
if ( ! empty( $messages ) ) { if ( ! empty( $messages ) ) {
$notice_args = array(
'type' => 'success',
'dismissible' => true,
'id' => 'message',
);
foreach ( $messages as $msg ) { foreach ( $messages as $msg ) {
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . $msg . '</p></div>'; wp_admin_notice( $msg, $notice_args );
} }
} }
?> ?>

View File

@ -196,7 +196,15 @@ if ( isset( $_GET['enabled'] ) ) {
/* translators: %s: Number of themes. */ /* translators: %s: Number of themes. */
$message = _n( '%s theme enabled.', '%s themes enabled.', $enabled ); $message = _n( '%s theme enabled.', '%s themes enabled.', $enabled );
} }
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
wp_admin_notice(
sprintf( $message, number_format_i18n( $enabled ) ),
array(
'type' => 'success',
'dismissible' => true,
'id' => 'message',
)
);
} elseif ( isset( $_GET['disabled'] ) ) { } elseif ( isset( $_GET['disabled'] ) ) {
$disabled = absint( $_GET['disabled'] ); $disabled = absint( $_GET['disabled'] );
if ( 1 === $disabled ) { if ( 1 === $disabled ) {
@ -205,9 +213,24 @@ if ( isset( $_GET['enabled'] ) ) {
/* translators: %s: Number of themes. */ /* translators: %s: Number of themes. */
$message = _n( '%s theme disabled.', '%s themes disabled.', $disabled ); $message = _n( '%s theme disabled.', '%s themes disabled.', $disabled );
} }
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
wp_admin_notice(
sprintf( $message, number_format_i18n( $disabled ) ),
array(
'type' => 'success',
'dismissible' => true,
'id' => 'message',
)
);
} elseif ( isset( $_GET['error'] ) && 'none' === $_GET['error'] ) { } elseif ( isset( $_GET['error'] ) && 'none' === $_GET['error'] ) {
echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>'; wp_admin_notice(
__( 'No theme selected.' ),
array(
'type' => 'error',
'dismissible' => true,
'id' => 'message',
)
);
} }
?> ?>

View File

@ -234,41 +234,57 @@ network_edit_site_nav(
); );
if ( isset( $_GET['update'] ) ) : if ( isset( $_GET['update'] ) ) :
$message = '';
$type = 'error';
switch ( $_GET['update'] ) { switch ( $_GET['update'] ) {
case 'adduser': case 'adduser':
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . __( 'User added.' ) . '</p></div>'; $type = 'success';
$message = __( 'User added.' );
break; break;
case 'err_add_member': case 'err_add_member':
echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'User is already a member of this site.' ) . '</p></div>'; $message = __( 'User is already a member of this site.' );
break; break;
case 'err_add_fail': case 'err_add_fail':
echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'User could not be added to this site.' ) . '</p></div>'; $message = __( 'User could not be added to this site.' );
break; break;
case 'err_add_notfound': case 'err_add_notfound':
echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'Enter the username of an existing user.' ) . '</p></div>'; $message = __( 'Enter the username of an existing user.' );
break; break;
case 'promote': case 'promote':
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . __( 'Changed roles.' ) . '</p></div>'; $type = 'success';
$message = __( 'Changed roles.' );
break; break;
case 'err_promote': case 'err_promote':
echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'Select a user to change role.' ) . '</p></div>'; $message = __( 'Select a user to change role.' );
break; break;
case 'remove': case 'remove':
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . __( 'User removed from this site.' ) . '</p></div>'; $type = 'success';
$message = __( 'User removed from this site.' );
break; break;
case 'err_remove': case 'err_remove':
echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'Select a user to remove.' ) . '</p></div>'; $message = __( 'Select a user to remove.' );
break; break;
case 'newuser': case 'newuser':
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . __( 'User created.' ) . '</p></div>'; $type = 'success';
$message = __( 'User created.' );
break; break;
case 'err_new': case 'err_new':
echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'Enter the username and email.' ) . '</p></div>'; $message = __( 'Enter the username and email.' );
break; break;
case 'err_new_dup': case 'err_new_dup':
echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'Duplicated username or email address.' ) . '</p></div>'; $message = __( 'Duplicated username or email address.' );
break; break;
} }
wp_admin_notice(
$message,
array(
'type' => $type,
'dismissible' => true,
'id' => 'message',
)
);
endif; endif;
?> ?>

View File

@ -358,7 +358,14 @@ if ( isset( $_GET['updated'] ) ) {
} }
if ( ! empty( $msg ) ) { if ( ! empty( $msg ) ) {
$msg = '<div id="message" class="notice notice-success is-dismissible"><p>' . $msg . '</p></div>'; $msg = wp_get_admin_notice(
$msg,
array(
'type' => 'success',
'dismissible' => true,
'id' => 'message',
)
);
} }
} }

View File

@ -367,57 +367,82 @@ if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
<hr class="wp-header-end"> <hr class="wp-header-end">
<?php <?php
$message = '';
$type = 'success';
if ( isset( $_GET['enabled'] ) ) { if ( isset( $_GET['enabled'] ) ) {
$enabled = absint( $_GET['enabled'] ); $enabled = absint( $_GET['enabled'] );
if ( 1 === $enabled ) { if ( 1 === $enabled ) {
$message = __( 'Theme enabled.' ); $message = __( 'Theme enabled.' );
} else { } else {
/* translators: %s: Number of themes. */ $message = sprintf(
$message = _n( '%s theme enabled.', '%s themes enabled.', $enabled ); /* translators: %s: Number of themes. */
_n( '%s theme enabled.', '%s themes enabled.', $enabled ),
number_format_i18n( $enabled )
);
} }
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
} elseif ( isset( $_GET['disabled'] ) ) { } elseif ( isset( $_GET['disabled'] ) ) {
$disabled = absint( $_GET['disabled'] ); $disabled = absint( $_GET['disabled'] );
if ( 1 === $disabled ) { if ( 1 === $disabled ) {
$message = __( 'Theme disabled.' ); $message = __( 'Theme disabled.' );
} else { } else {
/* translators: %s: Number of themes. */ $message = sprintf(
$message = _n( '%s theme disabled.', '%s themes disabled.', $disabled ); /* translators: %s: Number of themes. */
_n( '%s theme disabled.', '%s themes disabled.', $disabled ),
number_format_i18n( $disabled )
);
} }
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
} elseif ( isset( $_GET['deleted'] ) ) { } elseif ( isset( $_GET['deleted'] ) ) {
$deleted = absint( $_GET['deleted'] ); $deleted = absint( $_GET['deleted'] );
if ( 1 === $deleted ) { if ( 1 === $deleted ) {
$message = __( 'Theme deleted.' ); $message = __( 'Theme deleted.' );
} else { } else {
/* translators: %s: Number of themes. */ $message = sprintf(
$message = _n( '%s theme deleted.', '%s themes deleted.', $deleted ); /* translators: %s: Number of themes. */
_n( '%s theme deleted.', '%s themes deleted.', $deleted ),
number_format_i18n( $deleted )
);
} }
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . sprintf( $message, number_format_i18n( $deleted ) ) . '</p></div>';
} elseif ( isset( $_GET['enabled-auto-update'] ) ) { } elseif ( isset( $_GET['enabled-auto-update'] ) ) {
$enabled = absint( $_GET['enabled-auto-update'] ); $enabled = absint( $_GET['enabled-auto-update'] );
if ( 1 === $enabled ) { if ( 1 === $enabled ) {
$message = __( 'Theme will be auto-updated.' ); $message = __( 'Theme will be auto-updated.' );
} else { } else {
/* translators: %s: Number of themes. */ $message = sprintf(
$message = _n( '%s theme will be auto-updated.', '%s themes will be auto-updated.', $enabled ); /* translators: %s: Number of themes. */
_n( '%s theme will be auto-updated.', '%s themes will be auto-updated.', $enabled ),
number_format_i18n( $enabled )
);
} }
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
} elseif ( isset( $_GET['disabled-auto-update'] ) ) { } elseif ( isset( $_GET['disabled-auto-update'] ) ) {
$disabled = absint( $_GET['disabled-auto-update'] ); $disabled = absint( $_GET['disabled-auto-update'] );
if ( 1 === $disabled ) { if ( 1 === $disabled ) {
$message = __( 'Theme will no longer be auto-updated.' ); $message = __( 'Theme will no longer be auto-updated.' );
} else { } else {
/* translators: %s: Number of themes. */ $message = sprintf(
$message = _n( '%s theme will no longer be auto-updated.', '%s themes will no longer be auto-updated.', $disabled ); /* translators: %s: Number of themes. */
_n( '%s theme will no longer be auto-updated.', '%s themes will no longer be auto-updated.', $disabled ),
number_format_i18n( $disabled )
);
} }
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
} elseif ( isset( $_GET['error'] ) && 'none' === $_GET['error'] ) { } elseif ( isset( $_GET['error'] ) && 'none' === $_GET['error'] ) {
echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>'; $message = __( 'No theme selected.' );
$type = 'error';
} elseif ( isset( $_GET['error'] ) && 'main' === $_GET['error'] ) { } elseif ( isset( $_GET['error'] ) && 'main' === $_GET['error'] ) {
echo '<div id="message" class="notice notice-error is-dismissible"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>'; $message = __( 'You cannot delete a theme while it is active on the main site.' );
$type = 'error';
} }
if ( '' !== $message ) {
wp_admin_notice(
$message,
array(
'type' => $type,
'dismissible' => true,
'id' => 'message',
)
);
}
?> ?>
<form method="get"> <form method="get">

View File

@ -107,19 +107,33 @@ require_once ABSPATH . 'wp-admin/admin-header.php';
<h1 id="add-new-user"><?php _e( 'Add New User' ); ?></h1> <h1 id="add-new-user"><?php _e( 'Add New User' ); ?></h1>
<?php <?php
if ( '' !== $message ) { if ( '' !== $message ) {
echo '<div id="message" class="notice notice-success is-dismissible"><p>' . $message . '</p></div>'; wp_admin_notice(
$message,
array(
'type' => 'success',
'dismissible' => true,
'id' => 'message',
)
);
} }
if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) { if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) {
?> $error_messages = '';
<div id="message" class="notice notice-error is-dismissible"> foreach ( $add_user_errors->get_error_messages() as $error ) {
<?php $error_messages .= "<p>$error</p>";
foreach ( $add_user_errors->get_error_messages() as $error ) { }
echo "<p>$error</p>";
} wp_admin_notice(
?> $error_messages,
</div> array(
<?php } ?> 'type' => 'error',
'dismissible' => true,
'id' => 'message',
'paragraph_wrap' => false,
)
);
}
?>
<form action="<?php echo esc_url( network_admin_url( 'user-new.php?action=add-user' ) ); ?>" id="adduser" method="post" novalidate="novalidate"> <form action="<?php echo esc_url( network_admin_url( 'user-new.php?action=add-user' ) ); ?>" id="adduser" method="post" novalidate="novalidate">
<p><?php echo wp_required_field_message(); ?></p> <p><?php echo wp_required_field_message(); ?></p>
<table class="form-table" role="presentation"> <table class="form-table" role="presentation">

View File

@ -254,29 +254,33 @@ get_current_screen()->set_screen_reader_content(
require_once ABSPATH . 'wp-admin/admin-header.php'; require_once ABSPATH . 'wp-admin/admin-header.php';
if ( isset( $_REQUEST['updated'] ) && 'true' === $_REQUEST['updated'] && ! empty( $_REQUEST['action'] ) ) { if ( isset( $_REQUEST['updated'] ) && 'true' === $_REQUEST['updated'] && ! empty( $_REQUEST['action'] ) ) {
?> $message = '';
<div id="message" class="notice notice-success is-dismissible"><p> switch ( $_REQUEST['action'] ) {
<?php case 'delete':
switch ( $_REQUEST['action'] ) { $message = __( 'User deleted.' );
case 'delete': break;
_e( 'User deleted.' ); case 'all_spam':
break; $message = __( 'Users marked as spam.' );
case 'all_spam': break;
_e( 'Users marked as spam.' ); case 'all_notspam':
break; $message = __( 'Users removed from spam.' );
case 'all_notspam': break;
_e( 'Users removed from spam.' ); case 'all_delete':
break; $message = __( 'Users deleted.' );
case 'all_delete': break;
_e( 'Users deleted.' ); case 'add':
break; $message = __( 'User added.' );
case 'add': break;
_e( 'User added.' ); }
break;
} wp_admin_notice(
?> $message,
</p></div> array(
<?php 'type' => 'success',
'dismissible' => true,
'id' => 'message',
)
);
} }
?> ?>
<div class="wrap"> <div class="wrap">

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.4-alpha-56408'; $wp_version = '6.4-alpha-56409';
/** /**
* 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.