Skip to content

Administration: Show excerpts for untitled On This Day posts - #12581

Open
alshakero wants to merge 17 commits into
WordPress:trunkfrom
alshakero:alshakero/on-this-day-untitled-excerpt
Open

Administration: Show excerpts for untitled On This Day posts#12581
alshakero wants to merge 17 commits into
WordPress:trunkfrom
alshakero:alshakero/on-this-day-untitled-excerpt

Conversation

@alshakero

@alshakero alshakero commented Jul 17, 2026

Copy link
Copy Markdown

Summary

Trac: https://core.trac.wordpress.org/ticket/65658
See: https://wordpress.org/support/topic/on-this-day-widget/

This adds the same untitled-post fallback used in the posts list table to the On This Day dashboard widget. When a matching post has no title, the widget now appends a trimmed excerpt after (no title) when the current user can read the post and the post is not password protected.

The change keeps protected post excerpts hidden and adds PHPUnit coverage for the trimmed excerpt and password-protected cases.

Testing

  • Checkout this PR locally and run npm run env:start, then npm run env:install.
  • Go to Dashboard (admin:password), you should see the widget.
  • Insepect its empty state.
  • Import this file to create backdated posts: filexml
  • Use the widget.
  • Update the post to get rid of the title.
  • It should render (no title) 15 word excerpt.

Screenshots

Before

image

After

image

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@alshakero
alshakero force-pushed the alshakero/on-this-day-untitled-excerpt branch from 7ce530a to 29a796a Compare July 17, 2026 14:51
@alshakero
alshakero marked this pull request as ready for review July 17, 2026 14:59
@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props alshakero, joedolson, mukesh27, peterwilsoncc, wildworks, bph.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@bph

bph commented Jul 17, 2026

Copy link
Copy Markdown

Thank you @alshakero for jumping right on it!

Comment thread src/wp-admin/includes/dashboard-on-this-day.php Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 16:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the wp-admin “On This Day” dashboard widget so that when a matched post has an empty title, it can display a short trimmed excerpt alongside the “(no title)” fallback (while ensuring password-protected posts do not show excerpts). It also extends PHPUnit coverage for the new excerpt behavior.

Changes:

  • Add a private helper to compute a 15-word trimmed excerpt for untitled posts in the On This Day widget.
  • Update widget rendering to append the excerpt when applicable.
  • Expand PHPUnit tests and extend the test post factory helper to accept additional post args.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
tests/phpunit/tests/admin/wpOnThisDay.php Extends the test helper and adds coverage for trimmed excerpt output and password-protected excerpt suppression.
src/wp-admin/includes/dashboard-on-this-day.php Adds helper logic for untitled-post excerpt generation and renders the excerpt in the dashboard widget output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/wp-admin/includes/dashboard-on-this-day.php Outdated
Comment thread src/wp-admin/includes/dashboard-on-this-day.php Outdated
Comment thread tests/phpunit/tests/admin/wpDashboardOnThisDay.php
Copilot AI review requested due to automatic review settings July 23, 2026 12:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/wp-admin/includes/dashboard-on-this-day.php:67

  • Because the widget query args are filterable via wp_dashboard_on_this_day_query_args, this helper should also enforce a read-capability check (as the posts list table does) to avoid exposing excerpts if a plugin/theme broadens the query to include non-public posts the current user can’t read.
