Skip to content

Add Simplified Summary block and shortcode for manual placement - #1837

Open
SteveJonesDev wants to merge 5 commits into
developfrom
steve/pro-1226-block-to-insert-the-simplified-summary-manually-in-the-block
Open

Add Simplified Summary block and shortcode for manual placement#1837
SteveJonesDev wants to merge 5 commits into
developfrom
steve/pro-1226-block-to-insert-the-simplified-summary-manually-in-the-block

Conversation

@SteveJonesDev

@SteveJonesDev SteveJonesDev commented Jul 15, 2026

Copy link
Copy Markdown
Member

Summary

Adds a dynamic edac/simplified-summary block (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 automatic the_content insertion.

Screenshot 2026-07-15 at 1 07 23 AM Screenshot 2026-07-15 at 1 07 29 AM Screenshot 2026-07-15 at 1 13 24 AM

Closes #1835 (Linear: PRO-1226). This completes the block half originally suggested in #124.

Implementation

  • Block (includes/classes/Blocks/SimplifiedSummaryBlock.php + includes/blocks/simplified-summary/block.json): dynamic block with a PHP render callback. Resolves the post from the postId block context (FSE templates, Query Loop) with a get_the_ID() fallback, and reuses Simplified_Summary::simplified_summary_markup() as the single markup source. Because the custom webpack build doesn't generate *.asset.php files, the editor script is pre-registered with an explicit dependency list and block.json references the handle string.
  • Editor view: static placeholder mirroring the frontend markup shape — the summary is authored in the Accessibility Checker sidebar, so the block acts as a position marker. Never renders invisibly when the summary is empty.
  • Shortcode (includes/classes/Shortcodes/SimplifiedSummaryShortcode.php): optional post_id attribute, falls back to the current post.
  • Auto-insert suppression: 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. New edac_filter_simplified_summary_is_manually_placed filter is the escape hatch for template parts / synced patterns, which has_block() cannot resolve.
  • Semantics: manual placement intentionally ignores the edac_simplified_summary_prompt option (matching edac_get_simplified_summary()); empty summary meta renders nothing.
  • Webpack: new simplifiedSummaryBlock entry; added @wordpress/blocks to externals.

Testing

  • PHPUnit: 13 new tests (suppression via block/shortcode/template/filter; render via context, global-post fallback, do_blocks() end-to-end; prompt=none still renders; empty meta → empty string). Full suite: 890 tests passing.
  • Jest: 4 new tests (registration, dynamic save, Edit output). Full suite: 952 tests passing.
  • PHPCS, ESLint, and PHP syntax lint clean.

Summary by CodeRabbit

  • New Features
    • Added an “Simplified Summary” Gutenberg block with an editor placeholder and dynamic front-end rendering.
    • Added the [edac_simplified_summary] shortcode with optional post_id support.
  • Bug Fixes
    • Automatic Simplified Summaries no longer appear when the summary is manually placed via the block or shortcode in post content or templates.
  • Documentation
    • Updated setup guidance to describe placement options and how manual placement disables auto-insertion.
  • Tests
    • Added and expanded unit/integration tests for block, shortcode, and manual-placement behavior.

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>
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

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

Changes

Simplified Summary placement

Layer / File(s) Summary
Block and shortcode rendering
includes/blocks/simplified-summary/block.json, includes/classes/Blocks/..., includes/classes/Shortcodes/..., includes/classes/class-plugin.php, tests/phpunit/includes/classes/Blocks/..., tests/phpunit/includes/classes/Shortcodes/...
Registers the dynamic block and shortcode, resolves target posts from context, attributes, or the current post, renders saved summary markup, and validates these paths.
Manual-placement suppression
includes/classes/class-simplified-summary.php, tests/phpunit/includes/classes/SimplifiedSummaryTest.php, readme.txt
Detects manually placed blocks and shortcodes in post or template content, applies the placement filter, suppresses automatic insertion, and documents the behavior.
Block editor bundle and UI
src/simplifiedSummaryBlock/*, tests/jest/simplifiedSummaryBlock/*, webpack.config.js
Adds the editor placeholder, dynamic block registration, SCSS styling, webpack entry, external WordPress blocks dependency, and Jest coverage.

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
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR satisfies #1835 by adding a manual-placement block for posts/FSE templates and an optional shortcode.
Out of Scope Changes check ✅ Passed All changes support the block/shortcode feature, including editor assets, tests, docs, and build config.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding a Simplified Summary block and shortcode for manual placement.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch steve/pro-1226-block-to-insert-the-simplified-summary-manually-in-the-block

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot 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.

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.

Comment thread includes/classes/Blocks/SimplifiedSummaryBlock.php Outdated
Comment thread tests/phpunit/includes/classes/SimplifiedSummaryTest.php

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

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

Comment thread includes/classes/class-simplified-summary.php Outdated
Comment thread includes/classes/Shortcodes/SimplifiedSummaryShortcode.php Outdated

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 4

🧹 Nitpick comments (1)
tests/jest/simplifiedSummaryBlock/index.test.js (1)

9-19: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Mock @wordpress/i18n explicitly in this suite.

Edit imports __, but this test only mocks @wordpress/blocks and @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

📥 Commits

Reviewing files that changed from the base of the PR and between 4a9100f and 6422d2b.

📒 Files selected for processing (14)
  • includes/blocks/simplified-summary/block.json
  • includes/classes/Blocks/SimplifiedSummaryBlock.php
  • includes/classes/Shortcodes/SimplifiedSummaryShortcode.php
  • includes/classes/class-plugin.php
  • includes/classes/class-simplified-summary.php
  • readme.txt
  • src/simplifiedSummaryBlock/edit.js
  • src/simplifiedSummaryBlock/index.js
  • src/simplifiedSummaryBlock/sass/simplified-summary-block.scss
  • tests/jest/simplifiedSummaryBlock/index.test.js
  • tests/phpunit/includes/classes/Blocks/SimplifiedSummaryBlockTest.php
  • tests/phpunit/includes/classes/Shortcodes/SimplifiedSummaryShortcodeTest.php
  • tests/phpunit/includes/classes/SimplifiedSummaryTest.php
  • webpack.config.js

Comment thread includes/classes/Blocks/SimplifiedSummaryBlock.php Outdated
Comment thread includes/classes/class-simplified-summary.php
Comment thread includes/classes/Shortcodes/SimplifiedSummaryShortcode.php
Comment thread src/simplifiedSummaryBlock/sass/simplified-summary-block.scss Outdated
- 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>
SteveJonesDev and others added 3 commits July 15, 2026 00:31
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>
@github-actions

Copy link
Copy Markdown
Contributor

✅ Accessibility Checker build (primary only)


$explicit_post_id = absint( $atts['post_id'] );

if ( $explicit_post_id && ! is_post_publicly_viewable( $explicit_post_id ) ) {

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.

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?

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.

Block to insert the simplified summary manually in the block editor or an FSE template

2 participants