moxie-lean / wp-endpoints-static
Generic but customisable endpoint to expose our static data via WP-API.
Requires
- php: >=5.4
- moxie-lean/wp-acf: 1.*.*
- moxie-lean/wp-endpoint: 2.*.*
- moxie-lean/wp-widgets: 1.*.*
Requires (Dev)
README
Generic but customisable endpoint to expose our static data via WP-API. This extension will create an endpoint (at
`
/wp-json/leean/v1/static`
by default).
The endpoint takes a no parameters and returns the following data:
- Site name
- Site tagline
- Menus
- Menu location
- Menu items
- Menu location
- Widgets
Getting Started
The easiest way to install this package is by using composer from your terminal:
composer require moxie-lean/wp-endpoints-static
Or by adding the following lines on your composer.json
file
"require": {
"moxie-lean/wp-endpoints-static": "dev-master"
}
This will download the files from the packagist site and set you up with the latest version located on master branch of the repository.
After that you can include the autoload.php
file in order to
be able to autoload the class during the object creation.
include '/vendor/autoload.php';
Finally you need to initialise the endpoint by adding this to your code:
\Lean\Endpoints\StaticApi::init();
Usage
The extension has a number of filters which can be used to customised the output. In addition it does some useful extra manipulation of ACF data to make it more useful to a front-end app.
Filters
Common parameters passed by many filers are:
- $endpoint : the name of the endpoint. Always '/static' for this extension.
ln_endpoints_api_namespace
Customise the API namespace ('leean' in `
/wp-json/leean/v1/static`
)
add_filter( 'ln_endpoints_api_namespace', function( $namespace, $endpoint ) {
return 'my-app';
}, 10, 2 );
ln_endpoints_api_version
Customise the API version ('v1' in `
/wp-json/leean/v1/static`
)
add_filter( 'ln_endpoints_api_version', function( $version, $endpoint ) {
return 'v2';
}, 10, 2 );
ln_endpoints_data
Customise the results just before they are sent.
add_filter( 'ln_endpoints_data', function( $data, $endpoint ) {
$data['site_title] = 'New Title;
return $data;
}, 10, 3 );