PHPackages                             pinkcrab/ajax - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. pinkcrab/ajax

ActiveLibrary[Framework](/categories/framework)

pinkcrab/ajax
=============

Ajax creation library for the Perique Framework.

2.1.1(2mo ago)31.0k1[3 PRs](https://github.com/Pink-Crab/Perique-Ajax/pulls)MITPHPPHP &gt;=8.0.0CI passing

Since May 13Pushed 1mo agoCompare

[ Source](https://github.com/Pink-Crab/Perique-Ajax)[ Packagist](https://packagist.org/packages/pinkcrab/ajax)[ Docs](https://pinkcrab.co.uk)[ RSS](/packages/pinkcrab-ajax/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (9)Dependencies (38)Versions (27)Used By (0)

[![logo](docs/Ajax.jpg "PinkCrab Ajax Module")](docs/Ajax.jpg)

Ajax
====

[](#ajax)

A simple but powerful Ajax library for the PinkCrab Perique framework. Allows for the creation of object based Ajax calls that handle all basic Nonce validation, WP Actions and makes use of the HTTP PSR Interfaces.

[![Latest Stable Version](https://camo.githubusercontent.com/476804decbdfa0248c6fea1396c04ea847cf8e1919590f1e3a8b955664ca674f/68747470733a2f2f706f7365722e707567782e6f72672f70696e6b637261622f616a61782f76)](https://packagist.org/packages/pinkcrab/ajax) [![Total Downloads](https://camo.githubusercontent.com/a6eb0d46f3ab387f00cb43a6d3de41641b4b5f6b76ff3e522cb8561bb7fb3d2d/68747470733a2f2f706f7365722e707567782e6f72672f70696e6b637261622f616a61782f646f776e6c6f616473)](https://packagist.org/packages/pinkcrab/ajax) [![Latest Unstable Version](https://camo.githubusercontent.com/30db1802b1c9a4aefdc645f1315d1c74aeced40dc41d7ac4df131735dd1aa862/68747470733a2f2f706f7365722e707567782e6f72672f70696e6b637261622f616a61782f762f756e737461626c65)](https://packagist.org/packages/pinkcrab/ajax) [![License](https://camo.githubusercontent.com/c96651e649cf56113e99507562988ad661caa77db1a11220f060529b7d831e4f/68747470733a2f2f706f7365722e707567782e6f72672f70696e6b637261622f616a61782f6c6963656e7365)](https://packagist.org/packages/pinkcrab/ajax) [![PHP Version Require](https://camo.githubusercontent.com/7c60d27578bbda121b75f173b2b30087815ee530cfbdd445b0c26ab2935e361b/68747470733a2f2f706f7365722e707567782e6f72672f70696e6b637261622f616a61782f726571756972652f706870)](https://packagist.org/packages/pinkcrab/ajax)

[![WP6.6 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/Perique-Ajax/actions/workflows/WP_6_6.yaml/badge.svg)](https://github.com/Pink-Crab/Perique-Ajax/actions/workflows/WP_6_6.yaml)[![WP6.7 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/Perique-Ajax/actions/workflows/WP_6_7.yaml/badge.svg)](https://github.com/Pink-Crab/Perique-Ajax/actions/workflows/WP_6_7.yaml)[![WP6.8 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/Perique-Ajax/actions/workflows/WP_6_8.yaml/badge.svg)](https://github.com/Pink-Crab/Perique-Ajax/actions/workflows/WP_6_8.yaml)[![WP6.9 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/Perique-Ajax/actions/workflows/WP_6_9.yaml/badge.svg)](https://github.com/Pink-Crab/Perique-Ajax/actions/workflows/WP_6_9.yaml)

[![codecov](https://camo.githubusercontent.com/4f475056fbfd3e3be68a51562c65932d557bfcf1c97f409158c02ab7dcaed587/68747470733a2f2f636f6465636f762e696f2f67682f50696e6b2d437261622f506572697175652d416a61782f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d4e455a4f7a3646734b4b)](https://codecov.io/gh/Pink-Crab/Perique-Ajax)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/fe047136857f715ff409015c45e2ca9b3db5d617f364839b56df70def883d529/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f50696e6b2d437261622f506572697175652d416a61782f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Pink-Crab/Perique-Ajax/?branch=master)[![Maintainability](https://camo.githubusercontent.com/2a416e414a2ef678e8118c1d7f144642c8abcc77388e62bb6cc971212a6ac2ed/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f37353334656539643361623661353738353338362f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/Pink-Crab/Perique-Ajax/maintainability)

---

Why?
----

[](#why)

Writing Ajax scripts for WordPress can get messy really quickly, with the need to define up to 2 actions with a shared callback. The Perique Ajax Module makes use of the registration and dependency injection aspects of the framework. This allows for the injection of services into your callback, allowing for clean and testable code.

---

Perique Ajax Documentation
--------------------------

[](#perique-ajax-documentation)

- [Ajax Model](docs/Ajax_Model.md)
- [Ajax Helper](docs/Ajax_Helper.md)
- [Response Factory](docs/Response_Factory.md)
- [Hooks](docs/Hooks.md)
- [Example](docs/Examples.md)

---

Setup
-----

[](#setup)

> *Requires the PinkCrab Perique Framework v2 and Composer*

**Install the Module using composer**

```
$ composer require pinkcrab/ajax
```

**Include the custom Ajax Module**

```
// file:plugin.php

// Boot the app as normal, including the module.
$app = ( new App_Factory )
    ->default_setup()
    ->module( \PinkCrab\Ajax\Module\Ajax::class )
    ->boot();
```

Usage
-----

[](#usage)

**Create your Ajax Models**

```
use PinkCrab\Ajax\Ajax;
use PinkCrab\Ajax\Ajax_Helper;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use PinkCrab\Ajax\Dispatcher\Response_Factory;

class My_Ajax extends Ajax {

    /**
     * Define the action to call.
     * @var string
     */
    protected $action = 'my_ajax_action';

    /**
     * The ajax calls nonce handle.
     * @var string
     */
    protected $nonce_handle = 'my_ajax_nonce';

    /**
     * Some service which handles the logic of the call.
     * @var Some_Service
     */
    protected $my_service;

    /**
     * Constructs the object
     * My_Service will be injected when this is created by the DI Container
     */
    public function __construct( Some_Service $my_service ) {
        $this->my_service = $my_service;
    }

    /**
     * The callback
     *
     * @param \Psr\Http\Message\ServerRequestInterface $request
     * @param \PinkCrab\Ajax\Dispatcher\Response_Factory $response_factory
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function callback(
        ServerRequestInterface $request,
        Response_Factory $response_factory
    ): ResponseInterface {

        // Extract the args from the request, you can also do this manually
        $args = Ajax_Helper::extract_server_request_args( $request );

        // Do something with the request args, ideally in a service class
        $data_to_return = array_key_exists('foo', $args)
            ? $this->my_service->do_something($args['foo'])
            : 'Foo not found!';

        // Return with a valid PSR Response.
        return $response_factory->success( $data_to_return );
    }
}
```

> This would have an ajax call with `my_ajax_action` action assigned.

\*\*Add all your Ajax Models to `registration.php` \*\*

```
// file:registration.php

return [
    ....
    My_Ajax_Call::class,
    ....
];
```

---

License
-------

[](#license)

### MIT License

[](#mit-license)

Pre-Release
-----------

[](#pre-release)

- For Perique 1.4.\*, use version 1.1.0
- For Perique 1.3.\*, use version 1.0.4
- For Perique 1.0.\* - 1.2.\*, use version 1.0.3

Change Log
----------

[](#change-log)

- 2.1.1 - Updated dev dependencies.
- 2.1.0 - Bump support for Perique 2.1.0, update deps.
- 2.0.0 - Bump support for Perique 2.0.0, remove Ajax::bootstrap() and replace with the Ajax Module.
- 1.1.0 - Bump support for Perique 1.4.0
- 1.0.4 - Update dev deps to wp6.1 and PinkCrab/HTTP 1.\*, Drop Support for PHP 7.1
- 1.0.3 - Update dev deps, update GH Pipeline and improve conditional on checking if doing ajax.
- 1.0.2 - Added in Ajax\_Bootstrap class with ::use() method, for simpler inclusion with Perique. Docs improved as part of Perique.info site
- 1.0.1 - Update yoast/phpunit-polyfills requirement from ^0.2.0 to ^0.2.0 || ^1.0.0 by @dependabot in #13
- 1.0.0 - Supports Perique 1.0.0 and includes checks to ensure only added when wp\_ajax called
- 0.1.0 Extracted from the Registerables module. Now makes use of a custom Registration\_Middleware service for dispatching all Ajax calls.

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance89

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 97.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~221 days

Recently: every ~285 days

Total

9

Last Release

76d ago

Major Versions

1.1.0 → 2.0.02023-04-03

PHP version history (4 changes)1.0.0PHP &gt;=7.1.0

1.0.4PHP &gt;=7.2.0

2.0.0PHP &gt;=7.4.0

2.1.1PHP &gt;=8.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d82b9e8ef7816d3d0b9812ad233f61f6a313f529e0ac85721781b46ad292e1ea?d=identicon)[glynnquelch](/maintainers/glynnquelch)

---

Top Contributors

[![gin0115](https://avatars.githubusercontent.com/u/28779094?v=4)](https://github.com/gin0115 "gin0115 (124 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")

---

Tags

httppsr-7wordpress

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pinkcrab-ajax/health.svg)

```
[![Health](https://phpackages.com/badges/pinkcrab-ajax/health.svg)](https://phpackages.com/packages/pinkcrab-ajax)
```

###  Alternatives

[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k39.6M296](/packages/laravel-dusk)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
