--- a/wp/wp-admin/includes/dashboard.php Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-admin/includes/dashboard.php Tue Dec 15 13:49:49 2020 +0100
@@ -42,7 +42,21 @@
wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Required' ), 'wp_dashboard_php_nag' );
}
- // Right Now
+ // Site Health.
+ if ( current_user_can( 'view_site_health_checks' ) && ! is_network_admin() ) {
+ if ( ! class_exists( 'WP_Site_Health' ) ) {
+ require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
+ }
+
+ WP_Site_Health::get_instance();
+
+ wp_enqueue_style( 'site-health' );
+ wp_enqueue_script( 'site-health' );
+
+ wp_add_dashboard_widget( 'dashboard_site_health', __( 'Site Health Status' ), 'wp_dashboard_site_health' );
+ }
+
+ // Right Now.
if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) {
wp_add_dashboard_widget( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' );
}
@@ -51,18 +65,18 @@
wp_add_dashboard_widget( 'network_dashboard_right_now', __( 'Right Now' ), 'wp_network_dashboard_right_now' );
}
- // Activity Widget
+ // Activity Widget.
if ( is_blog_admin() ) {
wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' );
}
- // QuickPress Widget
+ // QuickPress Widget.
if ( is_blog_admin() && current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
$quick_draft_title = sprintf( '<span class="hide-if-no-js">%1$s</span> <span class="hide-if-js">%2$s</span>', __( 'Quick Draft' ), __( 'Your Recent Drafts' ) );
wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' );
}
- // WordPress Events and News
+ // WordPress Events and News.
wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress Events and News' ), 'wp_dashboard_events_news' );
if ( is_network_admin() ) {
@@ -123,9 +137,9 @@
wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[ $widget_id ]['callback'], $wp_registered_widget_controls[ $widget_id ]['callback'] );
}
- if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget_id'] ) ) {
+ if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget_id'] ) ) {
check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' );
- ob_start(); // hack - but the same hack wp-admin/widgets.php uses
+ ob_start(); // Hack - but the same hack wp-admin/widgets.php uses.
wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
ob_end_clean();
wp_redirect( remove_query_arg( 'edit' ) );
@@ -181,7 +195,7 @@
$side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' );
$location = 'normal';
- if ( in_array( $widget_id, $side_widgets ) ) {
+ if ( in_array( $widget_id, $side_widgets, true ) ) {
$location = 'side';
}
@@ -249,7 +263,7 @@
}
//
-// Dashboard Widgets
+// Dashboard Widgets.
//
/**
@@ -264,13 +278,15 @@
<div class="main">
<ul>
<?php
- // Posts and Pages
+ // Posts and Pages.
foreach ( array( 'post', 'page' ) as $post_type ) {
$num_posts = wp_count_posts( $post_type );
if ( $num_posts && $num_posts->publish ) {
- if ( 'post' == $post_type ) {
+ if ( 'post' === $post_type ) {
+ /* translators: %s: Number of posts. */
$text = _n( '%s Post', '%s Posts', $num_posts->publish );
} else {
+ /* translators: %s: Number of pages. */
$text = _n( '%s Page', '%s Pages', $num_posts->publish );
}
$text = sprintf( $text, number_format_i18n( $num_posts->publish ) );
@@ -282,15 +298,16 @@
}
}
}
- // Comments
+ // Comments.
$num_comm = wp_count_comments();
if ( $num_comm && ( $num_comm->approved || $num_comm->moderated ) ) {
+ /* translators: %s: Number of comments. */
$text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->approved ), number_format_i18n( $num_comm->approved ) );
?>
<li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li>
<?php
$moderated_comments_count_i18n = number_format_i18n( $num_comm->moderated );
- /* translators: %s: number of comments in moderation */
+ /* translators: %s: Number of comments. */
$text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $num_comm->moderated ), $moderated_comments_count_i18n );
?>
<li class="comment-mod-count
@@ -329,7 +346,7 @@
if ( ! is_network_admin() && ! is_user_admin() && current_user_can( 'manage_options' ) && '0' == get_option( 'blog_public' ) ) {
/**
- * Filters the link title attribute for the 'Search Engines Discouraged'
+ * Filters the link title attribute for the 'Search engines discouraged'
* message displayed in the 'At a Glance' dashboard widget.
*
* Prior to 3.8.0, the widget was named 'Right Now'.
@@ -342,7 +359,7 @@
$title = apply_filters( 'privacy_on_link_title', '' );
/**
- * Filters the link label for the 'Search Engines Discouraged' message
+ * Filters the link label for the 'Search engines discouraged' message
* displayed in the 'At a Glance' dashboard widget.
*
* Prior to 3.8.0, the widget was named 'Right Now'.
@@ -351,10 +368,10 @@
*
* @param string $content Default text.
*/
- $content = apply_filters( 'privacy_on_link_text', __( 'Search Engines Discouraged' ) );
+ $content = apply_filters( 'privacy_on_link_text', __( 'Search engines discouraged' ) );
$title_attr = '' === $title ? '' : " title='$title'";
- echo "<p><a href='options-reading.php'$title_attr>$content</a></p>";
+ echo "<p class='search-engines-info'><a href='options-reading.php'$title_attr>$content</a></p>";
}
?>
</div>
@@ -409,12 +426,12 @@
$c_users = get_user_count();
$c_blogs = get_blog_count();
- /* translators: %s: number of users on the network */
+ /* translators: %s: Number of users on the network. */
$user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) );
- /* translators: %s: number of sites on the network */
+ /* translators: %s: Number of sites on the network. */
$blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) );
- /* translators: 1: text indicating the number of sites on the network, 2: text indicating the number of users on the network */
+ /* translators: 1: Text indicating the number of sites on the network, 2: Text indicating the number of users on the network. */
$sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text );
if ( $actions ) {
@@ -489,21 +506,21 @@
}
/* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
- $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID
+ $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID.
if ( $last_post_id ) {
$post = get_post( $last_post_id );
- if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
+ if ( empty( $post ) || 'auto-draft' !== $post->post_status ) { // auto-draft doesn't exist anymore.
$post = get_default_post_to_edit( 'post', true );
- update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
+ update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.
} else {
- $post->post_title = ''; // Remove the auto draft title
+ $post->post_title = ''; // Remove the auto draft title.
}
} else {
$post = get_default_post_to_edit( 'post', true );
$user_id = get_current_user_id();
// Don't create an option if this is a super admin who does not belong to this site.
- if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) ) {
- update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
+ if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ), true ) ) {
+ update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.
}
}
@@ -580,19 +597,33 @@
echo '<div class="drafts">';
if ( count( $drafts ) > 3 ) {
- echo '<p class="view-all"><a href="' . esc_url( admin_url( 'edit.php?post_status=draft' ) ) . '">' . __( 'View all drafts' ) . "</a></p>\n";
+ printf(
+ '<p class="view-all"><a href="%s">%s</a></p>' . "\n",
+ esc_url( admin_url( 'edit.php?post_status=draft' ) ),
+ __( 'View all drafts' )
+ );
}
echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n<ul>";
+ /* translators: Maximum number of words used in a preview of a draft on the dashboard. */
+ $draft_length = intval( _x( '10', 'draft_length' ) );
+
$drafts = array_slice( $drafts, 0, 3 );
foreach ( $drafts as $draft ) {
$url = get_edit_post_link( $draft->ID );
$title = _draft_or_post_title( $draft->ID );
echo "<li>\n";
- /* translators: %s: post title */
- echo '<div class="draft-title"><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . esc_html( $title ) . '</a>';
- echo '<time datetime="' . get_the_time( 'c', $draft ) . '">' . get_the_time( __( 'F j, Y' ), $draft ) . '</time></div>';
- if ( $the_content = wp_trim_words( $draft->post_content, 10 ) ) {
+ printf(
+ '<div class="draft-title"><a href="%s" aria-label="%s">%s</a><time datetime="%s">%s</time></div>',
+ esc_url( $url ),
+ /* translators: %s: Post title. */
+ esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ),
+ esc_html( $title ),
+ get_the_time( 'c', $draft ),
+ get_the_time( __( 'F j, Y' ), $draft )
+ );
+ $the_content = wp_trim_words( $draft->post_content, $draft_length );
+ if ( $the_content ) {
echo '<p>' . $the_content . '</p>';
}
echo "</li>\n";
@@ -606,7 +637,7 @@
* @access private
* @since 2.7.0
*
- * @global WP_Comment $comment
+ * @global WP_Comment $comment Global comment object.
*
* @param WP_Comment $comment The current comment.
* @param bool $show_date Optional. Whether to display the date.
@@ -646,19 +677,70 @@
$trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
$delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
- $actions['approve'] = "<a href='$approve_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a aria-button-if-js' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
- $actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved' class='vim-u aria-button-if-js' aria-label='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
- $actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' aria-label='" . esc_attr__( 'Edit this comment' ) . "'>" . __( 'Edit' ) . '</a>';
- $actions['reply'] = '<button type="button" onclick="window.commentReply && commentReply.open(\'' . $comment->comment_ID . '\',\'' . $comment->comment_post_ID . '\');" class="vim-r button-link hide-if-no-js" aria-label="' . esc_attr__( 'Reply to this comment' ) . '">' . __( 'Reply' ) . '</button>';
- $actions['spam'] = "<a href='$spam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::spam=1' class='vim-s vim-destructive aria-button-if-js' aria-label='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
+ $actions['approve'] = sprintf(
+ '<a href="%s" data-wp-lists="%s" class="vim-a aria-button-if-js" aria-label="%s">%s</a>',
+ $approve_url,
+ "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved",
+ esc_attr__( 'Approve this comment' ),
+ __( 'Approve' )
+ );
+
+ $actions['unapprove'] = sprintf(
+ '<a href="%s" data-wp-lists="%s" class="vim-u aria-button-if-js" aria-label="%s">%s</a>',
+ $unapprove_url,
+ "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved",
+ esc_attr__( 'Unapprove this comment' ),
+ __( 'Unapprove' )
+ );
+
+ $actions['edit'] = sprintf(
+ '<a href="%s" aria-label="%s">%s</a>',
+ "comment.php?action=editcomment&c={$comment->comment_ID}",
+ esc_attr__( 'Edit this comment' ),
+ __( 'Edit' )
+ );
+
+ $actions['reply'] = sprintf(
+ '<button type="button" onclick="window.commentReply && commentReply.open(\'%s\',\'%s\');" class="vim-r button-link hide-if-no-js" aria-label="%s">%s</button>',
+ $comment->comment_ID,
+ $comment->comment_post_ID,
+ esc_attr__( 'Reply to this comment' ),
+ __( 'Reply' )
+ );
+
+ $actions['spam'] = sprintf(
+ '<a href="%s" data-wp-lists="%s" class="vim-s vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
+ $spam_url,
+ "delete:the-comment-list:comment-{$comment->comment_ID}::spam=1",
+ esc_attr__( 'Mark this comment as spam' ),
+ /* translators: "Mark as spam" link. */
+ _x( 'Spam', 'verb' )
+ );
if ( ! EMPTY_TRASH_DAYS ) {
- $actions['delete'] = "<a href='$delete_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive aria-button-if-js' aria-label='" . esc_attr__( 'Delete this comment permanently' ) . "'>" . __( 'Delete Permanently' ) . '</a>';
+ $actions['delete'] = sprintf(
+ '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
+ $delete_url,
+ "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
+ esc_attr__( 'Delete this comment permanently' ),
+ __( 'Delete Permanently' )
+ );
} else {
- $actions['trash'] = "<a href='$trash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive aria-button-if-js' aria-label='" . esc_attr__( 'Move this comment to the Trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>';
+ $actions['trash'] = sprintf(
+ '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
+ $trash_url,
+ "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
+ esc_attr__( 'Move this comment to the Trash' ),
+ _x( 'Trash', 'verb' )
+ );
}
- $actions['view'] = '<a class="comment-link" href="' . esc_url( get_comment_link( $comment ) ) . '" aria-label="' . esc_attr__( 'View this comment' ) . '">' . __( 'View' ) . '</a>';
+ $actions['view'] = sprintf(
+ '<a class="comment-link" href="%s" aria-label="%s">%s</a>',
+ esc_url( get_comment_link( $comment ) ),
+ esc_attr__( 'View this comment' ),
+ __( 'View' )
+ );
/**
* Filters the action links displayed for each comment in the 'Recent Comments'
@@ -674,18 +756,27 @@
$actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
$i = 0;
+
foreach ( $actions as $action => $link ) {
++$i;
- ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
- // Reply and quickedit need a hide-if-no-js span
- if ( 'reply' == $action || 'quickedit' == $action ) {
+ if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i )
+ || 1 === $i
+ ) {
+ $sep = '';
+ } else {
+ $sep = ' | ';
+ }
+
+ // Reply and quickedit need a hide-if-no-js span.
+ if ( 'reply' === $action || 'quickedit' === $action ) {
$action .= ' hide-if-no-js';
}
if ( 'view' === $action && '1' !== $comment->comment_approved ) {
$action .= ' hidden';
}
+
$actions_string .= "<span class='$action'>$sep$link</span>";
}
}
@@ -693,17 +784,24 @@
<li id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status( $comment ) ), $comment ); ?>>
- <?php echo get_avatar( $comment, 50, 'mystery' ); ?>
+ <?php
+ $comment_row_class = '';
- <?php if ( ! $comment->comment_type || 'comment' == $comment->comment_type ) : ?>
+ if ( get_option( 'show_avatars' ) ) {
+ echo get_avatar( $comment, 50, 'mystery' );
+ $comment_row_class .= ' has-avatar';
+ }
+ ?>
- <div class="dashboard-comment-wrap has-row-actions">
+ <?php if ( ! $comment->comment_type || 'comment' === $comment->comment_type ) : ?>
+
+ <div class="dashboard-comment-wrap has-row-actions <?php echo $comment_row_class; ?>">
<p class="comment-meta">
<?php
// Comments might not have a post they relate to, e.g. programmatically created ones.
if ( $comment_post_link ) {
printf(
- /* translators: 1: comment author, 2: post link, 3: notification if the comment is pending */
+ /* translators: 1: Comment author, 2: Post link, 3: Notification if the comment is pending. */
__( 'From %1$s on %2$s %3$s' ),
'<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
$comment_post_link,
@@ -711,7 +809,7 @@
);
} else {
printf(
- /* translators: 1: comment author, 2: notification if the comment is pending */
+ /* translators: 1: Comment author, 2: Notification if the comment is pending. */
__( 'From %1$s %2$s' ),
'<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
'<span class="approve">' . __( '[Pending]' ) . '</span>'
@@ -740,7 +838,7 @@
// Pingbacks, Trackbacks or custom comment types might not have a post they relate to, e.g. programmatically created ones.
if ( $comment_post_link ) {
printf(
- /* translators: 1: type of comment, 2: post link, 3: notification if the comment is pending */
+ /* translators: 1: Type of comment, 2: Post link, 3: Notification if the comment is pending. */
_x( '%1$s on %2$s %3$s', 'dashboard' ),
"<strong>$type</strong>",
$comment_post_link,
@@ -748,7 +846,7 @@
);
} else {
printf(
- /* translators: 1: type of comment, 2: notification if the comment is pending */
+ /* translators: 1: Type of comment, 2: Notification if the comment is pending. */
_x( '%1$s %2$s', 'dashboard' ),
"<strong>$type</strong>",
'<span class="approve">' . __( '[Pending]' ) . '</span>'
@@ -801,7 +899,6 @@
if ( ! $future_posts && ! $recent_posts && ! $recent_comments ) {
echo '<div class="no-activity">';
- echo '<p class="smiley" aria-hidden="true"></p>';
echo '<p>' . __( 'No activity yet!' ) . '</p>';
echo '</div>';
}
@@ -856,22 +953,22 @@
echo '<ul>';
$today = current_time( 'Y-m-d' );
- $tomorrow = gmdate( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) );
+ $tomorrow = current_datetime()->modify( '+1 day' )->format( 'Y-m-d' );
$year = current_time( 'Y' );
while ( $posts->have_posts() ) {
$posts->the_post();
$time = get_the_time( 'U' );
- if ( date( 'Y-m-d', $time ) == $today ) {
+ if ( gmdate( 'Y-m-d', $time ) == $today ) {
$relative = __( 'Today' );
- } elseif ( date( 'Y-m-d', $time ) == $tomorrow ) {
+ } elseif ( gmdate( 'Y-m-d', $time ) == $tomorrow ) {
$relative = __( 'Tomorrow' );
- } elseif ( date( 'Y', $time ) !== $year ) {
- /* translators: date and time format for recent posts on the dashboard, from a different calendar year, see https://secure.php.net/date */
+ } elseif ( gmdate( 'Y', $time ) !== $year ) {
+ /* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/date */
$relative = date_i18n( __( 'M jS Y' ), $time );
} else {
- /* translators: date and time format for recent posts on the dashboard, see https://secure.php.net/date */
+ /* translators: Date and time format for recent posts on the dashboard, see https://www.php.net/date */
$relative = date_i18n( __( 'M jS' ), $time );
}
@@ -881,10 +978,10 @@
$draft_or_post_title = _draft_or_post_title();
printf(
'<li><span>%1$s</span> <a href="%2$s" aria-label="%3$s">%4$s</a></li>',
- /* translators: 1: relative date, 2: time */
+ /* translators: 1: Relative date, 2: Time. */
sprintf( _x( '%1$s, %2$s', 'dashboard' ), $relative, get_the_time() ),
$recent_post_link,
- /* translators: %s: post title */
+ /* translators: %s: Post title. */
esc_attr( sprintf( __( 'Edit “%s”' ), $draft_or_post_title ) ),
$draft_or_post_title
);
@@ -987,14 +1084,17 @@
* which is later replaced by Ajax call (see top of /wp-admin/index.php)
*
* @since 2.5.0
+ * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
+ * by adding it to the function signature.
*
- * @param string $widget_id
- * @param callable $callback
- * @param array $check_urls RSS feeds
- * @return bool False on failure. True on success.
+ * @param string $widget_id The widget ID.
+ * @param callable $callback The callback function used to display each feed.
+ * @param array $check_urls RSS feeds.
+ * @param mixed ...$args Optional additional parameters to pass to the callback function.
+ * @return bool True on success, false on failure.
*/
-function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
- $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><div class="hide-if-js notice notice-error inline"><p>' . __( 'This widget requires JavaScript.' ) . '</p></div>';
+function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array(), ...$args ) {
+ $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><div class="hide-if-js notice notice-error inline"><p>' . __( 'This widget requires JavaScript.' ) . '</p></div>';
$doing_ajax = wp_doing_ajax();
if ( empty( $check_urls ) ) {
@@ -1008,7 +1108,8 @@
$locale = get_user_locale();
$cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
- if ( false !== ( $output = get_transient( $cache_key ) ) ) {
+ $output = get_transient( $cache_key );
+ if ( false !== $output ) {
echo $output;
return true;
}
@@ -1019,18 +1120,18 @@
}
if ( $callback && is_callable( $callback ) ) {
- $args = array_slice( func_get_args(), 3 );
array_unshift( $args, $widget_id, $check_urls );
ob_start();
call_user_func_array( $callback, $args );
- set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS ); // Default lifetime in cache of 12 hours (same as the feeds)
+ // Default lifetime in cache of 12 hours (same as the feeds).
+ set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS );
}
return true;
}
//
-// Dashboard Widgets Controls
+// Dashboard Widgets Controls.
//
/**
@@ -1066,10 +1167,11 @@
* @since 2.5.0
*
* @param string $widget_id
- * @param array $form_inputs
+ * @param array $form_inputs
*/
function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
- if ( ! $widget_options = get_option( 'dashboard_widget_options' ) ) {
+ $widget_options = get_option( 'dashboard_widget_options' );
+ if ( ! $widget_options ) {
$widget_options = array();
}
@@ -1077,10 +1179,11 @@
$widget_options[ $widget_id ] = array();
}
- $number = 1; // Hack to use wp_widget_rss_form()
+ $number = 1; // Hack to use wp_widget_rss_form().
+
$widget_options[ $widget_id ]['number'] = $number;
- if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget-rss'][ $number ] ) ) {
+ if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget-rss'][ $number ] ) ) {
$_POST['widget-rss'][ $number ] = wp_unslash( $_POST['widget-rss'][ $number ] );
$widget_options[ $widget_id ] = wp_widget_rss_process( $_POST['widget-rss'][ $number ] );
$widget_options[ $widget_id ]['number'] = $number;
@@ -1126,7 +1229,7 @@
'<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
'https://make.wordpress.org/community/meetups-landing-page',
__( 'Meetups' ),
- /* translators: accessibility text */
+ /* translators: Accessibility text. */
__( '(opens in a new tab)' )
);
?>
@@ -1138,7 +1241,7 @@
'<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
'https://central.wordcamp.org/schedule/',
__( 'WordCamps' ),
- /* translators: accessibility text */
+ /* translators: Accessibility text. */
__( '(opens in a new tab)' )
);
?>
@@ -1151,7 +1254,7 @@
/* translators: If a Rosetta site exists (e.g. https://es.wordpress.org/news/), then use that. Otherwise, leave untranslated. */
esc_url( _x( 'https://wordpress.org/news/', 'Events and News dashboard widget' ) ),
__( 'News' ),
- /* translators: accessibility text */
+ /* translators: Accessibility text. */
__( '(opens in a new tab)' )
);
?>
@@ -1243,7 +1346,7 @@
<script id="tmpl-community-events-attend-event-near" type="text/template">
<?php
printf(
- /* translators: %s: the name of a city */
+ /* translators: %s: The name of a city. */
__( 'Attend an upcoming event near %s.' ),
'<strong>{{ data.location.description }}</strong>'
);
@@ -1290,8 +1393,8 @@
<# if ( data.location.description ) { #>
<?php
printf(
- /* translators: 1: the city the user searched for, 2: meetup organization documentation URL */
- __( 'There aren’t any events scheduled near %1$s at the moment. Would you like to <a href="%2$s">organize one</a>?' ),
+ /* translators: 1: The city the user searched for, 2: Meetup organization documentation URL. */
+ __( 'There aren’t any events scheduled near %1$s at the moment. Would you like to <a href="%2$s">organize a WordPress event</a>?' ),
'{{ data.location.description }}',
__( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' )
);
@@ -1300,8 +1403,8 @@
<# } else { #>
<?php
printf(
- /* translators: %s: meetup organization documentation URL */
- __( 'There aren’t any events scheduled near you at the moment. Would you like to <a href="%s">organize one</a>?' ),
+ /* translators: %s: Meetup organization documentation URL. */
+ __( 'There aren’t any events scheduled near you at the moment. Would you like to <a href="%s">organize a WordPress event</a>?' ),
__( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' )
);
?>
@@ -1399,7 +1502,7 @@
}
/**
- * Display the WordPress events and news feeds.
+ * Displays the WordPress events and news feeds.
*
* @since 3.8.0
* @since 4.8.0 Removed popular plugins feed.
@@ -1417,7 +1520,7 @@
}
/**
- * Display file upload quota on dashboard.
+ * Displays file upload quota on dashboard.
*
* Runs on the {@see 'activity_box_end'} hook in wp_dashboard_right_now().
*
@@ -1449,7 +1552,7 @@
<li class="storage-count">
<?php
$text = sprintf(
- /* translators: %s: number of megabytes */
+ /* translators: %s: Number of megabytes. */
__( '%s MB Space Allowed' ),
number_format_i18n( $quota )
);
@@ -1463,7 +1566,7 @@
</li><li class="storage-count <?php echo $used_class; ?>">
<?php
$text = sprintf(
- /* translators: 1: number of megabytes, 2: percentage */
+ /* translators: 1: Number of megabytes, 2: Percentage. */
__( '%1$s MB (%2$s%%) Space Used' ),
number_format_i18n( $used, 2 ),
$percentused
@@ -1481,21 +1584,25 @@
<?php
}
-// Display Browser Nag Meta Box
+/**
+ * Displays the browser update nag.
+ *
+ * @since 3.2.0
+ */
function wp_dashboard_browser_nag() {
$notice = '';
$response = wp_check_browser_version();
if ( $response ) {
if ( $response['insecure'] ) {
- /* translators: %s: browser name and link */
$msg = sprintf(
+ /* translators: %s: Browser name and link. */
__( "It looks like you're using an insecure version of %s. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser." ),
sprintf( '<a href="%s">%s</a>', esc_url( $response['update_url'] ), esc_html( $response['name'] ) )
);
} else {
- /* translators: %s: browser name and link */
$msg = sprintf(
+ /* translators: %s: Browser name and link. */
__( "It looks like you're using an old version of %s. For the best WordPress experience, please update your browser." ),
sprintf( '<a href="%s">%s</a>', esc_url( $response['update_url'] ), esc_html( $response['name'] ) )
);
@@ -1516,7 +1623,13 @@
$browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
}
- $notice .= '<p>' . sprintf( __( '<a href="%1$s" class="update-browser-link">Update %2$s</a> or learn how to <a href="%3$s" class="browse-happy-link">browse happy</a>' ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ), esc_url( $browsehappy ) ) . '</p>';
+ $notice .= '<p>' . sprintf(
+ /* translators: 1: Browser update URL, 2: Browser name, 3: Browse Happy URL. */
+ __( '<a href="%1$s" class="update-browser-link">Update %2$s</a> or learn how to <a href="%3$s" class="browse-happy-link">browse happy</a>' ),
+ esc_attr( $response['update_url'] ),
+ esc_html( $response['name'] ),
+ esc_url( $browsehappy )
+ ) . '</p>';
$notice .= '<p class="hide-if-no-js"><a href="" class="dismiss" aria-label="' . esc_attr__( 'Dismiss the browser warning panel' ) . '">' . __( 'Dismiss' ) . '</a></p>';
$notice .= '<div class="clear"></div>';
}
@@ -1529,14 +1642,16 @@
* @param string $notice The notice content.
* @param array $response An array containing web browser information. See `wp_check_browser_version()`.
*/
- echo apply_filters( 'browse-happy-notice', $notice, $response );
+ echo apply_filters( 'browse-happy-notice', $notice, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
}
/**
+ * Adds an additional class to the browser nag if the current version is insecure.
+ *
* @since 3.2.0
*
- * @param array $classes
- * @return array
+ * @param string[] $classes Array of meta box classes.
+ * @return string[] Modified array of meta box classes.
*/
function dashboard_browser_nag_class( $classes ) {
$response = wp_check_browser_version();
@@ -1549,11 +1664,11 @@
}
/**
- * Check if the user needs a browser update
+ * Checks if the user needs a browser update.
*
* @since 3.2.0
*
- * @return array|bool False on failure, array of browser data on success.
+ * @return array|bool Array of browser data on success, false on failure.
*/
function wp_check_browser_version() {
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
@@ -1562,9 +1677,10 @@
$key = md5( $_SERVER['HTTP_USER_AGENT'] );
- if ( false === ( $response = get_site_transient( 'browser_' . $key ) ) ) {
- // include an unmodified $wp_version
- include( ABSPATH . WPINC . '/version.php' );
+ $response = get_site_transient( 'browser_' . $key );
+ if ( false === $response ) {
+ // Include an unmodified $wp_version.
+ require ABSPATH . WPINC . '/version.php';
$url = 'http://api.wordpress.org/core/browse-happy/1.1/';
$options = array(
@@ -1636,7 +1752,7 @@
'<a class="button button-primary" href="%1$s" target="_blank" rel="noopener noreferrer">%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
esc_url( wp_get_update_php_url() ),
__( 'Learn more about updating PHP' ),
- /* translators: accessibility text */
+ /* translators: Accessibility text. */
__( '(opens in a new tab)' )
);
?>
@@ -1652,8 +1768,8 @@
*
* @since 5.1.0
*
- * @param array $classes Metabox classes.
- * @return array Modified metabox classes.
+ * @param string[] $classes Array of meta box classes.
+ * @return string[] Modified array of meta box classes.
*/
function dashboard_php_nag_class( $classes ) {
$response = wp_check_php_version();
@@ -1666,7 +1782,91 @@
}
/**
+ * Displays the Site Health Status widget.
+ *
+ * @since 5.4.0
+ */
+function wp_dashboard_site_health() {
+ $get_issues = get_transient( 'health-check-site-status-result' );
+
+ $issue_counts = array();
+
+ if ( false !== $get_issues ) {
+ $issue_counts = json_decode( $get_issues, true );
+ }
+
+ if ( ! is_array( $issue_counts ) || ! $issue_counts ) {
+ $issue_counts = array(
+ 'good' => 0,
+ 'recommended' => 0,
+ 'critical' => 0,
+ );
+ }
+
+ $issues_total = $issue_counts['recommended'] + $issue_counts['critical'];
+ ?>
+ <div class="health-check-title-section site-health-progress-wrapper loading hide-if-no-js">
+ <div class="site-health-progress">
+ <svg role="img" aria-hidden="true" focusable="false" width="100%" height="100%" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg">
+ <circle r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
+ <circle id="bar" r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
+ </svg>
+ </div>
+ <div class="site-health-progress-label">
+ <?php if ( false === $get_issues ) : ?>
+ <?php _e( 'No information yet…' ); ?>
+ <?php else : ?>
+ <?php _e( 'Results are still loading…' ); ?>
+ <?php endif; ?>
+ </div>
+ </div>
+
+ <?php if ( false === $get_issues ) : ?>
+ <p>
+ <?php
+ printf(
+ /* translators: %s: URL to Site Health screen. */
+ __( 'Site health checks will automatically run periodically to gather information about your site. You can also <a href="%s">visit the Site Health screen</a> to gather information about your site now.' ),
+ esc_url( admin_url( 'site-health.php' ) )
+ );
+ ?>
+ </p>
+ <?php else : ?>
+ <p>
+ <?php if ( $issue_counts['critical'] > 0 ) : ?>
+ <?php _e( 'Your site has critical issues that should be addressed as soon as possible to improve its performance and security.' ); ?>
+ <?php elseif ( $issues_total <= 0 ) : ?>
+ <?php _e( 'Great job! Your site currently passes all site health checks.' ); ?>
+ <?php else : ?>
+ <?php _e( 'Your site’s health is looking good, but there are still some things you can do to improve its performance and security.' ); ?>
+ <?php endif; ?>
+ </p>
+ <?php endif; ?>
+
+ <?php if ( $issues_total > 0 && false !== $get_issues ) : ?>
+ <p>
+ <?php
+ printf(
+ /* translators: 1: Number of issues. 2: URL to Site Health screen. */
+ _n(
+ 'Take a look at the <strong>%1$d item</strong> on the <a href="%2$s">Site Health screen</a>.',
+ 'Take a look at the <strong>%1$d items</strong> on the <a href="%2$s">Site Health screen</a>.',
+ $issues_total
+ ),
+ $issues_total,
+ esc_url( admin_url( 'site-health.php' ) )
+ );
+ ?>
+ </p>
+ <?php endif; ?>
+
+ <?php
+}
+
+/**
* Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
+ *
+ * @since 2.5.0
*/
function wp_dashboard_empty() {}
@@ -1689,16 +1889,21 @@
<a class="button button-primary button-hero hide-if-customize" href="<?php echo admin_url( 'themes.php' ); ?>"><?php _e( 'Customize Your Site' ); ?></a>
<?php if ( current_user_can( 'install_themes' ) || ( current_user_can( 'switch_themes' ) && count( wp_get_themes( array( 'allowed' => true ) ) ) > 1 ) ) : ?>
<?php $themes_link = current_user_can( 'customize' ) ? add_query_arg( 'autofocus[panel]', 'themes', admin_url( 'customize.php' ) ) : admin_url( 'themes.php' ); ?>
- <p class="hide-if-no-customize"><?php printf( __( 'or, <a href="%s">change your theme completely</a>' ), $themes_link ); ?></p>
+ <p class="hide-if-no-customize">
+ <?php
+ /* translators: %s: URL to Themes panel in Customizer or Themes screen. */
+ printf( __( 'or, <a href="%s">change your theme completely</a>' ), $themes_link );
+ ?>
+ </p>
<?php endif; ?>
</div>
<div class="welcome-panel-column">
<h3><?php _e( 'Next Steps' ); ?></h3>
<ul>
- <?php if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_for_posts' ) ) : ?>
+ <?php if ( 'page' === get_option( 'show_on_front' ) && ! get_option( 'page_for_posts' ) ) : ?>
<li><?php printf( '<a href="%s" class="welcome-icon welcome-edit-page">' . __( 'Edit your front page' ) . '</a>', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?></li>
<li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add additional pages' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
- <?php elseif ( 'page' == get_option( 'show_on_front' ) ) : ?>
+ <?php elseif ( 'page' === get_option( 'show_on_front' ) ) : ?>
<li><?php printf( '<a href="%s" class="welcome-icon welcome-edit-page">' . __( 'Edit your front page' ) . '</a>', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?></li>
<li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add additional pages' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
<li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Add a blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
@@ -1713,27 +1918,16 @@
<div class="welcome-panel-column welcome-panel-last">
<h3><?php _e( 'More Actions' ); ?></h3>
<ul>
- <?php if ( current_theme_supports( 'widgets' ) || current_theme_supports( 'menus' ) ) : ?>
- <li><div class="welcome-icon welcome-widgets-menus">
- <?php
- if ( current_theme_supports( 'widgets' ) && current_theme_supports( 'menus' ) ) {
- printf(
- __( 'Manage <a href="%1$s">widgets</a> or <a href="%2$s">menus</a>' ),
- admin_url( 'widgets.php' ),
- admin_url( 'nav-menus.php' )
- );
- } elseif ( current_theme_supports( 'widgets' ) ) {
- echo '<a href="' . admin_url( 'widgets.php' ) . '">' . __( 'Manage widgets' ) . '</a>';
- } else {
- echo '<a href="' . admin_url( 'nav-menus.php' ) . '">' . __( 'Manage menus' ) . '</a>';
- }
- ?>
- </div></li>
+ <?php if ( current_theme_supports( 'widgets' ) ) : ?>
+ <li><?php printf( '<a href="%s" class="welcome-icon welcome-widgets">' . __( 'Manage widgets' ) . '</a>', admin_url( 'widgets.php' ) ); ?></li>
+ <?php endif; ?>
+ <?php if ( current_theme_supports( 'menus' ) ) : ?>
+ <li><?php printf( '<a href="%s" class="welcome-icon welcome-menus">' . __( 'Manage menus' ) . '</a>', admin_url( 'nav-menus.php' ) ); ?></li>
<?php endif; ?>
<?php if ( current_user_can( 'manage_options' ) ) : ?>
<li><?php printf( '<a href="%s" class="welcome-icon welcome-comments">' . __( 'Turn comments on or off' ) . '</a>', admin_url( 'options-discussion.php' ) ); ?></li>
<?php endif; ?>
- <li><?php printf( '<a href="%s" class="welcome-icon welcome-learn-more">' . __( 'Learn more about getting started' ) . '</a>', __( 'https://codex.wordpress.org/First_Steps_With_WordPress' ) ); ?></li>
+ <li><?php printf( '<a href="%s" class="welcome-icon welcome-learn-more">' . __( 'Learn more about getting started' ) . '</a>', __( 'https://wordpress.org/support/article/first-steps-with-wordpress/' ) ); ?></li>
</ul>
</div>
</div>