Repository navigation
Read icon sets from a directory outside the plugin first - #210
Open
Contributolo wants to merge 1 commit into
Open
Contributolo wants to merge 1 commit into
Contributolo wants to merge 1 commit into
Conversation
The icon picker and bs_render_icon() share one lookup: a set stored in wp-content/blockstudio/icons wins, the bundled set is the fallback. Activation and updates copy the bundled sets there, so a later release can stop shipping them without existing sites losing an icon. The blockstudio/icons/dir filter moves the directory, and an empty string keeps the sets in the plugin only.
This branch has not been deployed
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 #8. This is "release A" from my last comment there: the step that changes nothing visible and makes it possible to drop the 44 icon sets from the ZIP later (13.4 MB to about 7.6 MB) without an existing site losing an icon.
What changes
Blockstudio\Iconsclass with one lookup for both readers.Rest::icons()andbs_render_icon()each built the path toincludes/iconsthemselves. Both now callIcons::set_path(), which looks inwp-content/blockstudio/iconsfirst and in the plugin folder second. Name validation is stillUtils::icon_set_path(), for both directories.MigratecallsIcons::store_bundled_sets(). It copies the bundled sets to that directory, skips sets that are already stored with the same content, and writes each file aside before swapping it in, so a reader never sees half a set. It is not tied to a version key, so it runs for whichever release this lands in.blockstudio/icons/dir. It moves the directory, and an empty string stores nothing and keeps reading from the plugin folder only.Nothing is removed. A site where the copy fails (read-only
wp-content, for example) keeps working from the bundled sets exactly as today. The stored value{set, subSet, icon}, the REST route and the picker are unchanged, and there is no network request.Cost
The copy takes about 22 MB of disk in
wp-contentand runs once per update in the request that triggers the migration. Later runs only hash the files. A site that uses no icon fields can opt out withadd_filter('blockstudio/icons/dir', '__return_empty_string');.What a follow-up would do
Not part of this PR, and only if you want to go that way: stop shipping
includes/icons, publish the sets as release assets, and fetch a missing set into the same directory when it is first picked. The lookup added here already resolves a set that exists only in the stored directory (covered by a test), so that step would not touch rendering again.Tests
tests/unit/icons/IconStoreTest.php: fallback to the bundled set, full copy with identical content and no leftover temporary files, repeated runs writing only missing or changed sets, stored set winning forbs_icon()and the REST route, a set that is only stored, traversal out of the stored directory, the empty-directory opt-out, and the copy on update and on first activation.Run locally in WordPress Playground:
tests/unit/icons(66 tests),tests/unit/migrate(40) andtests/unit/rest(25) pass. PHPCS and PHPStan are clean on the changed files,npm run docs:checkpasses. I did not run the full suites, E2E, or the tests of the PHPStan package.blockstudio/icons/diris added to the hook list inHookCallbackRule. I left the changelog and the bundled LLM files to the release.Happy to change the directory, the filter name, or to make the copy opt-in instead of opt-out if you prefer that.