Administration: Use `wp_admin_notice()` more in `wp-admin/`.

Add additional usage of `wp_admin_notice()` in `wp-admin/` on `.error` and miscellaneous usages previously overlooked. 

Follow up to [56408], [56409], [56410], [56518], [56570], [56571], [56572], [56573], [56576], [56589], [56590], [56597], [56599].

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


git-svn-id: http://core.svn.wordpress.org/trunk@56112 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2023-09-17 15:33:17 +00:00
parent 6cdd74585d
commit 3356f6e33f
16 changed files with 304 additions and 161 deletions

View File

@ -113,8 +113,8 @@ if ( isset( $_REQUEST['post_id'] ) ) {
$id = media_handle_upload( 'async-upload', $post_id );
if ( is_wp_error( $id ) ) {
printf(
'<div class="error-div error">%s <strong>%s</strong><br />%s</div>',
$message = sprintf(
'%s <strong>%s</strong><br />%s',
sprintf(
'<button type="button" class="dismiss button-link" onclick="jQuery(this).parents(\'div.media-item\').slideUp(200, function(){jQuery(this).remove();});">%s</button>',
__( 'Dismiss' )
@ -126,6 +126,13 @@ if ( is_wp_error( $id ) ) {
),
esc_html( $id->get_error_message() )
);
wp_admin_notice(
$message,
array(
'additional_classes' => array( 'error-div', 'error' ),
'paragraph_wrap' => false,
)
);
exit;
}

View File

@ -301,7 +301,13 @@ if ( isset( $_REQUEST['error'] ) ) {
break;
}
if ( $error_msg ) {
echo '<div id="moderated" class="error"><p>' . $error_msg . '</p></div>';
wp_admin_notice(
$error_msg,
array(
'id' => 'moderated',
'additional_classes' => array( 'error' ),
)
);
}
}

View File

@ -462,12 +462,21 @@ if ( $message ) :
)
);
endif;
$connection_lost_message = sprintf(
'<span class="spinner"></span> %1$s <span class="hide-if-no-sessionstorage">%2$s</span>',
__( '<strong>Connection lost.</strong> Saving has been disabled until you are reconnected.' ),
__( 'This post is being backed up in your browser, just in case.' )
);
wp_admin_notice(
$connection_lost_message,
array(
'id' => 'lost-connection-notice',
'additional_classes' => array( 'error', 'hidden' ),
)
);
?>
<div id="lost-connection-notice" class="error hidden">
<p><span class="spinner"></span> <?php _e( '<strong>Connection lost.</strong> Saving has been disabled until you are reconnected.' ); ?>
<span class="hide-if-no-sessionstorage"><?php _e( 'This post is being backed up in your browser, just in case.' ); ?></span>
</p>
</div>
<form name="post" action="post.php" method="post" id="post"
<?php
/**

View File

@ -348,9 +348,16 @@ if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
<hr class="wp-header-end">
<?php if ( $message ) : ?>
<div id="message" class="<?php echo $class; ?> notice is-dismissible"><p><?php echo $message; ?></p></div>
<?php
<?php
if ( $message ) :
wp_admin_notice(
$message,
array(
'id' => 'message',
'additional_classes' => array( $class ),
'dismissible' => true,
)
);
$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message', 'error' ), $_SERVER['REQUEST_URI'] );
endif;
?>

View File

@ -60,16 +60,21 @@ $parent_file = 'tools.php';
<div class="wrap">
<h1><?php echo esc_html( $title ); ?></h1>
<?php if ( ! empty( $_GET['invalid'] ) ) : ?>
<div class="error">
<p><strong><?php _e( 'Error:' ); ?></strong>
<?php
/* translators: %s: Importer slug. */
printf( __( 'The %s importer is invalid or is not installed.' ), '<strong>' . esc_html( $_GET['invalid'] ) . '</strong>' );
?>
</p>
</div>
<?php endif; ?>
<?php
if ( ! empty( $_GET['invalid'] ) ) :
$importer_not_installed = '<strong>' . __( 'Error:' ) . '</strong> ' . sprintf(
/* translators: %s: Importer slug. */
__( 'The %s importer is invalid or is not installed.' ),
'<strong>' . esc_html( $_GET['invalid'] ) . '</strong>'
);
wp_admin_notice(
$importer_not_installed,
array(
'additional_classes' => array( 'error' ),
)
);
endif;
?>
<p><?php _e( 'If you have posts or comments in another system, WordPress can import those into this site. To get started, choose a system to import from below:' ); ?></p>
<?php

