Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
c5067f3
Add On This Day Widget
alshakero Apr 22, 2026
e1b0ba0
Lint
alshakero Apr 22, 2026
5b7cbcf
Refactor CSS
alshakero Apr 22, 2026
45571e4
Cleaner CSS
alshakero Apr 22, 2026
6bd17f6
Remove unneeded file
alshakero Apr 22, 2026
c1fcec2
Remove extra space
alshakero Apr 22, 2026
bdf30db
Merge branch 'trunk' into add/on-this-day-widget
alshakero Apr 23, 2026
b53e3b5
Add caching for fetching and rendering
alshakero Apr 23, 2026
63c8422
Merge branch 'add/on-this-day-widget' of https://github.com/alshakero…
alshakero Apr 23, 2026
4865fc0
Redesign
alshakero Apr 23, 2026
a32a13f
Fix on mobile
alshakero Apr 23, 2026
a79feb4
Render date pill only on the header of the postbox (not the title)
alshakero Apr 24, 2026
3ea2323
Design fine tuning
alshakero Apr 24, 2026
eceeec1
Merge branch 'trunk' into add/on-this-day-widget
alshakero Apr 24, 2026
aa09b83
Switch to WP_Query
alshakero Apr 24, 2026
05c5a23
Remove #[AllowDynamicProperties] attribute from WP_On_This_Day class
alshakero Apr 25, 2026
488310b
Add an adjustable window size
alshakero Apr 25, 2026
9747fb5
Merge branch 'trunk' into add/on-this-day-widget
alshakero Apr 26, 2026
dfc24f2
Merge branch 'trunk' into add/on-this-day-widget
alshakero Apr 27, 2026
bcf3daa
Address feedback
alshakero Apr 27, 2026
f62cfb3
Merge branch 'add/on-this-day-widget' of https://github.com/alshakero…
alshakero Apr 27, 2026
e446635
Don't concat two strings to make a sentence
alshakero Apr 27, 2026
4f6b9bc
Switch to `wp_scrub_utf8`
alshakero Apr 27, 2026
7dea82e
Bring back success message config
alshakero Apr 27, 2026
5b46861
Fix toggle indicator collapse on On This Day widget
escapemanuele Apr 28, 2026
6e960aa
Merge branch 'trunk' into add/on-this-day-widget
alshakero Apr 28, 2026
afc4ac2
Move away from CSS prop to `attr` for simpler escaping
alshakero Apr 28, 2026
efd8b31
Use `sprintf` instead
alshakero Apr 28, 2026
3d7ea6f
Refine On This Day widget escaping and rendered markup
escapemanuele Apr 29, 2026
ded7416
Run PHPCBF
alshakero Apr 29, 2026
2aa110e
Merge branch 'trunk' into add/on-this-day-widget
alshakero Apr 29, 2026
993c4fb
Switch to `WP_HTML_Tag_Processor` and use CSS for adding ellipsis ins…
alshakero Apr 30, 2026
d20b27d
Merge branch 'add/on-this-day-widget' of https://github.com/alshakero…
alshakero Apr 30, 2026
5a3fb28
Merge branch 'trunk' into add/on-this-day-widget
alshakero May 5, 2026
2c80205
Don't add whitespace for non-block tags and add tests
alshakero May 11, 2026
903f2c3
Merge branch 'add/on-this-day-widget' of https://github.com/alshakero…
alshakero May 11, 2026
d458d25
Merge branch 'trunk' into add/on-this-day-widget
alshakero May 11, 2026
39ed253
Remove excess whitespace
alshakero May 11, 2026
01e5164
Merge branch 'add/on-this-day-widget' of https://github.com/alshakero…
alshakero May 11, 2026
3be969a
Address feedback
alshakero May 12, 2026
165261c
Merge branch 'trunk' into add/on-this-day-widget
alshakero May 12, 2026
67ff936
Redesign:
alshakero May 13, 2026
e165fc7
Merge branch 'trunk' into add/on-this-day-widget
alshakero May 13, 2026
f0b6fb9
Cleaner empty state
alshakero May 20, 2026
d1479ff
Merge branch 'trunk' into add/on-this-day-widget
alshakero May 21, 2026
0658426
Merge branch 'trunk' into add/on-this-day-widget
alshakero May 23, 2026
242b0d5
Address feedback
alshakero Jun 18, 2026
2f00c14
Merge branch 'trunk' into add/on-this-day-widget
alshakero Jun 18, 2026
b4c40ed
Fix file path in tests
alshakero Jun 18, 2026
6c28025
Address all feedback
alshakero Jun 29, 2026
3b4c244
Merge branch 'trunk' into add/on-this-day-widget
alshakero Jun 29, 2026
7e172ea
Merge branch 'trunk' into add/on-this-day-widget
alshakero Jun 29, 2026
c5e11d5
Merge branch 'trunk' into add/on-this-day-widget
alshakero Jun 29, 2026
85cec58
Merge branch 'trunk' into add/on-this-day-widget
alshakero Jun 30, 2026
c9934f4
Merge branch 'trunk' into add/on-this-day-widget
alshakero Jun 30, 2026
0c3571b
Address feedback
alshakero Jul 3, 2026
5fe2fca
Address @peterwilsoncc's feedback
alshakero Jul 8, 2026
49aa78e
Address feedback
alshakero Jul 8, 2026
3075bf5
Merge branch 'trunk' into add/on-this-day-widget
alshakero Jul 8, 2026
657f55f
Merge branch 'trunk' into add/on-this-day-widget
alshakero Jul 9, 2026
ed7b83e
Address feedback
alshakero Jul 9, 2026
9213f82
Merge branch 'add/on-this-day-widget' of https://github.com/alshakero…
alshakero Jul 9, 2026
4ee1483
Address @peterwilsoncc's feedback
alshakero Jul 9, 2026
2403471
Use filter to add classname
alshakero Jul 9, 2026
1f77949
Merge branch 'trunk' into add/on-this-day-widget
alshakero Jul 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/wp-admin/css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,35 @@ body #dashboard-widgets .postbox form .submit {
top: 0;
}

