pollora / ajax
A modern PHP package for WordPress AJAX action management with fluent API
v1.0.0
2026-06-22 13:19 UTC
Requires
- php: ^8.2
Requires (Dev)
- laravel/pint: ^v1.22.1
- mockery/mockery: ^2.0.x-dev
- pestphp/pest: ^v3.8.2
- phpstan/phpstan: ^2.1.16
This package is not auto-updated.
Last update: 2026-06-23 12:17:23 UTC
README
A modern PHP package for WordPress AJAX action management with a fluent API and secure defaults.
Installation
composer require pollora/ajax
Quick Start
use Pollora\Ajax\Ajax; // Logged-in users only (default — secure by design) Ajax::listen('my_action', function () { wp_send_json_success(['message' => 'It works!']); }); // All users (explicit opt-in required) Ajax::listen('public_action', function () { // ... })->forAllUsers(); // Guest users only Ajax::listen('guest_action', function () { // ... })->forGuestUsers();
With the Pollora Framework
When used inside Pollora, you can also use the #[Ajax] PHP attribute for declarative registration:
use Pollora\Attributes\Ajax; use Pollora\Ajax\Domain\Model\AjaxAccess; class NewsletterHandler { #[Ajax('subscribe')] public function subscribe(): void { wp_send_json_success(['message' => 'Subscribed!']); } #[Ajax('load_more', access: AjaxAccess::ALL)] public function loadMore(): void { wp_send_json_success([/* ... */]); } }
Documentation
See docs/ajax.md for full documentation.
Testing
composer test
License
GPL-2.0-or-later