Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2930fd1
Increase query limit, per @m.
peterwilsoncc Oct 25, 2026
c3e69fe
OTD: Markup form.
peterwilsoncc Oct 25, 2026
794f554
On This Day opt-in.
peterwilsoncc Oct 25, 2026
b406247
No need for setting to be stored on object.
peterwilsoncc Oct 25, 2026
7fae9f7
Did not mean to delete this.
peterwilsoncc Oct 25, 2026
0fea482
Prefix all the things.
peterwilsoncc Oct 25, 2026
bba27d3
missing comma.
peterwilsoncc Oct 26, 2026
7f5b550
Update test for number of posts queried by OTD widget.
peterwilsoncc Oct 26, 2026
4774770
Remove uneeded teardown.
peterwilsoncc Oct 26, 2026
132390e
Use get_echo helper for test suite.
peterwilsoncc Oct 26, 2026
08c4372
Add messages to tests with multiple assertions.
peterwilsoncc Oct 26, 2026
1948059
Clarify OTD tests are for OTD.
peterwilsoncc Oct 26, 2026
f0420de
Ensure OTD posts are hidden before opt in.
peterwilsoncc Oct 26, 2026
e0836e0
Do not render form after opt-in or -out.
peterwilsoncc Oct 26, 2026
6a87b41
Test nothing displayed after opt-out. HTML renders for list.
peterwilsoncc Oct 26, 2026
2a2f6db
Ensure list displays after user has opted in.
peterwilsoncc Oct 26, 2026
f1712ba
Add summary to OTD tests.
peterwilsoncc Oct 26, 2026
d604837
i18n fixes.
peterwilsoncc Oct 26, 2026
0f3f610
Type fixes.
peterwilsoncc Oct 26, 2026
b5174d2
Trolling?
peterwilsoncc Oct 26, 2026
32f28b2
Smarten up toggling display.
peterwilsoncc Oct 26, 2026
c9fd3e8
Comment: explain what else means.
peterwilsoncc Oct 26, 2026
ec27f55
Use variable to determine whether to display the form, remove pointle…
peterwilsoncc Oct 26, 2026
b58426e
Typo: Filter -> filtered.
peterwilsoncc Oct 26, 2026
639820b
Merge branch 'trunk' into do/65116-otd-follow-up
westonruter Oct 26, 2026
014c605
Use mock action and move method to closure
westonruter Oct 26, 2026
2decea5
Fix static analysis in test_otd_renders_posts_from_all_authors_and_un…
westonruter Oct 26, 2026
f02d84e
Improve static analysis in test_recent_comments_widget_remains_regist…
westonruter Oct 26, 2026
22692a0
Improve static analysis of get_inline_styles_by_id test helper
westonruter Oct 26, 2026
a622593
Fix styles: extra line at bottom of widget.
peterwilsoncc Oct 26, 2026
a7ce5fa
Modify LI styles to account for those in common.css.
peterwilsoncc Oct 26, 2026
fbbfa23
Account for hide-if-no-js if there is no JS.
peterwilsoncc Oct 26, 2026
b3fc866
Merge branch 'trunk' into do/65116-otd-follow-up
peterwilsoncc Oct 26, 2026
2dad3b6
Pre-flight filter for OTD activity.
peterwilsoncc Oct 26, 2026
d990e65
Test for hidden class rather than display style.
peterwilsoncc Oct 27, 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
61 changes: 61 additions & 0 deletions src/js/_enqueues/admin/postbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,21 @@
postboxes.setMetaBoxReordering( enabled );
postboxes.save_meta_box_reordering_state( enabled );
} );

$( '.wp-on-this-day-toggle' ).on( 'click.postboxes', function() {
var enabled = $( this ).prop( 'checked' );

postboxes.setOnThisDayDisplay( enabled );
postboxes.save_on_this_day_display( enabled );
} );

$( '#wp-on-this-day-posts-form button' ).on( 'click.postboxes', function( event ) {
event.preventDefault();
var enabled = '1' === $( this ).prop( 'value' );

postboxes.setOnThisDayDisplay( enabled );
postboxes.save_on_this_day_display( enabled );
} );
},

