Download the PHP package philipnewcomer/wp-ajax-helper without Composer

On this page you can find all versions of the php package philipnewcomer/wp-ajax-helper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wp-ajax-helper

WP Ajax Helper

A library to simplify AJAX requests in WordPress plugins and themes.

What is This?

WP Ajax Helper exists to simplify the process of performing Ajax requests in WordPress.

With a simple, easy-to-understand syntax, it handles nonces and validation automatically, freeing you up to worry about more important things.

It also interprets the Ajax payload, passing it to your callback function as an array or string as appropriate, as well as interpreting the callback's response and returning it to the browser either as a string or as JSON.

With an simple validation component, you can easily restrict the user permissions under which the callback function will run.

Finally, it provides a JavaScript front-end component which interfaces with the backend library.

Getting Started

Backend

Include the package in your project using Composer, or simply include wp-ajax-helper.php from somewhere in your project.

The most basic usage is to call wp_ajax_helper() with a handle and a callback function, like this:

wp_ajax_helper()->handle( 'my-handle' )->with_callback( 'my_callback' );

The handle is the unique identifier for this instance, and the callback function is the function which should handle the Ajax request.

Frontend

Whenever a handle is registered, the JavaScript function wpAjaxHelperRequest() will be available to use in your scripts. Pass in the handle of the callback you want to call, and include an optional payload as the second parameter, which will be passed into your callback function.

wpAjaxHelperRequest( 'my-handle', 'payload' );

The payload can be either a string or an object. If an object is sent, it will be converted to a PHP array when passed to your callback function.

You'll probably want to do something with the response to your Ajax request; that is detailed below.

Advanced Usage

Backend: Callbacks

The callback can be a function name, a class method, or a closure.

Here are several examples illustrating various ways a callback can be registered:

Two parameters will be provided to the callback function when it is executed: $ajax_payload and $args. The first parameter is the Ajax payload from the request. The second is an array of values which were (optionally) specified as the second parameter when registering the handle.

If the callback function returns a string, the Ajax response will be a string. If the callback returns an array, the Ajax response will be that array, converted to a JSON object. If the callback function returns anything else, i.e. null, a WP_Error object, or throws an exception, the response will be an error.

Backend: Validation

To specify validations which need to pass before the callback function can run, pass in an array of validations to the with_validation() method, with the values to test in the following format.

The following validations are available:

Example usage:

All validations are optional.

Backend: Filters

The following filters are available, which will allow you to filter the Ajax payload before being sent to a callback function, as well as filtering the output of the callback function before being sent back to the browser.

Frontend: Handling the Response

The wpAjaxHelperRequest function will return a jQuery $.POST response, which you can utilize just like a normal $.POST request to handle the response:


All versions of wp-ajax-helper with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package philipnewcomer/wp-ajax-helper contains the following files

Loading the files please wait ....