View File

@ -384,7 +384,14 @@ switch ( $action ) {
$_nav_menu_selected_id = wp_update_nav_menu_object( 0, array( 'menu-name' => $new_menu_title ) );
if ( is_wp_error( $_nav_menu_selected_id ) ) {
$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
$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_id = $_nav_menu_selected_id;
@ -435,7 +442,14 @@ switch ( $action ) {
exit;
}
} else {
$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
$messages[] = wp_get_admin_notice(
__( 'Please enter a valid menu name.' ),
array(
'id' => 'message',
'additional_classes' => array( 'error' ),
'dismissible' => true,
)
);
}
// Update existing menu.
@ -457,7 +471,14 @@ switch ( $action ) {
$menu_title = trim( esc_html( $_POST['menu-name'] ) );
if ( ! $menu_title ) {
$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
$messages[] = wp_get_admin_notice(
__( 'Please enter a valid menu name.' ),
array(
'id' => 'message',
'additional_classes' => array( 'error' ),
'dismissible' => true,
)
);
$menu_title = $_menu_object->name;
}
@ -510,7 +531,14 @@ switch ( $action ) {
// Set menu locations.
set_theme_mod( 'nav_menu_locations', $menu_locations );
$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Menu locations updated.' ) . '</p></div>';
$messages[] = wp_get_admin_notice(
__( 'Menu locations updated.' ),
array(
'id' => 'message',
'additional_classes' => array( 'updated' ),
'dismissible' => true,
)
);
}
break;

View File

@ -29,7 +29,15 @@ if ( empty( $plugins ) ) {
?>
<div class="wrap">
<h1><?php echo esc_html( $title ); ?></h1>
<div id="message" class="error"><p><?php _e( 'No plugins are currently available.' ); ?></p></div>
<?php
wp_admin_notice(
__( 'No plugins are currently available.' ),
array(
'id' => 'message',
'additional_classes' => array( 'error' ),
)
);
?>
</div>
<?php
require_once ABSPATH . 'wp-admin/admin-footer.php';

View File

@ -339,15 +339,31 @@ if ( $action ) {
?>
<?php if ( 1 === $plugins_to_delete ) : ?>
<h1><?php _e( 'Delete Plugin' ); ?></h1>
<?php if ( $have_non_network_plugins && is_network_admin() ) : ?>
<div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'This plugin may be active on other sites in the network.' ); ?></p></div>
<?php endif; ?>
<?php
if ( $have_non_network_plugins && is_network_admin() ) :
$maybe_active_plugin = '<strong>' . __( 'Caution:' ) . '</strong> ' . __( 'This plugin may be active on other sites in the network.' );
wp_admin_notice(
$maybe_active_plugin,
array(
'additional_classes' => array( 'error' ),
)
);
endif;
?>
<p><?php _e( 'You are about to remove the following plugin:' ); ?></p>
<?php else : ?>
<h1><?php _e( 'Delete Plugins' ); ?></h1>
<?php if ( $have_non_network_plugins && is_network_admin() ) : ?>
<div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'These plugins may be active on other sites in the network.' ); ?></p></div>
<?php endif; ?>
<?php
if ( $have_non_network_plugins && is_network_admin() ) :
$maybe_active_plugins = '<strong>' . __( 'Caution:' ) . '</strong> ' . __( 'These plugins may be active on other sites in the network.' );
wp_admin_notice(
$maybe_active_plugins,
array(
'additional_classes' => array( 'error' ),
)
);
endif;
?>
<p><?php _e( 'You are about to remove the following plugins:' ); ?></p>
<?php endif; ?>
<ul class="ul-disc">
@ -607,14 +623,19 @@ require_once ABSPATH . 'wp-admin/admin-header.php';
$invalid = validate_active_plugins();
if ( ! empty( $invalid ) ) {
foreach ( $invalid as $plugin_file => $error ) {
echo '<div id="message" class="error"><p>';
printf(
$deactivated_message = sprintf(
/* translators: 1: Plugin file, 2: Error message. */
__( 'The plugin %1$s has been deactivated due to an error: %2$s' ),
'<code>' . esc_html( $plugin_file ) . '</code>',
esc_html( $error->get_error_message() )
);
echo '</p></div>';
wp_admin_notice(
$deactivated_message,
array(
'id' => 'message',
'additional_classes' => array( 'error' ),
)
);
}
}

View File

@ -262,7 +262,12 @@ if ( preg_match( '/\.css$/', $file ) && ! wp_is_block_theme() && current_user_ca
<?php
if ( $theme->errors() ) {
echo '<div class="error"><p><strong>' . __( 'This theme is broken.' ) . '</strong> ' . $theme->errors()->get_error_message() . '</p></div>';
wp_admin_notice(
'<strong>' . __( 'This theme is broken.' ) . '</strong> ' . $theme->errors()->get_error_message(),
array(
'additional_classes' => array( 'error' ),
)
);
}
?>
@ -294,7 +299,12 @@ if ( $theme->errors() ) {
<?php
if ( $error ) :
echo '<div class="error"><p>' . __( 'File does not exist! Please double check the name and try again.' ) . '</p></div>';
wp_admin_notice(
__( 'File does not exist! Please double check the name and try again.' ),
array(
'additional_classes' => array( 'error' ),
)
);
else :
?>
<form name="template" id="template" action="theme-editor.php" method="post">

View File

@ -183,9 +183,14 @@ require_once ABSPATH . 'wp-admin/admin-header.php';
<hr class="wp-header-end">
<div class="error hide-if-js">
<p><?php _e( 'The Theme Installer screen requires JavaScript.' ); ?></p>
</div>
<?php
wp_admin_notice(
__( 'The Theme Installer screen requires JavaScript.' ),
array(
'additional_classes' => array( 'error', 'hide-if-js' ),
)
);
?>
<div class="upload-theme">
<?php install_themes_upload(); ?>

View File

@ -345,7 +345,12 @@ if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) {
$current_theme = wp_get_theme();
if ( $current_theme->errors() && ( ! is_multisite() || current_user_can( 'manage_network_themes' ) ) ) {
echo '<div class="error"><p>' . __( 'Error:' ) . ' ' . $current_theme->errors()->get_error_message() . '</p></div>';
wp_admin_notice(
__( 'Error:' ) . ' ' . $current_theme->errors()->get_error_message(),
array(
'additional_classes' => array( 'error' ),
)
);
}
$current_theme_actions = array();
@ -438,79 +443,88 @@ foreach ( $themes as $theme ) :
<?php } ?>
<?php if ( $theme['hasUpdate'] ) : ?>
<?php if ( $theme['updateResponse']['compatibleWP'] && $theme['updateResponse']['compatiblePHP'] ) : ?>
<div class="update-message notice inline notice-warning notice-alt"><p>
<?php if ( $theme['hasPackage'] ) : ?>
<?php _e( 'New version available. <button class="button-link" type="button">Update now</button>' ); ?>
<?php else : ?>
<?php _e( 'New version available.' ); ?>
<?php endif; ?>
</p></div>
<?php else : ?>
<div class="update-message notice inline notice-error notice-alt"><p>
<?php
if ( ! $theme['updateResponse']['compatibleWP'] && ! $theme['updateResponse']['compatiblePHP'] ) {
printf(
/* translators: %s: Theme name. */
__( 'There is a new version of %s available, but it does not work with your versions of WordPress and PHP.' ),
$theme['name']
<?php
if ( $theme['updateResponse']['compatibleWP'] && $theme['updateResponse']['compatiblePHP'] ) :
if ( $theme['hasPackage'] ) {
$new_version_available = __( 'New version available. <button class="button-link" type="button">Update now</button>' );
} else {
$new_version_available = __( 'New version available.' );
}
wp_admin_notice(
$new_version_available,
array(
'type' => 'warning',
'additional_classes' => array( 'notice-alt', 'inline', 'update-message' ),
)
);
else :
$theme_update_error = '';
if ( ! $theme['updateResponse']['compatibleWP'] && ! $theme['updateResponse']['compatiblePHP'] ) {
$theme_update_error .= sprintf(
/* translators: %s: Theme name. */
__( 'There is a new version of %s available, but it does not work with your versions of WordPress and PHP.' ),
$theme['name']
);
if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
$theme_update_error .= sprintf(
/* 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>.' ),
self_admin_url( 'update-core.php' ),
esc_url( wp_get_update_php_url() )
);
if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
printf(
/* 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>.' ),
self_admin_url( 'update-core.php' ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation( '</p><p><em>', '</em>' );
} elseif ( current_user_can( 'update_core' ) ) {
printf(
/* translators: %s: URL to WordPress Updates screen. */
' ' . __( '<a href="%s">Please update WordPress</a>.' ),
self_admin_url( 'update-core.php' )
);
} elseif ( current_user_can( 'update_php' ) ) {
printf(
/* translators: %s: URL to Update PHP page. */
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation( '</p><p><em>', '</em>' );
}
} elseif ( ! $theme['updateResponse']['compatibleWP'] ) {
printf(
/* translators: %s: Theme name. */
__( 'There is a new version of %s available, but it does not work with your version of WordPress.' ),
$theme['name']
wp_update_php_annotation( '</p><p><em>', '</em>', false );
} elseif ( current_user_can( 'update_core' ) ) {
$theme_update_error .= sprintf(
/* translators: %s: URL to WordPress Updates screen. */
' ' . __( '<a href="%s">Please update WordPress</a>.' ),
self_admin_url( 'update-core.php' )
);
if ( current_user_can( 'update_core' ) ) {
printf(
/* translators: %s: URL to WordPress Updates screen. */
' ' . __( '<a href="%s">Please update WordPress</a>.' ),
self_admin_url( 'update-core.php' )
);
}
} elseif ( ! $theme['updateResponse']['compatiblePHP'] ) {
printf(
/* translators: %s: Theme name. */
__( 'There is a new version of %s available, but it does not work with your version of PHP.' ),
$theme['name']
} elseif ( current_user_can( 'update_php' ) ) {
$theme_update_error .= sprintf(
/* translators: %s: URL to Update PHP page. */
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() )
);
if ( current_user_can( 'update_php' ) ) {
printf(
/* translators: %s: URL to Update PHP page. */
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation( '</p><p><em>', '</em>' );
}
wp_update_php_annotation( '</p><p><em>', '</em>', false );
}
?>
</p></div>
<?php endif; ?>
<?php endif; ?>
} elseif ( ! $theme['updateResponse']['compatibleWP'] ) {
$theme_update_error .= sprintf(
/* translators: %s: Theme name. */
__( 'There is a new version of %s available, but it does not work with your version of WordPress.' ),
$theme['name']
);
if ( current_user_can( 'update_core' ) ) {
$theme_update_error .= sprintf(
/* translators: %s: URL to WordPress Updates screen. */
' ' . __( '<a href="%s">Please update WordPress</a>.' ),
self_admin_url( 'update-core.php' )
);
}
} elseif ( ! $theme['updateResponse']['compatiblePHP'] ) {
$theme_update_error .= sprintf(
/* translators: %s: Theme name. */
__( 'There is a new version of %s available, but it does not work with your version of PHP.' ),
$theme['name']
);
if ( current_user_can( 'update_php' ) ) {
$theme_update_error .= sprintf(
/* translators: %s: URL to Update PHP page. */
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation( '</p><p><em>', '</em>', false );
}
}
wp_admin_notice(
$theme_update_error,
array(
'type' => 'error',
'additional_classes' => array( 'notice-alt', 'inline', 'update-message' ),
)
);
endif;
endif;
<?php
if ( ! $theme['compatibleWP'] || ! $theme['compatiblePHP'] ) {
$message = '';
if ( ! $theme['compatibleWP'] && ! $theme['compatiblePHP'] ) {
@ -566,9 +580,7 @@ foreach ( $themes as $theme ) :
)
);
}
?>
<?php
/* translators: %s: Theme name. */
$details_aria_label = sprintf( _x( 'View Theme Details for %s', 'theme' ), $theme['name'] );
?>
@ -662,7 +674,9 @@ if ( ! is_multisite() && $broken_themes ) {
<td></td>
<?php } ?>
</tr>
<?php foreach ( $broken_themes as $broken_theme ) : ?>
<?php
foreach ( $broken_themes as $broken_theme ) :
?>
<tr>
<td><?php echo $broken_theme->get( 'Name' ) ? $broken_theme->display( 'Name' ) : esc_html( $broken_theme->get_stylesheet() ); ?></td>
<td><?php echo $broken_theme->errors()->get_error_message(); ?></td>
@ -723,7 +737,9 @@ if ( ! is_multisite() && $broken_themes ) {
}
?>
</tr>
<?php endforeach; ?>
<?php
endforeach;
?>
</table>
</div>

View File

@ -1072,16 +1072,22 @@ if ( 'upgrade-core' === $action ) {
if ( 'themes' === $upgrade_error ) {
$theme_updates = get_theme_updates();
if ( ! empty( $theme_updates ) ) {
echo '<div class="error"><p>';
_e( 'Please select one or more themes to update.' );
echo '</p></div>';
wp_admin_notice(
__( 'Please select one or more themes to update.' ),
array(
'additional_classes' => array( 'error' ),
)
);
}
} else {
$plugin_updates = get_plugin_updates();
if ( ! empty( $plugin_updates ) ) {
echo '<div class="error"><p>';
_e( 'Please select one or more plugins to update.' );
echo '</p></div>';
wp_admin_notice(
__( 'Please select one or more plugins to update.' ),
array(
'additional_classes' => array( 'error' ),
)
);
}
}
}

View File

@ -244,11 +244,12 @@ switch ( $action ) {
endif;
if ( isset( $errors ) && is_wp_error( $errors ) ) {
?>
<div class="error">
<p><?php echo implode( "</p>\n<p>", $errors->get_error_messages() ); ?></p>
</div>
<?php
wp_admin_notice(
implode( "</p>\n<p>", $errors->get_error_messages() ),
array(
'additional_classes' => array( 'error' ),
)
);
}
?>

View File

@ -381,17 +381,19 @@ if ( current_user_can( 'create_users' ) ) {
?>
</h1>
<?php if ( isset( $errors ) && is_wp_error( $errors ) ) : ?>
<div class="error">
<ul>
<?php
foreach ( $errors->get_error_messages() as $err ) {
echo "<li>$err</li>\n";
}
?>
</ul>
</div>
<?php
<?php
if ( isset( $errors ) && is_wp_error( $errors ) ) :
$error_message = '';
foreach ( $errors->get_error_messages() as $err ) {
$error_message .= "<li>$err</li>\n";
}
wp_admin_notice(
'<ul>' . $error_message . '</ul>',
array(
'additional_classes' => array( 'error' ),
'paragraph_wrap' => false,
)
);
endif;
if ( ! empty( $messages ) ) {
@ -408,15 +410,21 @@ if ( ! empty( $messages ) ) {
}
?>
<?php if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) : ?>
<div class="error">
<?php
foreach ( $add_user_errors->get_error_messages() as $message ) {
echo "<p>$message</p>";
}
?>
</div>
<?php endif; ?>
<?php
if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) :
$error_message = '';
foreach ( $add_user_errors->get_error_messages() as $message ) {
$error_message .= "<p>$message</p>\n";
}
wp_admin_notice(
$error_message,
array(
'additional_classes' => array( 'error' ),
'paragraph_wrap' => false,
)
);
endif;
?>
<div id="ajax-response"></div>
<?php

View File

@ -339,11 +339,16 @@ switch ( $wp_list_table->current_action() ) {
<div class="wrap">
<h1><?php _e( 'Delete Users' ); ?></h1>
<?php if ( isset( $_REQUEST['error'] ) ) : ?>
<div class="error">
<p><strong><?php _e( 'Error:' ); ?></strong> <?php _e( 'Please select an option.' ); ?></p>
</div>
<?php endif; ?>
<?php
if ( isset( $_REQUEST['error'] ) ) :
wp_admin_notice(
'<strong>' . __( 'Error:' ) . '</strong> ' . __( 'Please select an option.' ),
array(
'additional_classes' => array( 'error' ),
)
);
endif;
?>
<?php if ( 1 === count( $all_user_ids ) ) : ?>
<p><?php _e( 'You have specified this user for deletion:' ); ?></p>
@ -742,17 +747,18 @@ switch ( $wp_list_table->current_action() ) {
endif;
?>
<?php if ( isset( $errors ) && is_wp_error( $errors ) ) : ?>
<div class="error">
<ul>
<?php
foreach ( $errors->get_error_messages() as $err ) {
echo "<li>$err</li>\n";
}
?>
</ul>
</div>
<?php
<?php
if ( isset( $errors ) && is_wp_error( $errors ) ) :
$error_message = '';
foreach ( $errors->get_error_messages() as $err ) {
$error_message .= "<li>$err</li>\n";
}
wp_admin_notice(
'<ul>' . $error_message . '</ul>',
array(
'additional_classes' => array( 'error' ),
)
);
endif;
if ( ! empty( $messages ) ) {

View File

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