Skip to content

Adding utility action functions to AbstractBase - #173

Open
amerk-sitecrafting wants to merge 6 commits into
update/ajax-loggingfrom
update/register-multiple-ajax-actions
Open

amerk-sitecrafting wants to merge 6 commits into
update/ajax-loggingfrom
update/register-multiple-ajax-actions

Conversation

@amerk-sitecrafting

Copy link
Copy Markdown
Contributor

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

@amerk-sitecrafting
amerk-sitecrafting requested review from rhendrickson-sc and a lite review from Copilot August 20, 2026 21:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(), and get_registered_actions() on AbstractBase backed 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,
];
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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']);
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amerk-sitecrafting This also feels like something work adding.

Comment thread docs/ajax-handlers.md
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)`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amerk-sitecrafting Also feels worthwhile.

Comment thread docs/changelog/2026.md Outdated

@rhendrickson-sc rhendrickson-sc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

Deploying conifer-plugin with  Cloudflare Pages  Cloudflare Pages

Latest commit: 697e5da
Status: ✅  Deploy successful!
Preview URL: https://48916339.conifer-plugin.pages.dev

View logs

@rhendrickson-sc rhendrickson-sc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking solid!

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.

3 participants