Repository navigation
Add scripts and styles as a capability the plugin orchestrates - #177
Merged
Merged
Conversation
This was referenced Oct 24, 2026
Keep a supplied injector's configuration: the asset location and the debug mode the asset loading checks are template methods now, not injector defaults. Guard against an enqueue action fired inside one, validate handles and paths against what WordPress and browsers do with them, compare script registrations by what they mean, check dynamic declaration calls and a forwarder's own names, keep the value-object allowance to subsystems, and load the sample script once the notice is there on WordPress before 6.3.
The asset declarations moved the sample services' methods down, so the citations of them in the patterns and principles are updated to where the same code is now.
schlessera
force-pushed
the
feat/37-asset-capability
branch
from
October 24, 2026 00:23
c72bf64 to
be421b6
Compare
schlessera
added a commit
to mwpd/content-freshness
that referenced
this pull request
Oct 24, 2026
Follows mwpd/basic-scaffold@c72bf64 (mwpd/basic-scaffold#177): the plugin no longer delegates AssetLocation and DebugMode in the injector but asks the template methods get_asset_location() and get_debug_mode(), an enqueue action fired from inside get_assets() is only remembered, handles are AssetHandle values that reject what WordPress cannot print, equivalent script registrations compare equal, and the prefix rule sees dynamic receivers. The composition root overrides get_debug_mode() to return the DebugMode its services are bound to, so one rebinding covers the notice and the plugin's asset boundary alike. Refs #2
4 tasks done
schlessera
added a commit
to mwpd/content-freshness
that referenced
this pull request
Oct 24, 2026
The notice now has a default style, loaded in the head only on outdated singular posts through the asset capability ported from mwpd/basic-scaffold#177. Refs #2.
This was referenced Oct 24, 2026
Open
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.
Refs #37
What changed
A service can now declare the scripts and styles it needs by implementing
HasAssets. It returns immutableStyleandScriptdeclarations fromget_assets( AssetContext ), and the plugin orchestrates the rest. If any declared service has assets, the plugin hookswp_enqueue_scripts,admin_enqueue_scripts(keeping$hook_suffix),enqueue_block_editor_assetsandlogin_enqueue_scripts, once each. At each of those actions it asks every registeredHasAssetsservice and hands the result to anAssetsloader (WordPressAssetsby default; it is a trailing optional constructor parameter).How the pieces behave:
get_asset_location(). By default that is the main file's directory URL plus itsVersionheader. No constant is read, and a missing header is anInvalidAsset.Delayedhandles an action that has passed.The two samples now use it:
SampleLoopServicedeclares a stylesheet for its post header on the front end. The service only exists on singular views.SampleBackendServicedeclares a deferred "Copy the plugin name" script for admin screens only.The architecture rules learn the new capability:
prefixedNameschecks the handle where it is declared (Style::file(),Style::inline(),Script::file(), including dynamic receivers).WordPressAssetsis listed as a forwarder.capabilitiesOnServicesacceptsDelayed+HasAssetsas having work to run.dependencyDirectionlets a subsystem name the infrastructure's value objects, but not a top-level class.Why this shape
The design is the ruled proposal on #37, built on
navnorth/museable'sAsset/Style/Script, minus its defects: global constants, build-path rewriting, hardcoded versions, per-service enqueue hooks, and render-time enqueueing, which leaves content unstyled until the footer.Two places deviate from the proposal text, both because review found real bugs:
get_asset_location(),get_debug_mode()), not default injector delegations. A default delegation silently replaced aDebugModedelegation configured on an injector passed into the constructor, for every plugin, with or without assets. Template methods sit next toget_main_file()and leave the injector alone.1, an empty strategy, and thewp-i18ndependency thatwp_set_script_translations()adds all count as equal.A second, independent review ran on the branch. Its findings are fixed in the third commit:
%2e%2eand control characters in paths;?and whitespace in handles;Errorand priority-order tests.Proof
Checklist
composer testandcomposer lintpass locally, and CI is green on the current head.breakingand a ruling.Anything left open
HasAssets,add_asset_service(), patterns.md), but not tested. That needs WordPress's real print pipeline, which the Brain Monkey suites don't have. HenceRefs, notCloses.