/**
Expand Down Expand Up @@ -495,6 +510,26 @@
}
},

/**
* Enables or disables the On This Day display in the activity widget.
*
* @since 7.2.0
*
* @param {boolean} enabled Whether On This Day should be enabled.
* @return {void}
*/
setOnThisDayDisplay: function( enabled ) {
var $onThisDayWidget = $( '#wp-on-this-day-posts' ),
$onThisDayList = $( '#wp-on-this-day-posts-list' ),
$onThisDayForm = $( '#wp-on-this-day-posts-form'),
$onThisDayScreenOption = $( '#wp-on-this-day-toggle' );

$onThisDayForm.hide(); // Always hidden once a choice is made.
$onThisDayWidget.toggle( enabled ).toggleClass( 'hidden', ! enabled );
$onThisDayList.toggle( enabled );
$onThisDayScreenOption.prop( 'checked', enabled );
},

/**
* Saves the state of the postboxes to the server.
*
Expand Down Expand Up @@ -560,6 +595,32 @@
);
},

/**
* Saves the On This Day setting to the server.
*
* @since 7.2.0
*
* @param {boolean} enabled Whether On This Day activity is enabled.
* @return {void}
*/
save_on_this_day_display: function( enabled ) {
$.post(
ajaxurl,
{
action: 'on-this-day-display',
enabled: enabled ? 1 : 0,
screenoptionnonce: $( '#screenoptionnonce' ).val()
},
function() {
wp.a11y.speak(
enabled ?
__( 'On This Day display is enabled.' ) :
__( 'On This Day display is disabled.' )
);
}
);
},

/**
* Saves the order of the postboxes to the server.
*
Expand Down
1 change: 1 addition & 0 deletions src/wp-admin/admin-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
'closed-postboxes',
'hidden-columns',
'meta-box-reordering',
'on-this-day-display',
'update-welcome-panel',
'menu-get-metabox',
'wp-link-ajax',
Expand Down
18 changes: 13 additions & 5 deletions src/wp-admin/css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -931,27 +931,28 @@ body #dashboard-widgets .postbox form .submit {

#future-posts ul,
#published-posts ul,
#on-this-day-posts ul {
#wp-on-this-day-posts ul {
margin: 8px -12px 0 -12px;
}

#future-posts li,
#published-posts li,
#on-this-day-posts li {
#wp-on-this-day-posts li {
display: grid;
grid-template-columns: clamp(160px, calc(2vw + 140px), 200px) auto;
column-gap: 10px;
color: #646970;
padding: 4px 12px;
padding: 7px 12px;
margin-bottom: 0;
}

#future-posts li:nth-child(odd),
#published-posts li:nth-child(odd),
#on-this-day-posts li:nth-child(odd) {
#wp-on-this-day-posts-list li:nth-child(odd) {
background-color: #f6f7f7;
}

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

Expand All @@ -966,6 +967,13 @@ body #dashboard-widgets .postbox form .submit {
margin-bottom: 0;
}

/* The last visible block, ignoring any hidden blocks that follow it. */
.activity-block:nth-last-child(1 of :not(.hidden)),
.no-js .activity-block:nth-last-child(1 of :not(.hidden, .hide-if-no-js)) {
border-bottom: none;
margin-bottom: 0;
}

.activity-block .subsubsub li {
color: #646970;
}
Expand Down
16 changes: 16 additions & 0 deletions src/wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,22 @@ function wp_ajax_meta_box_reordering() {
wp_die( 1 );
}

/**
* Handles the On This Day display setting via Ajax.
*
* @since 7.2.0
*
* @return never
*/
function wp_ajax_on_this_day_display(): void {
check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' );

$enabled = isset( $_POST['enabled'] ) && is_string( $_POST['enabled'] ) && '1' === $_POST['enabled'];
update_user_option( get_current_user_id(), 'dashboard_show_on_this_day', $enabled ? 'opt-in' : 'opt-out' );

wp_die( 1 );
}

/**
* Handles updating whether to display the welcome panel via AJAX.
*
Expand Down
13 changes: 13 additions & 0 deletions src/wp-admin/includes/class-wp-screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ public function show_screen_options() {

if ( $has_meta_boxes ) {
$additional_settings .= $this->get_meta_box_reordering_option();
$additional_settings .= $this->get_on_this_day_option();
}

if ( 'post' === $this->base ) {
Expand Down Expand Up @@ -1184,6 +1185,18 @@ private function get_meta_box_reordering_option() {
. '<label for="meta-box-reordering">' . __( 'Allow screen elements to be rearranged' ) . '</label>';
}

/**
* Gets the option to enable or disable meta box reordering.
*
* @since 7.2.0
*
* @return string Meta box reordering option markup.
*/
private function get_on_this_day_option(): string {
return '<input class="wp-on-this-day-toggle" name="wp-on-this-day-toggle" type="checkbox" id="wp-on-this-day-toggle" value="opt-in"' . checked( wp_is_on_this_day_enabled(), true, false ) . ' />'
. '<label for="wp-on-this-day-toggle">' . __( 'Display "On This Day" posts in Activity' ) . '</label>';
}

