Skip to content

Commit

Permalink
Administration: Use wp_admin_notice() more in /wp-admin/includes/.
Browse files Browse the repository at this point in the history
Adds further usages of `wp_admin_notice()` in `/wp-admin/includes/` on `.notice-error`, `.notice-warning`, `.error`, and `.updated`.

Ongoing task to implement new function across core.

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

Props joedolson, mukesh27, costdev.
See #57791.

git-svn-id: https://develop.svn.wordpress.org/trunk@56599 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
costdev committed Sep 17, 2023
1 parent fe097d1 commit ce32693
Show file tree
Hide file tree
Showing 14 changed files with 278 additions and 147 deletions.
10 changes: 8 additions & 2 deletions src/wp-admin/includes/class-bulk-upgrader-skin.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,16 @@ public function after( $title = '' ) {
echo '</p></div>';
if ( $this->error || ! $this->result ) {
if ( $this->error ) {
echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>';
$after_error_message = sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' );
} else {
echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed'], $title ) . '</p></div>';
$after_error_message = sprintf( $this->upgrader->strings['skin_update_failed'], $title );
}
wp_admin_notice(
$after_error_message,
array(
'additional_classes' => array( 'error' ),
)
);

echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js( $this->upgrader->update_current ) . '\').show();</script>';
}
Expand Down
24 changes: 14 additions & 10 deletions src/wp-admin/includes/class-custom-background.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,20 @@ public function admin_page() {
}

if ( ! empty( $this->updated ) ) {
?>
<div id="message" class="updated">
<p>
<?php
/* translators: %s: Home URL. */
printf( __( 'Background updated. <a href="%s">Visit your site</a> to see how it looks.' ), esc_url( home_url( '/' ) ) );
?>
</p>
</div>
<?php } ?>
$updated_message = sprintf(
/* translators: %s: Home URL. */
__( 'Background updated. <a href="%s">Visit your site</a> to see how it looks.' ),
esc_url( home_url( '/' ) )
);
wp_admin_notice(
$updated_message,
array(
'id' => 'message',
'additional_classes' => array( 'updated' ),
)
);
}
?>

<h2><?php _e( 'Background Image' ); ?></h2>

Expand Down
26 changes: 15 additions & 11 deletions src/wp-admin/includes/class-custom-image-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,18 +524,22 @@ public function step_1() {
)
);
}
?>

<?php if ( ! empty( $this->updated ) ) { ?>
<div id="message" class="updated">
<p>
<?php
/* translators: %s: Home URL. */
printf( __( 'Header updated. <a href="%s">Visit your site</a> to see how it looks.' ), esc_url( home_url( '/' ) ) );
?>
</p>
</div>
<?php } ?>
if ( ! empty( $this->updated ) ) {
$updated_message = sprintf(
/* translators: %s: Home URL. */
__( 'Header updated. <a href="%s">Visit your site</a> to see how it looks.' ),
esc_url( home_url( '/' ) )
);
wp_admin_notice(
$updated_message,
array(
'id' => 'message',
'additional_classes' => array( 'updated' ),
)
);
}
?>

<h2><?php _e( 'Header Image' ); ?></h2>

