fix(166): expose SCF fields as inline-token (Bits) source for RichText#519
Open
faisalahammad wants to merge 1 commit into
Open
fix(166): expose SCF fields as inline-token (Bits) source for RichText#519faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
Expose SCF fields as a source for inline tokens (Bits) that can be inserted mid-string inside paragraph, heading, and list-item blocks. - New includes/Bits/Registry.php singleton with built-in scf/field source; register()/unregister() and an scf/bits/register action hook for third-party bits. - New includes/Bits/Walker.php render_block filter (priority 100) resolves persisted span shapes via get_field() and replaces inner HTML; Tag Processor path with regex fallback for older WP. - New includes/Bits/Editor.php enqueues the RTE picker script for WP 6.5+ and localizes the field list via window.scfFieldBits. - New assets/src/js/bits/ entry adds an SCF field button to the BlockControls of paragraph/heading/list-item with a picker modal. - PHPUnit tests for Registry (7) and Walker (8). Fixes WordPress#166
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @[email protected]. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an
scf/fieldinline-token ("Bit") source so SCF field values can be inserted mid-string inside paragraph, heading, and list-item blocks. Bits are persisted as<span class="scf-field-bit" data-bit="...">fallback</span>and resolved at render time via arender_blockfilter (priority 100) usingget_field(). Compatible with existingacf/fieldblock bindings (different namespace, different layer).Designed around the only stable community API for Bits today (PRC
prc-block-bit). When WP/Gutenberg lands core Bits, the walker is a single-class regex-tractable filter; migration path is detection in the same filter.Closes #166
What's in this PR
PHP (new):
includes/Bits/Registry.php— singleton registry. Auto-registersscf/fieldwith attribute schema (key,target,fallback,format: text|html). Publicregister()/unregister(); firesscf/bits/registeraction atinitpriority 11 for third-party bits.includes/Bits/Walker.php—render_blockfilter. Early-exits if noscf-field-bitpresent; uses Tag Processor with a regex fallback for older WP. Text format ->esc_html; HTML ->wp_kses_post; empty/missing -> fallback. Deactivated SCF -> fallback visible.includes/Bits/Editor.php— enqueues editor script on WP 6.5+; localizes field list viawindow.scfFieldBits.JS (new):
assets/src/js/bits/index.jsandtoolbar.js— toolbar button on paragraph/heading/list-item via BlockControls, picker modal, persists the span shape.Bootstrap + wiring (modified):
secure-custom-fields.php— instantiates Walker and Editor; boots Registry oninitpriority 11.includes/assets.php— registersscf-field-bitsscript.composer.json— PSR-4 mapping forSCF\Bits\.webpack.config.js— addsjs/scf-field-bitsentry.Tests:
tests/php/includes/bits/Test_Bits_Registry.php— 7 tests (defaults, idempotent boot, validation, register/unregister, filtering).tests/php/includes/bits/Test_Bits_Walker.php— 8 tests (early exit, substitution, fallback, html kses, raw cap, script strip).How to test
scf-bits-166.zip(branch commit also fine viacomposer install && npm run build).forecast_today/text/ fallback "sunny"; Insert.Full 6-scenario manual pass is in
TESTING_INSTRUCTIONS.md(untracked).Verification
includes/Bits/andtests/php/includes/bits/.scf-field-bitsbundle without errors.Use of AI Tools
Used standard editor tooling to read documentation, draft commit messages, and structure the PR — final code was reviewed and tested manually. The repository maintainers and reviewing engineers should consider this PR's contents as written by a human contributor.