Skip to content

Preserve block custom CSS class in published credits output - #9

Merged
jashjacob merged 1 commit into
masterfrom
fix/preserve-block-custom-css-class
Sep 29, 2026
Merged

jashjacob merged 1 commit into
masterfrom
fix/preserve-block-custom-css-class

Conversation

@jashjacob

Copy link
Copy Markdown
Owner

Summary

  • Fixes IMPROVEMENT_PLAN.md item 1 bullet 3: a custom CSS class added to the Credits Link block via the editor's Advanced panel was dropped from the front-end/published output, even though the editor preview showed it correctly (via useBlockProps()).
  • credits_render_block() now derives the block wrapper's extra class through get_block_wrapper_attributes() (WP 5.6+), falling back to the raw className attribute on older WordPress, and merges it into the rendered <ul> class list.
  • Plain [credits] shortcode calls never receive this wrapper class, so shortcode rendering stays independent of any block context, as the plan requires.
  • No HTML allowlist changes were needed — ul.class was already permitted; only additional class tokens are appended, never new attributes.
  • Reviewed the rest of item 1: the API-version PHP/JS mismatch bug (bullets 1–2) was already fixed in 1.6.0 (hardcoded apiVersion: 3 on both sides, no localized comparison, covered by an existing regression test) — noted in IMPROVEMENT_PLAN.md rather than re-doing it. One plan/implementation mismatch is flagged there too: the plan asked to retain the legacy Block API v1 fallback, but 1.6.0 removed it outright instead — left as a flagged note since that's a product decision, not a bug.
  • Bumped the version to 1.6.1 and updated changelogs (readme.txt, README.md).

Test plan

  • vendor/bin/phpunit — 50 tests, 178 assertions, all passing (was 44/167 before this change)
  • New tests cover: custom class preserved, default class not duplicated, multiple classes merged, hostile/XSS class input sanitized, shortcode output unaffected by any block wrapper state, and block vs. shortcode output parity when no custom class is set
  • Manual check in a live WordPress editor (not done in this session — flagged as still needed per the plan's own note that a live editor/theme check is outstanding)

🤖 Generated with Claude Code

The Credits Link block dropped any custom CSS class added via the
editor's Advanced panel from the front-end output, since the render
callback passed attributes straight to the shared renderer without
reading className or using get_block_wrapper_attributes(). The editor
preview already showed the class via useBlockProps(), so saved and
published output diverged.

credits_render_block() now derives the wrapper's extra class via
get_block_wrapper_attributes() (WP 5.6+) with a className fallback for
older WordPress, and passes it through a new optional parameter that
plain shortcode calls never populate, keeping shortcode output
independent of any block wrapper context.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jashjacob
jashjacob merged commit 37253df into master Sep 29, 2026
13 checks passed
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.

1 participant