Skip to content

(perf): Register icon collections - #527

Open
firestar300 wants to merge 7 commits into
masterfrom
perf/register-icon-collections
Open

firestar300 wants to merge 7 commits into
masterfrom
perf/register-icon-collections

Conversation

@firestar300

@firestar300 firestar300 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Correctifs pour #525 .


Note

Low Risk
Changes are confined to theme icon registration and caching; the main caveat is stale transient lists if icons change without updating the collection directory mtime, mitigated in theme development mode.

Overview
Icon registration is gated earlier and avoids repeated filesystem work on each request.

The WordPress icon APIs are now checked once in boot() before any init hooks are attached, and the duplicate guards inside collection/icon registration are removed. Collection registration is reordered so a collection is only registered after SVG files are found, with empty glob results handled via new helpers instead of silent early returns mid-loop.

SVG file lists are cached in transients (one week, keyed by directory path and directory mtime), with cache bypassed when development mode is theme or all. Per-icon registration drops realpath/is_readable checks and uses sanitize_title() for slugs while passing through the resolved path from directory resolution.

Reviewed by Cursor Bugbot for commit bb513f4. Bugbot is set up for automated code reviews on this repo. Configure here.

Skip registering init callbacks when icon registry functions are unavailable instead of repeating function_exists checks in each handler.
Align slug normalization with WP_Icons_Registry so underscores and mixed-case filenames are preserved instead of stripped or silently merged.
Pass glob paths directly to wp_register_icon instead of realpath and is_readable on every init; directory safety stays in resolve_icons_directory().
Avoid glob on every request by storing file paths in a transient keyed by directory mtime; bypass the cache when WP_DEBUG is enabled.
Register icon collections only after glob finds at least one SVG so empty dist/images folders do not appear in the block picker.
@firestar300
firestar300 requested a review from Rahe November 4, 2026 15:26
Comment thread inc/Services/Icon.php Resolved
Comment thread inc/Services/Icon.php Resolved
@firestar300
firestar300 requested a review from Rahe November 4, 2026 16:31
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