Skip to content

Conversation

@sidharthpandita1
Copy link
Contributor

@sidharthpandita1 sidharthpandita1 commented Oct 24, 2025

What?

Closes #72348

Replaces the "Display excerpt" toggle with a "Display content" dropdown in the Latest Comments block, providing three options: No content, Excerpt, and Full content.

Why?

The Latest Comments block currently only offers a binary choice (show excerpt or hide it). This limits flexibility for users who want to display the full comment text or hide comment content entirely while still showing author information and metadata. This enhancement provides more granular control over comment display.

How?

  • Updated block.json to replace the displayExcerpt boolean attribute with a new displayContent string attribute (enum: "none", "excerpt", "full")
  • Modified edit.js to replace the ToggleControl with a SelectControl dropdown offering three options
  • Added deprecated.js with migration logic to automatically convert blocks using the old displayExcerpt boolean to the new displayContent string format
  • Updated index.php rendering logic to:
    • Handle backward compatibility by checking for the legacy displayExcerpt attribute first
    • Call get_comment_text() when "Full content" is selected
    • Call get_comment_excerpt() when "Excerpt" is selected
    • Display no content when "None" is selected
  • Updated CSS class logic to apply has-excerpts class when content is displayed
  • Added test fixtures (core__latest-comments__deprecated-v1.*) to verify migration works correctly

Testing Instructions

  1. Open a post or page in the block editor
  2. Insert a Latest Comments block
  3. Open the block settings panel on the right sidebar
  4. Locate the "Display content" dropdown (previously "Display excerpt" toggle)
  5. Test each option:
    • Select "No content" - verify only comment author, post title, and date (if enabled) are shown
    • Select "Excerpt" - verify comment excerpts are displayed (default behavior)
    • Select "Full content" - verify full comment text is displayed
  6. Save and view on the frontend to ensure all three options render correctly
  7. Test with comments of varying lengths to ensure full content doesn't break the layout

Backward Compatibility Testing

  1. Test deprecated attribute migration:
    • Switch to Code Editor view
    • Manually insert an old-format block: <!-- wp:latest-comments {"displayExcerpt":false} /-->
    • Switch back to Visual Editor
    • Verify the dropdown shows "No content" selected
    • View on frontend - should display no content (only author/date/post title)
    • Make any edit to the block (e.g., toggle display avatar)
    • Switch back to Code Editor
    • Verify the block now uses "displayContent":"none" instead of "displayExcerpt":false
  2. Repeat step 8 with {"displayExcerpt":true} and verify it migrates to "displayContent":"excerpt"

Testing Instructions for Keyboard

  1. Open a post or page in the block editor
  2. Insert a Latest Comments block using the inserter (press / then type "latest comments")
  3. Press Tab to navigate to the block toolbar, then continue tabbing to reach the settings sidebar
  4. Use Tab to navigate to the "Display content" dropdown
  5. Press Space or Enter to open the dropdown
  6. Use Arrow Up/Down keys to navigate through the three options
  7. Press Enter to select an option
  8. Verify the block preview updates accordingly
  9. Use Tab to navigate to other settings and ensure keyboard navigation works smoothly throughout

Screenshots or screencast

Screen.Recording.2025-10-21.at.1.08.29.AM.mov

Additional Notes

  • The default value is "Excerpt" to maintain existing behavior
  • The CSS class has-excerpts is applied when content is displayed (excerpt or full)
  • Full comment content uses get_comment_text() as suggested in the original issue
  • All comment content is wrapped in wpautop() for proper paragraph formatting
  • Backward compatibility: Blocks with the old displayExcerpt attribute are automatically migrated via deprecation logic when edited, and render correctly on the frontend via PHP fallback logic
  • Migration is triggered by isEligible() check that only runs when the legacy displayExcerpt attribute exists
  • Test fixtures ensure the migration from displayExcerpt: falsedisplayContent: "none" and displayExcerpt: truedisplayContent: "excerpt" works correctly

@github-actions
Copy link

github-actions bot commented Oct 24, 2025

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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: sidharthpandita1 <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: Copons <[email protected]>

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

… validation

Adds new test fixtures for the core/latest-comments block to verify the deprecated v1 migration path.
Includes:
- core__latest-comments__deprecated-v1.html
- core__latest-comments__deprecated-v1.json
- core__latest-comments__deprecated-v1.serialized.html

These fixtures ensure correct migration from legacy 'displayExcerpt' to the new 'displayContent' attribute.
@sidharthpandita1
Copy link
Contributor Author

Adds new test fixtures for the core/latest-comments block to verify the deprecated v1 migration path.
Includes:

  • core__latest-comments__deprecated-v1.html
  • core__latest-comments__deprecated-v1.json
  • core__latest-comments__deprecated-v1.serialized.html @t-hamano

@t-hamano
Copy link
Contributor

@sidharthpandita1
Copy link
Contributor Author

@sidharthpandita1 This PR contains a lot of changes. See the file diff: https://github.com/WordPress/gutenberg/pull/72665/files

I didn’t make significant modifications to these files — the large diff is likely due to some whitespace or indentation differences introduced during copy–paste.

@t-hamano
Copy link
Contributor

I didn’t make significant modifications to these files — the large diff is likely due to some whitespace or indentation differences introduced during copy–paste.

Regardless of the cause, as the CI failures indicate, these changes are unacceptable. Could you revert the unnecessary changes?

@sidharthpandita1
Copy link
Contributor Author

I didn’t make significant modifications to these files — the large diff is likely due to some whitespace or indentation differences introduced during copy–paste.

Regardless of the cause, as the CI failures indicate, these changes are unacceptable. Could you revert the unnecessary changes?

Absolutely !!

@sidharthpandita1
Copy link
Contributor Author

@t-hamano removed the extra spacing/indentation of block.json, should i continue the same for the rest?

@t-hamano
Copy link
Contributor

@sidharthpandita1 Yes. It would also be a good idea to correctly update the PR title and description.

@sidharthpandita1 sidharthpandita1 changed the title Changes made Add option to display full comments/v-2 Oct 25, 2025
@sidharthpandita1
Copy link
Contributor Author

@t-hamano changes made accordingly !

@t-hamano
Copy link
Contributor

@sidharthpandita1 There are still a lot of unnecessary changes. Most of them are because the indentation is done with spaces instead of tabs. Can you run the following commands?

  • Format JS files: npm run format packages/block-library/src/latest-comments/block.json packages/block-library/src/latest-comments/deprecated.js
  • Format PHP file: npm run format:php
  • Generate the fixture file correctly: npm run fixtures:regenerate

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Block] Latest Comments Affects the Latest Comments Block labels Oct 25, 2025
@sidharthpandita1
Copy link
Contributor Author

commands ran successfully @t-hamano

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

Thanks for the update! I think we're almost finished 🙏 Finally, could you run npm run fixtures:regenerate one more time?

@sidharthpandita1
Copy link
Contributor Author

Thanks for the update! I think we're almost finished 🙏 Finally, could you run npm run fixtures:regenerate one more time?

command ran successfully !

@t-hamano t-hamano changed the title Add option to display full comments/v-2 Latest Comments: Add option to display full comments Oct 27, 2025
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

LGTM! Finally, could you run npm run docs:build? This should ensure that all CI jobs succeed.

@sidharthpandita1
Copy link
Contributor Author

npm run docs:build

Done !

@t-hamano t-hamano merged commit 703897a into WordPress:trunk Oct 27, 2025
34 checks passed
@github-actions github-actions bot added this to the Gutenberg 22.0 milestone Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Latest Comments Affects the Latest Comments Block [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Latest Comments Block: Add option to display full comments

2 participants