function _wp_dashboard_on_this_day_get_no_title_excerpt( $post ) {
	if ( '' !== get_the_title( $post )
		|| post_password_required( $post )
	) {
		return '';

Copilot AI review requested due to automatic review settings July 23, 2026 21:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/wp-admin/includes/dashboard-on-this-day.php:67

  • The caller treats whitespace-only titles as “no title” (using trim()), but this helper only checks for an exactly empty title via '' !== get_the_title( $post ). For posts whose titles are only whitespace, the widget will show “(no title)” but will never append the excerpt. Consider trimming the title here as well so the excerpt behavior matches the widget’s no-title detection.
function _wp_dashboard_on_this_day_get_no_title_excerpt( $post ) {
	if ( '' !== get_the_title( $post )
		|| post_password_required( $post )
	) {
		return '';

@peterwilsoncc peterwilsoncc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good and is testing well.

I've put a couple of very minor comments inline.

Comment thread src/wp-admin/includes/dashboard-on-this-day.php Outdated
Comment thread tests/phpunit/tests/admin/wpDashboardOnThisDay.php
Comment thread src/wp-admin/includes/dashboard-on-this-day.php Outdated
Copilot AI review requested due to automatic review settings July 24, 2026 08:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/wp-admin/includes/dashboard-on-this-day.php:68

  • The no-title excerpt helper doesn’t match the widget’s own “no title” check and the posts list table behavior: it checks get_the_title() without trim(), so a whitespace-only title triggers the widget fallback but the helper will return an empty excerpt. It also doesn’t ensure the current user can read the post, which can leak excerpt text if the query is filtered to include non-public posts.

Consider aligning this with WP_Posts_List_Table::get_no_title_excerpt() by trimming the title and checking current_user_can( 'read_post', $post->ID ), and update the docblock accordingly.

	if ( '' !== get_the_title( $post )
		|| post_password_required( $post )
	) {
		return '';
	}

Copilot AI review requested due to automatic review settings July 24, 2026 08:07
Copilot AI review requested due to automatic review settings July 24, 2026 10:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/wp-admin/includes/dashboard-on-this-day.php:67

  • The widget treats whitespace-only titles as “no title” (via trim()), but this helper only checks for an empty string and does not verify the current user can read the post. If wp_dashboard_on_this_day_query_args is filtered to include private/draft posts, this can lead to (no title) being shown without an excerpt for whitespace titles, and potentially leaking an excerpt for posts the current user cannot read. Align the helper with the caller and the posts list table behavior by trimming the title and checking current_user_can( 'read_post', $post->ID ).
function _wp_dashboard_on_this_day_get_no_title_excerpt( $post ) {
	if ( '' !== get_the_title( $post )
		|| post_password_required( $post )
	) {
		return '';

@alshakero

Copy link
Copy Markdown
Author

Addressed all!

Copilot AI review requested due to automatic review settings July 24, 2026 10:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

src/wp-admin/includes/dashboard-on-this-day.php:68

  • _wp_dashboard_on_this_day_get_no_title_excerpt() doesn’t enforce the “current user can read the post” requirement (WP_Posts_List_Table::get_no_title_excerpt() checks current_user_can( 'read_post', $post->ID )). Also, the widget treats whitespace-only titles as untitled via trim(), but this helper only checks for an empty string, so untitled whitespace titles will show “(no title)” without an excerpt.
	if ( '' !== get_the_title( $post )
		|| post_password_required( $post )
	) {
		return '';
	}

tests/phpunit/tests/admin/wpOnThisDay.php:355

  • The new no-title excerpt behavior is intended to only show when the current user can read the post, but the tests don’t currently cover the negative case (e.g., a draft/private post from another author surfaced via the query args filter should not output a trimmed excerpt for a subscriber). Adding a regression test similar to wpPostsListTable::test_no_title_excerpt_hidden_when_user_cannot_read_post would lock this down.
	/**
	 * @covers ::wp_dashboard_on_this_day
	 * @covers ::_wp_dashboard_on_this_day_get_no_title_excerpt
	 */
	public function test_widget_includes_trimmed_excerpt_for_untitled_private_posts_authored_by_current_user() {

Comment thread src/wp-admin/includes/dashboard-on-this-day.php Outdated
Copilot AI review requested due to automatic review settings July 27, 2026 21:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (3)

src/wp-admin/includes/dashboard-on-this-day.php:67

  • The widget treats whitespace-only titles as “no title” (via trim() in wp_dashboard_on_this_day()), but this helper checks for a strictly empty title. That can prevent excerpts from being shown for whitespace-only titles. Also, the posts list table’s equivalent helper guards on current_user_can( 'read_post', $post->ID ); adding the same check here keeps behavior consistent (and matches the PR description when filters broaden the query beyond published posts).
/**
 * Gets a trimmed excerpt to display in place of a missing post title.
 *
 * The post is expected to be readable by the current user, as enforced by the
 * widget query. Only returns text for posts that have no title and do not
 * require a password.
 *
 * @since 7.1.0
 * @access private
 *
 * @param WP_Post $post The current WP_Post object.
 * @return string The trimmed excerpt, or an empty string.
 */
function _wp_dashboard_on_this_day_get_no_title_excerpt( $post ) {
	if ( '' !== get_the_title( $post )
		|| post_password_required( $post )

tests/phpunit/tests/admin/wpDashboardOnThisDay.php:379

  • This new test appears to be for Trac #65658 (per the PR description), but the docblock still references #65116. Please update the ticket annotation so the test is linked to the bug being fixed.
	 * @ticket 65116

tests/phpunit/tests/admin/wpDashboardOnThisDay.php:416

  • This new test appears to be for Trac #65658 (per the PR description), but the docblock still references #65116. Please update the ticket annotation so the test is linked to the bug being fixed.
	 * @ticket 65116

Comment thread tests/phpunit/tests/admin/wpDashboardOnThisDay.php
Copilot AI review requested due to automatic review settings July 27, 2026 21:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (4)

src/wp-admin/includes/dashboard-on-this-day.php:69

  • This helper is called when trim( $title ) is empty, but it checks get_the_title() without trimming, so whitespace-only titles will skip the excerpt. Also, unlike the posts list table’s get_no_title_excerpt(), this doesn’t verify current_user_can( 'read_post', $post->ID ), so filtered queries that include non-readable posts could leak excerpt text.
	if ( '' !== get_the_title( $post )
		|| post_password_required( $post )
	) {
		return '';

tests/phpunit/tests/admin/wpDashboardOnThisDay.php:344

  • This new test is specifically covering the untitled-post excerpt behavior introduced for the Trac ticket referenced in this PR (65658), but the docblock still points to 65116.
	 * @ticket 65116

tests/phpunit/tests/admin/wpDashboardOnThisDay.php:379

  • This new test is specifically covering the untitled-post excerpt behavior introduced for the Trac ticket referenced in this PR (65658), but the docblock still points to 65116.
	 * @ticket 65116

tests/phpunit/tests/admin/wpDashboardOnThisDay.php:416

  • This new test is specifically covering the untitled-post excerpt behavior introduced for the Trac ticket referenced in this PR (65658), but the docblock still points to 65116.
	 * @ticket 65116

Comment thread tests/phpunit/tests/admin/wpDashboardOnThisDay.php
Copilot AI review requested due to automatic review settings July 27, 2026 22:33
@alshakero

Copy link
Copy Markdown
Author

Hi @peterwilsoncc! Can we have this merged? I think it's good to go.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/wp-admin/includes/dashboard-on-this-day.php:70

  • _wp_dashboard_on_this_day_get_no_title_excerpt() relies on the widget query to ensure the current user can read the post, but the query args are filterable (wp_dashboard_on_this_day_query_args). For parity with the established pattern in WP_Posts_List_Table::get_no_title_excerpt(), add an explicit read capability check here so excerpts can’t be exposed if the query is broadened.
	if ( '' !== get_the_title( $post )
		|| post_password_required( $post )
	) {
		return '';
	}

Comment thread src/wp-admin/includes/dashboard-on-this-day.php Outdated
Comment thread src/wp-admin/includes/dashboard-on-this-day.php Outdated
* @param WP_Post $post The current WP_Post object.
* @return string The trimmed excerpt, or an empty string.
*/
function _wp_dashboard_on_this_day_get_no_title_excerpt( $post ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it's worth exposing a few lines of code that will only be used once as a function. How about inlining it? In fact, there are no direct unit tests for the _wp_dashboard_on_this_day_get_no_title_excerpt function.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree here; I think this can just be inlined.

Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 30, 2026 19:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@joedolson joedolson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only outstanding issue here is about whether the logic can be inlined for generating post excerpts. In my opinion, it makes sense; it's just a few lines of code.

* @param WP_Post $post The current WP_Post object.
* @return string The trimmed excerpt, or an empty string.
*/
function _wp_dashboard_on_this_day_get_no_title_excerpt( $post ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree here; I think this can just be inlined.

@alshakero

Copy link
Copy Markdown
Author

@joedolson @t-hamano thanks for the reviews! Addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants