PHPackages                             yahnis-elsts/ajax-wrapper - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. yahnis-elsts/ajax-wrapper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

yahnis-elsts/ajax-wrapper
=========================

AJAX action wrapper for WordPress

213.8k↓76.9%7PHP

Since Mar 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/YahnisElsts/ajax-wrapper)[ Packagist](https://packagist.org/packages/yahnis-elsts/ajax-wrapper)[ RSS](/packages/yahnis-elsts-ajax-wrapper/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

AJAX Action Wrapper
===================

[](#ajax-action-wrapper)

This helper library makes it easier to handle AJAX requests in WordPress plugins. Mainly for personal use.

### Example

[](#example)

Define action:

```
$exampleAction = ajaw_v1_CreateAction('ws_do_something')
	->handler(array($this, 'myAjaxCallback'))
	->requiredCap('manage_options')
	->method('post')
	->requiredParam('foo')
	->optionalParam('bar', 'default value')
	->register();
```

Call from JavaScript:

```
AjawV1.getAction('ws_do_something').post(
	{
		'foo': '...'
	},
	function(response) {
		console.log(response);
	}
);
```

### Features

[](#features)

- Automate common, boring stuff.
    - Automatically pass the `admin-ajax.php` URL and nonce to JS.
    - Define required parameters. ```
         $builder->requiredParam('foo', 'int')
        ```
    - Define optional parameters with default values. ```
         $builder->optionalParam('meaningOfLife', 42, 'int')
        ```
    - Automatically remove "magic quotes" that WordPress adds to `$_GET`, `$_POST` and `$_REQUEST`.
    - Encode return values as JSON.
- Security should be the default.
    - Generate and verify nonces. Nonce verification is on by default, but can be disabled. ```
         $builder->withoutNonce()
        ```
    - Check capabilities. ```
         $builder->requiredCap('manage_options');
        ```
    - Verify that all required parameters are set.
    - Validate parameter values. ```
         $builder->optionalParam('things', 1, 'int', function($value) {
         	if ($value > 10) {
         		return new WP_Error(
         			'excessive_things',
         			'Too many things!',
         			400 //HTTP status code.
         		);
         	}
         })
        ```
    - Set the required HTTP method. ```
         $builder->method('post')
        ```
- Resilience.
    - Lenient response parsing to work around bugs in other plugins. For example, deal with extraneous whitespace and PHP notices in AJAX responses.
    - Multiple versions of the library can coexist on the same site.

### Why not use the REST API instead?

[](#why-not-use-the-rest-api-instead)

Backwards compatibility. In theory, this library should be compatible with WP 4.1+.

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2527434?v=4)[Yahnis Elsts](/maintainers/YahnisElsts)[@YahnisElsts](https://github.com/YahnisElsts)

---

Top Contributors

[![YahnisElsts](https://avatars.githubusercontent.com/u/2527434?v=4)](https://github.com/YahnisElsts "YahnisElsts (13 commits)")

---

Tags

wordpress

### Embed Badge

![Health badge](/badges/yahnis-elsts-ajax-wrapper/health.svg)

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

###  Alternatives

[roots/acorn-prettify

Theme-agnostic front-end modifications for WordPress

58289.3k9](/packages/roots-acorn-prettify)[humanmade/mercator-redirect

Redirect component for Mercator.

1511.4k](/packages/humanmade-mercator-redirect)

PHPackages © 2026

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