/* On This Day dashboard widget */

#wp_dashboard_on_this_day h3 {
font-weight: 600;
}

#wp_dashboard_on_this_day li {
margin: 0;
padding: 0;
}

#wp_dashboard_on_this_day ul ul {
margin: 0 0 0 18px;
padding: 0;
list-style: disc;
}

#wp_dashboard_on_this_day ul ul li + li {
margin-top: 6px;
}

#wp_dashboard_on_this_day .wp-on-this-day-widget > ul > li + li {
margin-top: 16px;
}

#wp_dashboard_on_this_day .wp-on-this-day-post-author {
color: #646970;
}

/* Browse happy box */

#dashboard-widgets #dashboard_browser_nag.postbox .inside {
Expand Down
238 changes: 238 additions & 0 deletions src/wp-admin/includes/dashboard-on-this-day.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
<?php
/**
* WordPress Dashboard "On This Day" widget.
*
* @package WordPress
* @subpackage Administration
* @since 7.1.0
*/

/**
* Registers the On This Day dashboard widget.
*
* Designed to be the single entry point called from the dashboard setup
* routine. The widget is always registered so that it remains available in
* Screen Options and keeps its user-customized position. When there are no
* matching posts, a marker class is added to the postbox so the widget can be
* hidden with CSS.
*
* @since 7.1.0
*/
function wp_dashboard_on_this_day_setup() {
add_filter( 'postbox_classes_dashboard_wp_dashboard_on_this_day', 'wp_dashboard_on_this_day_postbox_classes' );

wp_add_dashboard_widget(
'wp_dashboard_on_this_day',
__( 'On This Day' ),
'wp_dashboard_on_this_day'
);
}

/**
* Hides the On This Day postbox when there are no posts to show.
*
* Adds the core `hidden` class so the widget stays registered — preserving its
* Screen Options entry and user-customized position — while being hidden when
* empty. A user can still reveal it via Screen Options, in which case the
* placeholder message is shown.
*
* @since 7.1.0
*
* @param string[] $classes An array of postbox classes.
* @return string[] Filtered postbox classes.
*/
function wp_dashboard_on_this_day_postbox_classes( $classes ) {
if ( empty( wp_dashboard_on_this_day_get_posts() ) ) {
$classes[] = 'hidden';
}

return $classes;
}

