Add Simplified Summary block and shortcode for manual placement - #1837
Add Simplified Summary block and shortcode for manual placement#1837SteveJonesDev wants to merge 5 commits into
Conversation
Adds a dynamic edac/simplified-summary block (the plugin's first block) and an [edac_simplified_summary] shortcode so the simplified summary can be placed manually in post content or block theme (FSE) templates, instead of relying solely on the automatic the_content insertion. - Block resolves the post from the postId block context (FSE templates, Query Loop) with a global post fallback, and reuses Simplified_Summary::simplified_summary_markup() as the markup source of truth. Editor shows a static placeholder since the summary is authored in the plugin sidebar. - Shortcode accepts an optional post_id attribute. - Automatic insertion is suppressed when the block or shortcode is manually placed (post content or current block theme template), with the edac_filter_simplified_summary_is_manually_placed filter as an escape hatch for template parts and synced patterns. - Manual placement intentionally ignores the simplified summary prompt option, matching edac_get_simplified_summary(). Closes #1835 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds a dynamic Simplified Summary block, an optional shortcode, editor assets, rendering tests, and automatic-insertion suppression when the summary is manually placed in post content or block templates. ChangesSimplified Summary placement
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Editor
participant SimplifiedSummaryBlock
participant SimplifiedSummary
Editor->>SimplifiedSummaryBlock: Render block with postId context
SimplifiedSummaryBlock->>SimplifiedSummary: Generate markup for postId
SimplifiedSummary-->>Editor: Return summary markup
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a new Gutenberg block (edac/simplified-summary) and a shortcode ([edac_simplified_summary]) to allow manual placement of the simplified summary, which automatically suppresses its automatic insertion on post content. The feedback suggests making the $block parameter optional in the block's render callback to prevent potential PHP errors, and implementing tearDown() methods in the PHPUnit test classes to clean up global variables and maintain proper test isolation.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6422d2b3f9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
tests/jest/simplifiedSummaryBlock/index.test.js (1)
9-19: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winMock
@wordpress/i18nexplicitly in this suite.
Editimports__, but this test only mocks@wordpress/blocksand@wordpress/block-editor. Add an identity mock to avoid environment-dependent imports and translated-text assertions.Proposed fix
jest.mock( '`@wordpress/block-editor`', () => ( { useBlockProps: jest.fn( ( props ) => props ), } ), { virtual: true } ); +jest.mock( '`@wordpress/i18n`', () => ( { + __: ( text ) => text, +} ), { virtual: true } ); + import { registerBlockType } from '`@wordpress/blocks`';🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/jest/simplifiedSummaryBlock/index.test.js` around lines 9 - 19, Explicitly mock `@wordpress/i18n` in the simplified summary block test suite, providing an identity implementation for the __ translation function before importing Edit. Keep the existing `@wordpress/blocks` and `@wordpress/block-editor` mocks unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@includes/classes/Blocks/SimplifiedSummaryBlock.php`:
- Around line 114-123: Update SimplifiedSummaryBlock::render() to obtain wrapper
attributes with get_block_wrapper_attributes() and include them on an outer
element around the result of Simplified_Summary::simplified_summary_markup().
Preserve the existing post ID validation and shared summary markup unchanged,
while ensuring block spacing margin classes and styles reach the frontend.
In `@includes/classes/class-simplified-summary.php`:
- Around line 89-95: Update the automatic-placement detection in the simplified
summary flow to also call has_shortcode() against $_wp_current_template_content
for the edac_simplified_summary shortcode, alongside the existing has_block()
check. Add a regression test in SimplifiedSummaryTest covering shortcode content
inside a block template and confirming automatic insertion is suppressed.
In `@includes/classes/Shortcodes/SimplifiedSummaryShortcode.php`:
- Around line 52-67: Update SimplifiedSummaryShortcode::render to validate that
the resolved post_id is publicly viewable before calling
Simplified_Summary::simplified_summary_markup(). Return an empty string when the
post is private, draft, or otherwise not publicly accessible, while preserving
the existing behavior for valid public posts.
In `@src/simplifiedSummaryBlock/sass/simplified-summary-block.scss`:
- Line 4: Update the border declaration in the simplified summary block
stylesheet to use the lint-approved lowercase currentcolor spelling instead of
currentColor.
---
Nitpick comments:
In `@tests/jest/simplifiedSummaryBlock/index.test.js`:
- Around line 9-19: Explicitly mock `@wordpress/i18n` in the simplified summary
block test suite, providing an identity implementation for the __ translation
function before importing Edit. Keep the existing `@wordpress/blocks` and
`@wordpress/block-editor` mocks unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7ac509c7-777f-46c3-8f19-45ce081baf2c
📒 Files selected for processing (14)
includes/blocks/simplified-summary/block.jsonincludes/classes/Blocks/SimplifiedSummaryBlock.phpincludes/classes/Shortcodes/SimplifiedSummaryShortcode.phpincludes/classes/class-plugin.phpincludes/classes/class-simplified-summary.phpreadme.txtsrc/simplifiedSummaryBlock/edit.jssrc/simplifiedSummaryBlock/index.jssrc/simplifiedSummaryBlock/sass/simplified-summary-block.scsstests/jest/simplifiedSummaryBlock/index.test.jstests/phpunit/includes/classes/Blocks/SimplifiedSummaryBlockTest.phptests/phpunit/includes/classes/Shortcodes/SimplifiedSummaryShortcodeTest.phptests/phpunit/includes/classes/SimplifiedSummaryTest.phpwebpack.config.js
- Detect the [edac_simplified_summary] shortcode in block theme template content, not just the block, when suppressing automatic insertion. - Gate explicit shortcode post_id values on is_post_publicly_viewable() so summaries of draft/private posts cannot be exposed. - Output block wrapper attributes in the render callback so the supports.spacing.margin styles reach the front end, with a guard for direct calls outside an active block render. - Make the render callback's $block parameter optional with an instanceof check. - Use lint-approved lowercase currentcolor in the editor stylesheet. - Reset the block template global in tearDown and add regression tests for the template shortcode and non-public post cases. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Localizes the heading with edac_filter_simplified_summary_heading applied to the editor script, so a custom heading (a pro setting) previews in the block exactly as it renders on the front end. Falls back to the default translated heading when the localized value is unavailable. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Moves the simplified summary block from the generic widgets category into a custom Accessibility Checker category, matching how our other products group their blocks and giving future blocks a shared home. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The simplified summary can be written in the editor sidebar or the Accessibility Checker meta box Readability tab, so the placeholder now points to both instead of only the sidebar. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
✅ Accessibility Checker build (primary only)
|
|
|
||
| $explicit_post_id = absint( $atts['post_id'] ); | ||
|
|
||
| if ( $explicit_post_id && ! is_post_publicly_viewable( $explicit_post_id ) ) { |
There was a problem hiding this comment.
is_post_publicly_viewable() does not account for a published post being password protected, so an explicit post_id can pass this check and simplified_summary_markup() will read its summary meta directly without requiring the password. WordPress core’s post-meta block binding handles this separately with post_password_required(). Could we add that guard here and cover a password-protected published post in the shortcode tests?
Summary
Adds a dynamic
edac/simplified-summaryblock (the plugin's first block) and an[edac_simplified_summary]shortcode so users can place the simplified summary manually in post content or in a block theme (FSE) template, instead of relying solely on the automaticthe_contentinsertion.Closes #1835 (Linear: PRO-1226). This completes the block half originally suggested in #124.
Implementation
includes/classes/Blocks/SimplifiedSummaryBlock.php+includes/blocks/simplified-summary/block.json): dynamic block with a PHP render callback. Resolves the post from thepostIdblock context (FSE templates, Query Loop) with aget_the_ID()fallback, and reusesSimplified_Summary::simplified_summary_markup()as the single markup source. Because the custom webpack build doesn't generate*.asset.phpfiles, the editor script is pre-registered with an explicit dependency list andblock.jsonreferences the handle string.includes/classes/Shortcodes/SimplifiedSummaryShortcode.php): optionalpost_idattribute, falls back to the current post.Simplified_Summary::is_manually_placed()skips the automatic insertion when the block/shortcode is in the post content or the block is in the current block theme template ($_wp_current_template_content), preventing duplicate output. Newedac_filter_simplified_summary_is_manually_placedfilter is the escape hatch for template parts / synced patterns, whichhas_block()cannot resolve.edac_simplified_summary_promptoption (matchingedac_get_simplified_summary()); empty summary meta renders nothing.simplifiedSummaryBlockentry; added@wordpress/blocksto externals.Testing
do_blocks()end-to-end; prompt=none still renders; empty meta → empty string). Full suite: 890 tests passing.Summary by CodeRabbit
[edac_simplified_summary]shortcode with optionalpost_idsupport.