Download the PHP package carloswph/wp-endpoint-gen without Composer

On this page you can find all versions of the php package carloswph/wp-endpoint-gen. 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-endpoint-gen

wp-endpoint-gen

Wordpress custom endpoints helper and class generator. Wordpress engine to add new custom endpoints to the WP API is not that hard to understand. However, manipulate dozens of new endpoints and the respective callbacks and permission callbacks can be troublesome depending on the complexity of the plugin or extension. Thus, this library helps you not only by creating an OOP approach to add new endpoints, but also for managing their namespaces, arguments and callbacks. Besides, we thought that'd be much simpler and organized if we concentrated callbacks and permissions for each of the new endpoints in a particular controller class - and, of course, automatically generate them depending on how you customize your new endpoint. Well, nothing else to add by now - let's check how it works within the following code samples.

Installation

Usage

The first step involves creating a new instance of the class WPH\Endpoints\Config in your code. Do not forget to make it instantiable using Composer's autoload. The Config class can either be instantiated within the Generator class, or before it, everytime you desire to change the default values for the config details.

Configuring what?

By default, we considered all custom endpoints to be positioned within the namespace wph (for obvious reasons). Generated classes will be created under the namespace or Psr "EndpointGroup", and will bring "v1" as the current version. The base path for saving the generated classes will be located onto a new folder named "endpoints", inside the wp-content directory. Brilliant, ain't it? No? Don't worry, by instantiating the Config class, you are able to customize all of those variables.

I loved your defaults - don't need to change it

Brilliant again! In this case, just ignore the Config class set up, and go to the next part of this tutorial. You'll still need to use the Config class, but if you don't need to change anything, you should just inject a new instance of it within the Generator class. The next example will clarify.

All custom endpoints will find the respective callbacks and permission callbacks inside their own classes, located in the path you indicated. It's more than just thinking the WP endpoints in an OOP way - that means you DON'T NEED to write dozens of repetitive functions and callbacks, nor pollute your code with huge anonymous functions or similars.

Ok, but you guys forgot the endpoint arguments...

Uhhh... no, actually we did not. By the way, you can add args to the endpoints using two different methods.

  1. If all endpoint methods shall be accepting the same arguments, add them as an array, while instantiating the Generator class (underway)
  2. However, if you need to add arguments just for the GET method, for instance, you can apply the chain method addArgs().

Let's start with the method 2, which is already functional. All you need to do is using the chained method addArgs(), with two paramets: the http method (GET, for instance), and an array of the desired arguments. Like this:

How generated classes look like?

So now you are probably asking yourself how those generated controllers we mentioned look like. Of course they are basically skeletons in which you can create your own processes and conditions, but they are already functional from the first moment, returning a simple instance of WP_Rest_Response class. Let's consider an endpoint added under the name 'boxes', and dealing with GET, POST and HEAD calls. In this case, the generated controller class would appear like this:

All classes are already annotated and bring a callback for each HTTP method created for the respective endpoint, as well as a permissions() function, which return by default. Callbacks, as shown, initially return a simple instance of the WP_Rest_Response class.


All versions of wp-endpoint-gen with dependencies

PHP Build Version
Package Version
Requires nette/php-generator Version ^3.5
nette/robot-loader Version ^3.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 carloswph/wp-endpoint-gen contains the following files

Loading the files please wait ....