Skip to content

Add register_core_block_extension method#79

Merged
kadamwhite merged 7 commits intov1from
add-register_core_block_extension-method
Feb 23, 2026
Merged

Add register_core_block_extension method#79
kadamwhite merged 7 commits intov1from
add-register_core_block_extension-method

Conversation

@kadamwhite
Copy link
Copy Markdown
Collaborator

@kadamwhite kadamwhite commented Feb 20, 2026

This implements the concept behind a piece of wp-scripts-asset-loader without being as prescriptive about file organization as that plugin.

If you pass a block.json specifying a name handle (e.g. core/paragraph) and one or more script or style references, like "style": "file:./style.css" to the new register_core_block_extension method, it will merge this into the core paragraph's dependencies and enqueue that style on output.

Open question: I left the "core" in the name of the function because that's the main use-case, but it doesn't seem limited to that. Should we just call it register_block_extension?

@kadamwhite
Copy link
Copy Markdown
Collaborator Author

kadamwhite commented Feb 20, 2026

@roborourke if you have bandwidth to give an opinion here on Monday, I like the ideas you've got in wp-scripts-asset-loader but really dislike how prescriptive it is about file organization, because it would make it much more complex to integrate into existing codebases. This PR attempts to take the core of your idea and make it more broadly applicable to the sorts of projects our squad is tackling right now.

@roborourke
Copy link
Copy Markdown

Yeah I think drop “core” from the function name. I use it for other blocks too.

Cleaner than what I’ve done and I like the opt in encapsulation, easy to write a helper to apply it to the file structure my plugin prescribes.

Good to see the idea is a goer though, will be happy to consolidate back on this plugin :)

Per PR review, if it works for all blocks, the core_ prefix is unneeded and could be misleading
… array

If we call this one at a time, we can immediately try to apply the override
when called if wp_loaded has run

It's also conceptually simpler to have all the methods work on the level
of a single block rather than an array, and the impact of N hook callbacks
for N custom block overrides is minimal
This MOST-reliably works on Init, still, but depending on usage, after the prior
change to run the overrides one blocok at a time, it is now possible to call this
up until enqueue_block_assets and still get the desired behavior.
@kadamwhite
Copy link
Copy Markdown
Collaborator Author

@goldenapples @roborourke Haven't gone back in to add unit tests yet (and may not have bandwidth today), but this is tested in my local project and ready for review.

Main remaining open question: how to handle the hook priority. It works most-reliably on init (when core registers its blocks), but can technically be run any time before core processes and outputs its own block scripts, with some recent changes I've pushed. Should we doing_it_wrong if called before wp_loaded? is waiting for wp_loaded necessary? Looking for opinions on the order of operations

@kadamwhite kadamwhite merged commit cd0f86a into v1 Feb 23, 2026
1 check passed
@kadamwhite kadamwhite deleted the add-register_core_block_extension-method branch February 23, 2026 15:00
@kadamwhite
Copy link
Copy Markdown
Collaborator Author

@roborourke @goldenapples Made a mistake with branches, recreated this here #80

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.

2 participants