Administration: Show excerpts for untitled On This Day posts - #12581
Administration: Show excerpts for untitled On This Day posts#12581alshakero wants to merge 17 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 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. Ifwp_dashboard_on_this_day_query_argsis 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 checkingcurrent_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 '';
|
Addressed all! |
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 (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() {
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 (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
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. |
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