Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
29a796a
Show excerpts for untitled On This Day posts
alshakero Jul 17, 2026
f55699a
Merge branch 'trunk' into alshakero/on-this-day-untitled-excerpt
alshakero Jul 17, 2026
cae24b7
Merge branch 'trunk' into alshakero/on-this-day-untitled-excerpt
alshakero Jul 20, 2026
d2626b8
Merge branch 'trunk' into alshakero/on-this-day-untitled-excerpt
alshakero Jul 22, 2026
edfad97
Merge branch 'trunk' into alshakero/on-this-day-untitled-excerpt
alshakero Jul 23, 2026
81e3b31
Merge branch 'trunk' into alshakero/on-this-day-untitled-excerpt
alshakero Jul 23, 2026
d2bcdd3
Test untitled On This Day excerpts for readable private posts
alshakero Jul 24, 2026
2064408
Address feedback
alshakero Jul 24, 2026
0455708
Fix On This Day limit test title assertions
alshakero Jul 24, 2026
a768873
Merge branch 'trunk' into alshakero/on-this-day-untitled-excerpt
alshakero Jul 24, 2026
2220636
Merge branch 'trunk' into alshakero/on-this-day-untitled-excerpt
alshakero Jul 27, 2026
f975fcc
Docs: Clarify On This Day excerpt visibility
alshakero Jul 27, 2026
6cc19e5
Merge branch 'trunk' into alshakero/on-this-day-untitled-excerpt
alshakero Jul 27, 2026
bf3511d
Apply suggestion from @peterwilsoncc
joedolson Jul 30, 2026
eff0ac9
Administration: Inline no-title excerpt logic
alshakero Jul 31, 2026
e18b0d9
Administration: Check no-title post readability
alshakero Jul 31, 2026
d5aceae
Merge branch 'trunk' into alshakero/on-this-day-untitled-excerpt
alshakero Jul 31, 2026
fca39c9
Administration: Cover On This Day excerpt rendering
alshakero Aug 2, 2026
918eab0
Merge branch 'trunk' into alshakero/on-this-day-untitled-excerpt
alshakero Aug 2, 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
20 changes: 18 additions & 2 deletions src/wp-admin/includes/dashboard-on-this-day.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,34 @@ function wp_dashboard_on_this_day() {
<ul>
<?php foreach ( $year_posts as $year_post ) : ?>
<?php
$title = get_the_title( $year_post );
$title = get_the_title( $year_post );
$no_title_excerpt = '';

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

if ( current_user_can( 'read_post', $year_post->ID ) && ! post_password_required( $year_post ) ) {
$excerpt = get_the_excerpt( $year_post );

if ( is_string( $excerpt ) && '' !== $excerpt ) {
$no_title_excerpt = wp_trim_words( $excerpt, 15 );
}
}
}