/**
* Checks whether the screen has meta boxes.
*
Expand Down
66 changes: 62 additions & 4 deletions src/wp-admin/includes/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,25 @@ function wp_dashboard_site_activity() {
* @return bool False if no posts were found. True otherwise.
*/
function wp_dashboard_on_this_day( $posts = null ) {
if ( 'opt-out' === get_user_option( 'dashboard_show_on_this_day' ) ) {
$display_list = false;
$display_form = false;
} elseif ( 'opt-in' === get_user_option( 'dashboard_show_on_this_day' ) ) {
$display_list = true;
$display_form = false;
} else {
/*
* User has not yet chosen to opt-in or -out.
*
* As On This Day features can be distressing in some circumstances,
* users are prompted to opt-in or -out of the feature prior to the
* list of posts being displayed. If they have done neither a form is
* displayed prompting them to make a choice.
*/
$display_list = false;
$display_form = true;
}

if ( null === $posts ) {
$posts = wp_dashboard_on_this_day_get_posts();
}
Expand All @@ -1028,9 +1047,29 @@ function wp_dashboard_on_this_day( $posts = null ) {
return false;
}

echo '<div id="on-this-day-posts" class="activity-block">';
echo '<h3>' . esc_html__( 'Published On This Day' ) . '</h3>';
echo '<ul>';
?>
<div id="wp-on-this-day-posts" class="activity-block wp-on-this-day-posts-title <?php echo $display_form ? 'hide-if-no-js' : ''; ?> <?php echo ! $display_form && ! $display_list ? 'hidden' : ''; ?>">
<h3><?php _e( 'Published On This Day' ); ?></h3>
<?php

if ( $display_form ) :
?>
<form method="post" id="wp-on-this-day-posts-form">
<p>
<?php _e( 'Would you like to see posts from previous years here? You can change this later in the Screen Options tab.' ); ?>
</p>
<p>
<?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce' ); ?>
<button name="enabled" value="1" class="button button-primary"><?php _e( 'Yes' ); ?></button>
<button name="enabled" value="0" class="button"><?php _e( 'No' ); ?></button>
</p>
</form>
<?php
endif;

?>
<ul id="wp-on-this-day-posts-list" <?php echo $display_list ? '' : 'class="hidden"'; ?>>
<?php

foreach ( $posts as $post ) {
/* translators: Date format for posts published in a previous year. */
Expand Down Expand Up @@ -1106,13 +1145,32 @@ function wp_dashboard_on_this_day( $posts = null ) {
* @return WP_Post[] Array of posts ordered by newest first.
*/
function wp_dashboard_on_this_day_get_posts() {
/**
* Filters whether to short-circuit performing the query for the On This Day dashboard query.
*
* Filter to allow the bypassing of the SQL query for the On This Day section of the activity
* widget.
*
* Return null for the default query to run or an array of post IDs to override the built in
* database query. Returning an empty array will have the effect of turning the feature off.
*
* @since 7.2.0
*
* @param WP_Post[]|null $preflight Null to continue, array of post objects to bypass query.
*/
$preflight = apply_filters( 'pre_wp_dashboard_on_this_day_get_posts', null );

if ( is_array( $preflight ) ) {
return $preflight;
}

$today = current_datetime();
$year = (int) $today->format( 'Y' );

$args = array(
'post_type' => 'post',
'post_status' => array( 'publish' ),
'posts_per_page' => 10,
'posts_per_page' => 100,
'ignore_sticky_posts' => true,
'orderby' => 'date',
'order' => 'DESC',
Expand Down
13 changes: 13 additions & 0 deletions src/wp-admin/includes/screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ function wp_is_meta_box_reordering_enabled() {
return false === $setting ? true : 'disabled' !== $setting;
}

/**
* Determines whether On This Day display is enabled.
*
* @since 7.2.0
*
* @return bool Whether meta box reordering is enabled.
*/
function wp_is_on_this_day_enabled(): bool {
$setting = get_user_option( 'dashboard_show_on_this_day' );

return 'opt-in' === $setting;
}

/**
* Register and configure an admin screen option
*
Expand Down
Loading
Loading