Expand Down
15 changes: 11 additions & 4 deletions src/wp-admin/includes/class-wp-plugin-install-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,17 @@ public function prepare_items() {
/**
*/
public function no_items() {
if ( isset( $this->error ) ) { ?>
<div class="inline error"><p><?php echo $this->error->get_error_message(); ?></p>
<p class="hide-if-no-js"><button class="button try-again"><?php _e( 'Try Again' ); ?></button></p>
</div>
if ( isset( $this->error ) ) {
$error_message = '<p>' . $this->error->get_error_message() . '</p>';
$error_message .= '<p class="hide-if-no-js"><button class="button try-again">' . __( 'Try Again' ) . '</button></p>';
wp_admin_notice(
$error_message,
array(
'additional_classes' => array( 'inline', 'error' ),
'paragraph_wrap' => false,
)
);
?>
<?php } else { ?>
<div class="no-plugin-results"><?php _e( 'No plugins found. Try a different search.' ); ?></div>
<?php
Expand Down
34 changes: 21 additions & 13 deletions src/wp-admin/includes/class-wp-plugins-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1282,56 +1282,64 @@ public function single_row( $item ) {
printf(
'<tr class="plugin-update-tr">' .
'<td colspan="%s" class="plugin-update colspanchange">' .
'<div class="update-message notice inline notice-error notice-alt"><p>',
esc_attr( $this->get_column_count() )
);

$incompatible_message = '';
if ( ! $compatible_php && ! $compatible_wp ) {
_e( 'This plugin does not work with your versions of WordPress and PHP.' );
$incompatible_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_message .= 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() )
);
wp_update_php_annotation( '</p><p><em>', '</em>' );
$incompatible_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
} elseif ( current_user_can( 'update_core' ) ) {
printf(
$incompatible_message .= sprintf(
/* 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(
$incompatible_message .= 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>' );
$incompatible_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
}
} elseif ( ! $compatible_wp ) {
_e( 'This plugin does not work with your version of WordPress.' );
$incompatible_message .= __( 'This plugin does not work with your version of WordPress.' );
if ( current_user_can( 'update_core' ) ) {
printf(
$incompatible_message .= sprintf(
/* translators: %s: URL to WordPress Updates screen. */
' ' . __( '<a href="%s">Please update WordPress</a>.' ),
self_admin_url( 'update-core.php' )
);
}
} elseif ( ! $compatible_php ) {
_e( 'This plugin does not work with your version of PHP.' );
$incompatible_message .= __( 'This plugin does not work with your version of PHP.' );
if ( current_user_can( 'update_php' ) ) {
printf(
$incompatible_message .= 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>' );
$incompatible_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
}
}

echo '</p></div></td></tr>';
wp_admin_notice(
$incompatible_message,
array(
'type' => 'error',
'additional_classes' => array( 'notice-alt', 'inline', 'update-message' ),
)
);

echo '</td></tr>';
}

/**
Expand Down
27 changes: 14 additions & 13 deletions src/wp-admin/includes/class-wp-privacy-policy-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,20 @@ public static function policy_text_changed_notice() {
return;
}

?>
<div class="policy-text-updated notice notice-warning is-dismissible">
<p>
<?php
printf(
/* translators: %s: Privacy Policy Guide URL. */
__( 'The suggested privacy policy text has changed. Please <a href="%s">review the guide</a> and update your privacy policy.' ),
esc_url( admin_url( 'privacy-policy-guide.php?tab=policyguide' ) )
);
?>
</p>
</div>
<?php
$privacy_message = sprintf(
/* translators: %s: Privacy Policy Guide URL. */
__( 'The suggested privacy policy text has changed. Please <a href="%s">review the guide</a> and update your privacy policy.' ),
esc_url( admin_url( 'privacy-policy-guide.php?tab=policyguide' ) )
);

wp_admin_notice(
$privacy_message,
array(
'type' => 'warning',
'additional_classes' => array( 'policy-text-updated' ),
'dismissible' => true,
)
);
}

/**
Expand Down
50 changes: 29 additions & 21 deletions src/wp-admin/includes/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,16 @@ function wp_dashboard_quick_press( $error_msg = false ) {

<form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form hide-if-no-js">

<?php if ( $error_msg ) : ?>
<div class="error"><?php echo $error_msg; ?></div>
<?php endif; ?>
<?php
if ( $error_msg ) {
wp_admin_notice(
$error_msg,
array(
'additional_classes' => array( 'error' ),
)
);
}
?>

<div class="input-text-wrap" id="title-wrap">
<label for="title">
Expand Down Expand Up @@ -1157,8 +1164,15 @@ function wp_dashboard_rss_output( $widget_id ) {
* @return bool True on success, false on failure.
*/
function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array(), ...$args ) {
$loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&hellip;' ) . '</p><div class="hide-if-js notice notice-error inline"><p>' . __( 'This widget requires JavaScript.' ) . '</p></div>';
$doing_ajax = wp_doing_ajax();
$loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&hellip;' ) . '</p>';
$loading .= wp_get_admin_notice(
__( 'This widget requires JavaScript.' ),
array(
'type' => 'error',
'additional_classes' => array( 'inline', 'hide-if-js' ),
)
);

if ( empty( $check_urls ) ) {
$widgets = get_option( 'dashboard_widget_options' );
Expand Down Expand Up @@ -1340,25 +1354,19 @@ function wp_dashboard_events_news() {
* @since 4.8.0
*/
function wp_print_community_events_markup() {
?>

<div class="community-events-errors notice notice-error inline hide-if-js">
<p class="hide-if-js">
<?php _e( 'This widget requires JavaScript.' ); ?>
</p>
$community_events_notice = '<p class="hide-if-js">' . ( 'This widget requires JavaScript.' ) . '</p>';
$community_events_notice .= '<p class="community-events-error-occurred" aria-hidden="true">' . __( 'An error occurred. Please try again.' ) . '</p>';
$community_events_notice .= '<p class="community-events-could-not-locate" aria-hidden="true"></p>';

<p class="community-events-error-occurred" aria-hidden="true">
<?php _e( 'An error occurred. Please try again.' ); ?>
</p>

<p class="community-events-could-not-locate" aria-hidden="true"></p>
</div>

<div class="community-events-loading hide-if-no-js">
<?php _e( 'Loading&hellip;' ); ?>
</div>
wp_admin_notice(
$community_events_notice,
array(
'type' => 'error',
'additional_classes' => array( 'community-events-errors', 'inline', 'hide-if-js' ),
'paragraph_wrap' => false,
)
);

<?php
/*
* Hide the main element when the page first loads, because the content
* won't be ready until wp.communityEvents.renderEventsTemplate() has run.
Expand Down
8 changes: 7 additions & 1 deletion src/wp-admin/includes/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -2426,7 +2426,13 @@ function request_filesystem_credentials( $form_post, $type = '', $error = false,
if ( is_wp_error( $error ) ) {
$error_string = esc_html( $error->get_error_message() );
}
echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
wp_admin_notice(
$error_string,
array(
'id' => 'message',
'additional_classes' => array( 'error' ),
)
);
}

$types = array();
Expand Down
13 changes: 11 additions & 2 deletions src/wp-admin/includes/ms.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,20 @@ function site_admin_notice() {
}

if ( (int) get_site_option( 'wpmu_upgrade_site' ) !== $wp_db_version ) {
echo "<div class='update-nag notice notice-warning inline'>" . sprintf(
$upgrade_network_message = sprintf(
/* translators: %s: URL to Upgrade Network screen. */
__( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ),
esc_url( network_admin_url( 'upgrade.php' ) )
) . '</div>';
);

wp_admin_notice(
$upgrade_network_message,
array(
'type' => 'warning',
'additional_classes' => array( 'update-nag', 'inline' ),
'paragraph_wrap' => false,
)
);
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/wp-admin/includes/nav-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,13 @@ function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selecte
);

if ( is_wp_error( $menu_item_db_id ) ) {
$messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>';
$messages[] = wp_get_admin_notice(
$menu_item_db_id->get_error_message(),
array(
'id' => 'message',
'additional_classes' => array( 'error' ),
)
);
} else {
unset( $menu_items[ $menu_item_db_id ] );
}
Expand Down
Loading

0 comments on commit ce32693

Please sign in to comment.