Administration: Show excerpts for untitled On This Day posts - #12581
Administration: Show excerpts for untitled On This Day posts#12581alshakero wants to merge 19 commits into
Conversation
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
7ce530a to
29a796a
Compare
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Thank you @alshakero for jumping right on it! |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 '';
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
This looks good and is testing well.
I've put a couple of very minor comments inline.
There was a problem hiding this comment.
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()withouttrim(), 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 '';
}
There was a problem hiding this comment.
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 checksget_the_title()without trimming, so whitespace-only titles will skip the excerpt. Also, unlike the posts list table’sget_no_title_excerpt(), this doesn’t verifycurrent_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
|
Hi @peterwilsoncc! Can we have this merged? I think it's good to go. |
There was a problem hiding this comment.
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 '';
}
| * @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 ) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I agree here; I think this can just be inlined.
Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com>
joedolson
left a comment
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
I agree here; I think this can just be inlined.
|
@joedolson @t-hamano thanks for the reviews! Addressed. |
t-hamano
left a comment
There was a problem hiding this comment.
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 thecurrent_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.
|
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. |
|
Hi @t-hamano! Addressed. Thank you so much for the review. |
There was a problem hiding this comment.
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
$argsasarrayand declare anarrayreturn 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_excerptis non-empty and output it in a singleechoto 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()ignorespost_excerptand 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 );
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
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

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
(no title) 15 word excerpt.Screenshots
Before
After