close
Skip to content

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

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

Administration: Show excerpts for untitled On This Day posts#12581
alshakero wants to merge 19 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, annezazu.

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 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.

@t-hamano t-hamano 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.

Thanks for the update! It would be great if we could also add the following two tests to verify that the logic added this time works correctly.

  • test_widget_hides_untitled_post_excerpt_for_unreadable_posts: Ensures the excerpt is not shown for an untitled post the current user cannot read, covering the current_user_can( 'read_post' ) guard.
  • test_widget_does_not_append_excerpt_to_titled_posts: Ensures a post that has a title renders only its title, so the excerpt stays limited to untitled posts.

Comment thread tests/phpunit/tests/admin/wpDashboardOnThisDay.php
Comment thread src/wp-admin/includes/dashboard-on-this-day.php Outdated
@annezazu

annezazu commented Aug 1, 2026

Copy link
Copy Markdown

Thanks so much for jumping right on this. I just managed to test this today and opened a trac issue prematurely only to find you all are all over it. It's looking great to me, UI wise.

@alshakero

Copy link
Copy Markdown
Author

Hi @t-hamano! Addressed. Thank you so much for the review.

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.

Suppressed comments (3)

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

  • For consistency with the rest of this test class (which uses parameter/return type hints), this filter callback should type-hint $args as array and declare an array return type.
	public function filter_on_this_day_query_private_posts( $args ) {
		$args['post_status'] = array( 'private' );

		return $args;
	}

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

  • The excerpt is appended by echoing on a new line without an explicit separator, which relies on template whitespace and also introduces extra whitespace inside the link text even when no excerpt is shown. Build the full link text with an explicit leading space only when $no_title_excerpt is non-empty and output it in a single echo to keep the markup stable.
								<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 );

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

  • This test asserts the custom excerpt isn't shown for password-protected posts, but get_the_excerpt() ignores post_excerpt and returns the generic protected-post message when a password is set. As a result, the test could pass even if the widget mistakenly appends the protected excerpt message; assert that the protected-post message is also absent.
		ob_start();
		wp_dashboard_on_this_day();
		$output = ob_get_clean();

		$this->assertStringNotContainsString( 'Private anniversary memory.', $output );

pento pushed a commit that referenced this pull request Aug 2, 2026
Match the behavior of posts in list tables by showing a short excerpt in the On This Day widget when the post does not have a saved title.

Developed in #12581

Props alshakero, softglaze, iamraju, mirmpro, shailu25, bph, nazmulasif, wildworks, annezazu, mukesh27, peterwilsoncc, joedolson.
Fixes #65658.

git-svn-id: https://develop.svn.wordpress.org/trunk@62968 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 62968
GitHub commit: d1c6be6

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Aug 2, 2026
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Aug 2, 2026
Match the behavior of posts in list tables by showing a short excerpt in the On This Day widget when the post does not have a saved title.

Developed in WordPress/wordpress-develop#12581

Props alshakero, softglaze, iamraju, mirmpro, shailu25, bph, nazmulasif, wildworks, annezazu, mukesh27, peterwilsoncc, joedolson.
Fixes #65658.
Built from https://develop.svn.wordpress.org/trunk@62968


git-svn-id: http://core.svn.wordpress.org/trunk@62209 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.

8 participants