Repository navigation
Adding utility action functions to AbstractBase - #173
Open
amerk-sitecrafting wants to merge 6 commits into
Open
amerk-sitecrafting wants to merge 6 commits into
amerk-sitecrafting wants to merge 6 commits into
Conversation
amerk-sitecrafting
requested review from
rhendrickson-sc
and
a lite review from Copilot
August 20, 2026 21:16
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a small registration layer to Conifer\AjaxHandler\AbstractBase so handler classes can declaratively register their WordPress AJAX hooks (authenticated and/or unauthenticated) and then install them in one call during site configuration.
Changes:
- Introduces
register_action(),add_actions(), andget_registered_actions()onAbstractBasebacked by a per-handler-class static registry. - Adds unit tests covering default/override privilege behavior and class isolation for registered actions.
- Updates AJAX handler documentation and the 2026 changelog to reflect the new registration workflow.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| test/unit/AjaxHandler/AjaxHandlerTest.php | Adds unit tests for register_action() / add_actions() behavior and class scoping. |
| lib/Conifer/AjaxHandler/AbstractBase.php | Implements the action registry plus new public static APIs to register and install hooks. |
| docs/changelog/2026.md | Notes the new AbstractBase functionality in v1.0.5. |
| docs/ajax-handlers.md | Updates examples and API docs to prefer registration + add_actions() in configuration. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+220
to
+226
| public static function register_action(string $action, bool $include_priv = true, bool $include_no_priv = false): void | ||
| { | ||
| static::$registered_actions[static::class][$action] = [ | ||
| 'include_priv' => $include_priv, | ||
| 'include_no_priv' => $include_no_priv, | ||
| ]; | ||
| } |
Contributor
There was a problem hiding this comment.
@amerk-sitecrafting This seems like a useful thing to implement.
Comment on lines
+233
to
+244
| public static function add_actions(): void | ||
| { | ||
| foreach (static::$registered_actions[static::class] ?? [] as $action => $options) { | ||
| if ($options['include_priv']) { | ||
| add_action("wp_ajax_{$action}", [static::class, 'handle']); | ||
| } | ||
|
|
||
| if ($options['include_no_priv']) { | ||
| add_action("wp_ajax_nopriv_{$action}", [static::class, 'handle']); | ||
| } | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
@amerk-sitecrafting This also feels like something work adding.
Comment on lines
+152
to
162
| ### `register_action(string $action, bool $include_priv = true, bool $include_no_priv = false)` | ||
|
|
||
| Registers an action for this handler class. By default, the action is available only to authenticated users. Set `$include_no_priv` to `true` to also handle unauthenticated requests, or set `$include_priv` to `false` to handle only unauthenticated requests. Call `add_actions()` in your config callback to add the registered hooks. | ||
|
|
||
|
|
||
| ### `add_actions()` | ||
|
|
||
| Adds the WordPress AJAX hooks for actions registered by this handler class. | ||
|
|
||
|
|
||
| ### `param(mixed $name)` |
…nt with naming convention. Also, adding doc section for get_actions
Deploying conifer-plugin with
|
| Latest commit: |
697e5da
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://48916339.conifer-plugin.pages.dev |
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.
Ticket: # 266
Issue
AbstractBase does not provide any way to register actions
Solution
Now it does!
Impact
Minimal, this should not affect any existing code. This update only extends functionality.
Testing
This update passed unit tests and PHPStan analysis