$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>
<a href="<?php echo esc_url( get_permalink( $year_post ) ); ?>">
<?php echo esc_html( $title ); ?>
<?php
if ( '' !== $no_title_excerpt ) {
echo esc_html( $no_title_excerpt );
}
?>
</a>
<?php if ( $show_author ) : ?>
<?php
echo '<span class="wp-on-this-day-post-author">' . esc_html(
Expand Down
191 changes: 182 additions & 9 deletions tests/phpunit/tests/admin/wpDashboardOnThisDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,28 @@ private function set_up_dashboard_screen() {
* @param string $title Post title.
* @param int $years_ago Number of years before today.
* @param string $time Post time.
* @param array $post_args Additional post arguments.
* @return int Post ID.
*/
private function create_matching_post(
int $author_id,
string $title = 'A memory from last year',
int $years_ago = 1,
string $time = '12:00:00'
string $time = '12:00:00',
array $post_args = array()
): int {
$post_date = current_datetime()->modify( '-' . $years_ago . ' years' )->format( 'Y-m-d' ) . ' ' . $time;

return self::factory()->post->create(
array(
'post_author' => $author_id,
'post_date' => $post_date,
'post_date_gmt' => get_gmt_from_date( $post_date ),
'post_status' => 'publish',
'post_title' => $title,
array_merge(
array(
'post_author' => $author_id,
'post_date' => $post_date,
'post_date_gmt' => get_gmt_from_date( $post_date ),
'post_status' => 'publish',
'post_title' => $title,
),
$post_args
)
);
}
Expand Down Expand Up @@ -338,6 +343,162 @@ public function test_widget_groups_posts_by_year() {
/**
* @ticket 65116
*
* @covers ::wp_dashboard_on_this_day
*/
public function test_widget_includes_trimmed_excerpt_for_untitled_posts() {
Comment thread
alshakero marked this conversation as resolved.
wp_set_current_user( self::$user_id );

$words = array();
for ( $n = 1; $n <= 20; $n++ ) {
$words[] = 'word' . $n;
}

$this->create_matching_post(
self::$user_id,
'',
1,
'12:00:00',
array(
'post_excerpt' => implode( ' ', $words ),
)
);

ob_start();
wp_dashboard_on_this_day();
$output = ob_get_clean();

$this->assertStringContainsString( '(no title)', $output );
$this->assertStringContainsString( 'word15', $output, 'The 15th word should be present.' );
$this->assertStringNotContainsString( 'word16', $output, 'The 16th word should be trimmed.' );
$this->assertStringContainsString( '&hellip;', $output, 'The excerpt should end with an ellipsis.' );
}

/**
* @ticket 65116
*
* @covers ::wp_dashboard_on_this_day
*/
public function test_widget_does_not_append_excerpt_to_titled_posts() {
wp_set_current_user( self::$user_id );

$this->create_matching_post(
self::$user_id,
'A titled anniversary memory',
1,
'12:00:00',
array(
'post_excerpt' => 'This excerpt should not be shown.',
)
);

ob_start();
wp_dashboard_on_this_day();
$output = ob_get_clean();

$this->assertStringContainsString( 'A titled anniversary memory', $output );
$this->assertStringNotContainsString( 'This excerpt should not be shown.', $output );
}

/**
* @ticket 65116
*
* @covers ::wp_dashboard_on_this_day
*/
public function test_widget_includes_trimmed_excerpt_for_untitled_private_posts_authored_by_current_user() {
$this->set_up_dashboard_screen();

wp_set_current_user( self::$user_id );

$this->create_matching_post(
self::$user_id,
'',
1,
'12:00:00',
array(
'post_excerpt' => 'Readable private anniversary memory.',
'post_status' => 'private',
)
);

add_filter( 'wp_dashboard_on_this_day_query_args', array( $this, 'filter_on_this_day_query_private_posts' ) );

ob_start();
try {
wp_dashboard_on_this_day();
$output = ob_get_clean();
} finally {
remove_filter( 'wp_dashboard_on_this_day_query_args', array( $this, 'filter_on_this_day_query_private_posts' ) );
}

$this->assertStringContainsString( '(no title)', $output );
$this->assertStringContainsString( 'Readable private anniversary memory.', $output );
}

/**
* @ticket 65116
*
* @covers ::wp_dashboard_on_this_day
*/
public function test_widget_hides_untitled_post_excerpt_for_unreadable_posts() {
$this->set_up_dashboard_screen();

wp_set_current_user( self::$user_id );

$post_id = $this->create_matching_post(
self::$other_user_id,
'',
1,
'12:00:00',
array(
'post_excerpt' => 'Unreadable private anniversary memory.',
'post_status' => 'private',
)
);

add_filter( 'wp_dashboard_on_this_day_query_args', array( $this, 'filter_on_this_day_query_private_posts' ) );

ob_start();
try {
wp_dashboard_on_this_day();
$output = ob_get_clean();
} finally {
remove_filter( 'wp_dashboard_on_this_day_query_args', array( $this, 'filter_on_this_day_query_private_posts' ) );
}

$this->assertFalse( current_user_can( 'read_post', $post_id ) );
$this->assertStringContainsString( '(no title)', $output );
$this->assertStringNotContainsString( 'Unreadable private anniversary memory.', $output );
}

/**
* @ticket 65116
*
* @covers ::wp_dashboard_on_this_day
*/
public function test_widget_hides_untitled_post_excerpt_for_password_protected_posts() {
Comment thread
t-hamano marked this conversation as resolved.
$this->set_up_dashboard_screen();

wp_set_current_user( self::$user_id );

$this->create_matching_post(
self::$user_id,
'',
1,
'12:00:00',
array(
'post_excerpt' => 'Private anniversary memory.',
'post_password' => 'secret',
)
);

ob_start();
wp_dashboard_on_this_day();
$output = ob_get_clean();

$this->assertStringNotContainsString( 'Private anniversary memory.', $output );
}
Comment thread
alshakero marked this conversation as resolved.

/**
* @covers ::wp_dashboard_on_this_day
* @covers ::wp_dashboard_on_this_day_get_posts
*/
Expand All @@ -353,8 +514,20 @@ public function test_widget_limits_posts_to_ten() {
$output = ob_get_clean();

$this->assertStringContainsString( '10 posts have been published on <strong>' . wp_date( 'F jS' ) . '</strong>:', $output );
$this->assertStringContainsString( 'Anniversary post 1<', $output );
$this->assertStringContainsString( 'Anniversary post 10<', $output );
$this->assertMatchesRegularExpression( '/>\s*Anniversary post 1\s*<\/a>/', $output );
$this->assertMatchesRegularExpression( '/>\s*Anniversary post 10\s*<\/a>/', $output );
$this->assertStringNotContainsString( 'Anniversary post 11', $output );
}

/**
* Filters the On This Day query to include private posts.
*
* @param array $args WP_Query arguments.
* @return array Filtered query arguments.
*/
public function filter_on_this_day_query_private_posts( $args ) {
$args['post_status'] = array( 'private' );

return $args;
}
}
Loading