Repository navigation
DSWP-1300 centralize theme hook registration - #208
Merged
robrien-bcgov merged 4 commits intoOct 28, 2026
Merged
robrien-bcgov merged 4 commits into
robrien-bcgov merged 4 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Taxonomy registration runs after the pattern loader, causing it to create a non-hierarchical fallback that loses ancestor paths in nested pattern category labels.
1 open issue
What changed in this PR
This PR makes theme initialization explicit by moving hook registration into Setup::init() and removing constructor-driven behavior.
Changes:
- Updates the theme entry point to call
Setup::init(). - Centralizes admin notice rendering and uses a shared notice instance.
- Adds tests for side-effect-free constructors and explicit hook registration.
| File | Description |
|---|---|
Tests/Actions/HookRegistrationTest.php |
Tests constructor behavior and hook registration through init(). |
src/Utils/AdminNotices.php |
Removes hook registration from the constructor. |
src/Setup.php |
Introduces explicit initialization and centralizes hook registration. |
src/Actions/ThemeSupports.php |
Removes constructor-triggered theme setup. |
src/Actions/RegisterCustomPatternsPostType.php |
Removes constructor-triggered post type registration. |
src/Actions/Dependencies.php |
Uses the shared admin notice instance for dependency warnings. |
src/Actions/BcgovSettings.php |
Removes constructor-based settings hook registration. |
functions.php |
Calls Setup::init() after creating the setup instance. |
Review effort: Balanced
Changed priority of custom pattern registration action. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The bcgov/wordpress-utils package is distributed via a private Satis repository that requires authentication in GitHub Actions. Using --prefer-source instead of --prefer-dist will install from the public GitHub repository instead, avoiding the HTTP 403 error. Fixes the PHP lint/test workflow failure in PR #208. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
robrien-bcgov
commented
Oct 28, 2026
ShawnTurple
approved these changes
Oct 28, 2026
ShawnTurple
left a comment
Contributor
There was a problem hiding this comment.
Thanks, this looks great
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.

This pull request refactors the theme's initialization process to ensure constructors are side-effect-free and that all WordPress hooks are registered explicitly via a new
initmethod in theSetupclass. It also improves test coverage for hook registration and updates how admin notices are managed. Below are the most important changes:Refactoring Theme Initialization and Hook Registration:
ThemeSupports,RegisterCustomPatternsPostType, andBcgovSettingsno longer register hooks or execute behavior; all hook registration is now centralized in theSetup::init()method. (src/Actions/ThemeSupports.php,src/Actions/RegisterCustomPatternsPostType.php,src/Actions/BcgovSettings.php, [1] [2] [3]functions.php) now creates aSetupinstance and calls itsinit()method, instead of relying on the constructor for hook registration.Setupclass's constructor is replaced with aninit()method that registers all necessary actions and filters, ensuring clearer control over when hooks are added. [1] [2]Testing and Reliability Improvements:
HookRegistrationTestto ensure constructors are side-effect-free and that hooks are only registered after callingSetup::init().Admin Notices Handling:
AdminNotices::get_instance()) throughout the codebase, and removes redundant hook registration from theAdminNoticesconstructor. (src/Utils/AdminNotices.php,src/Actions/Dependencies.php, [1] [2] [3]These changes collectively improve code maintainability, testability, and ensure predictable theme initialization.