/**
* Renders the On This Day dashboard widget.
*
* Outputs the matching posts grouped by publication year, newest year first.
*
* @since 7.1.0
*/
function wp_dashboard_on_this_day() {
$posts = wp_dashboard_on_this_day_get_posts();

if ( empty( $posts ) ) {
// Placeholder shown when a user reveals the hidden widget via Screen
// Options on a day with no matching posts.
echo '<p>' . esc_html__( 'No posts were published on this day in previous years.' ) . '</p>';
return;
Comment thread
joedolson marked this conversation as resolved.
}

$posts_by_year = array();
$post_count = count( $posts );

foreach ( $posts as $post ) {
$year = get_the_date( 'Y', $post );

if ( ! isset( $posts_by_year[ $year ] ) ) {
$posts_by_year[ $year ] = array();
}

$posts_by_year[ $year ][] = $post;
}

/* translators: Date format for the On This Day widget date, without year. See https://www.php.net/manual/datetime.format.php */
$date = '<strong>' . esc_html( wp_date( _x( 'F jS', 'on this day date format' ) ) ) . '</strong>';
?>
<div class="wp-on-this-day-widget">
<p>
<?php
if ( 1 === $post_count ) {
printf(
/* translators: %s: Date, without year. */
esc_html__( 'One post has been published on %s:' ),
$date // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Date is escaped above.
);
} else {
printf(
esc_html(
/* translators: 1: Number of posts, 2: Date, without year. */
_n(
'%1$s post has been published on %2$s:',
'%1$s posts have been published on %2$s:',
$post_count
)
),
esc_html( number_format_i18n( $post_count ) ),
$date // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Date is escaped above.
);
}
?>
</p>
<ul>
<?php foreach ( $posts_by_year as $year => $year_posts ) : ?>
<li>
<h3><?php echo esc_html( $year ); ?></h3>
<ul>
<?php foreach ( $year_posts as $year_post ) : ?>
<?php
$title = get_the_title( $year_post );

if ( '' === trim( $title ) ) {
$title = __( '(no title)' );
}

$author_id = (int) $year_post->post_author;
$author_name = $author_id > 0 ? (string) get_the_author_meta( 'display_name', $author_id ) : '';
$show_author = '' !== trim( $author_name ) && get_current_user_id() !== $author_id;
?>
<li>
<a href="<?php echo esc_url( get_permalink( $year_post ) ); ?>"><?php echo esc_html( $title ); ?></a>
<?php if ( $show_author ) : ?>
<?php
echo '<span class="wp-on-this-day-post-author">' . esc_html(
sprintf(
/* translators: %s: Post author's display name. */
__( 'by %s' ),
$author_name
)
) . '</span>';
?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php
}

/**
* Retrieves published posts from all authors that were published on this
* calendar day in previous years.
*
* The date constraint matches today's month and day, combined with a
* `before` clause anchored to January 1 of the current year. Up to ten posts
* are returned; use the `wp_dashboard_on_this_day_query_args` filter to change
* the limit. Results are cached by WP_Query's native query caching.
*
* @since 7.1.0
*
* @return WP_Post[] Array of posts ordered by newest first.
*/
function wp_dashboard_on_this_day_get_posts() {
$today = current_datetime();
$year = (int) $today->format( 'Y' );
$date_query = array(
'relation' => 'AND',
array(
'before' => array( 'year' => $year ),
),
_wp_dashboard_on_this_day_date_query_clause( $today ),
);

$args = array(
'post_type' => 'post',
'post_status' => array( 'publish' ),
'posts_per_page' => 10,
'ignore_sticky_posts' => true,
'orderby' => 'date',
'order' => 'DESC',
'no_found_rows' => true,
'update_post_term_cache' => false,
Comment thread
t-hamano marked this conversation as resolved.
'update_post_meta_cache' => false,
'date_query' => $date_query,
);

/**
* Filters the arguments used to query posts for the On This Day dashboard widget.
*
* @since 7.1.0
*
* @param array $args WP_Query arguments.
*/
$args = apply_filters( 'wp_dashboard_on_this_day_query_args', $args );

$query = new WP_Query( $args );

return $query->posts;
}

/**
* Builds the date query clause for today's anniversary date.
*
* On February 28 in a non-leap year, February 29 posts are included so
* leap-day anniversaries still appear.
*
* @since 7.1.0
* @access private
*
* @param DateTimeInterface $date Date to build the clause for.
* @return array Date query clause.
*/
function _wp_dashboard_on_this_day_date_query_clause( $date ) {
$month = (int) $date->format( 'm' );
$day = (int) $date->format( 'd' );
$clause = array(
'month' => $month,
'day' => $day,
);

// Display leap day posts on Feb 28 in non leap years.
if (
28 === $day
&& 2 === $month
&& false === (bool) $date->format( 'L' )
) {
$clause = array(
'relation' => 'OR',
$clause,
array(
'month' => 2,
'day' => 29,
),
);
}

return $clause;
}
7 changes: 7 additions & 0 deletions src/wp-admin/includes/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ function wp_dashboard_setup() {
wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' );
}

// On This Day.
if ( ! function_exists( 'wp_dashboard_on_this_day_setup' ) ) {
require_once ABSPATH . 'wp-admin/includes/dashboard-on-this-day.php';
}

wp_dashboard_on_this_day_setup();

Comment thread
joedolson marked this conversation as resolved.
// WordPress Events and News.
wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress Events and News' ), 'wp_dashboard_events_news' );

Expand Down
Loading
Loading