Skip to content

Commit

Permalink
Administration: Use wp_admin_notice() more in wp-admin/.
Browse files Browse the repository at this point in the history
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.

git-svn-id: https://develop.svn.wordpress.org/trunk@56600 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
joedolson committed Sep 17, 2023
1 parent ce32693 commit f058bd1
Show file tree
Hide file tree
Showing 15 changed files with 303 additions and 160 deletions.
11 changes: 9 additions & 2 deletions src/wp-admin/async-upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@

$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' )
Expand All @@ -126,6 +126,13 @@
),
esc_html( $id->get_error_message() )
);
wp_admin_notice(
$message,
array(
'additional_classes' => array( 'error-div', 'error' ),
'paragraph_wrap' => false,
)
);
exit;
}

Expand Down
8 changes: 7 additions & 1 deletion src/wp-admin/edit-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,13 @@
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' ),
)
);
}
}

Expand Down
19 changes: 14 additions & 5 deletions src/wp-admin/edit-form-advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,21 @@
)
);
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
/**
Expand Down
13 changes: 10 additions & 3 deletions src/wp-admin/edit-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,16 @@

<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;
?>
Expand Down
25 changes: 15 additions & 10 deletions src/wp-admin/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,21 @@

<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
Expand Down
36 changes: 32 additions & 4 deletions src/wp-admin/nav-menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,14 @@
$_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;
Expand Down Expand Up @@ -435,7 +442,14 @@
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.
Expand All @@ -457,7 +471,14 @@
$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;
}

Expand Down Expand Up @@ -510,7 +531,14 @@
// 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;
Expand Down
10 changes: 9 additions & 1 deletion src/wp-admin/plugin-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@
?>
<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';
Expand Down
39 changes: 30 additions & 9 deletions src/wp-admin/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,31 @@
?>
<?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">
Expand Down Expand Up @@ -607,14 +623,19 @@
$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' ),
)
);
}
}

Expand Down
14 changes: 12 additions & 2 deletions src/wp-admin/theme-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,12 @@

<?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' ),
)
);
}
?>

Expand Down Expand Up @@ -294,7 +299,12 @@

<?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">
Expand Down
11 changes: 8 additions & 3 deletions src/wp-admin/theme-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,14 @@

<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(); ?>
Expand Down
Loading

0 comments on commit f058bd1

Please sign in to comment.