2017 © Pedro Peláez
 

library wp-endpoints-routes

Get the set of routes.

image

moxie-leean/wp-endpoints-routes

Get the set of routes.

  • Tuesday, April 5, 2016
  • by moxieDeveloper
  • Repository
  • 5 Watchers
  • 0 Stars
  • 129 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

WP Endpoints: Routes

Get the set of routes and exposes them via WP-API. This extension will create an endpoint (at /wp-json/lean/v1/routes by default)., (*1)

Current State

As of now the endpoint only adds pages automatically. You can manually add others using the ln_endpoints_data_routes filter (see below)., (*2)

Getting Started

The easiest way to install this package is by using composer from your terminal:, (*3)

composer require moxie-lean/wp-endpoints-routes

Or by adding the following lines on your composer.json file, (*4)

"require": {
  "moxie-lean/wp-endpoints-routes": "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., (*5)

After that you can include the autoload.php file in order to be able to autoload the class during the object creation., (*6)

include '/vendor/autoload.php';

Finally you need to initialise the endpoint by adding this to your code:, (*7)

\Leean\Endpoints\Routes::init();

Usage

The endpoint takes no inputs and returns data in the following format:, (*8)

[
  {
    "state": "home",
    "url": "/",
    "template": "home",
    "endpoint": "post",
    "params": {
      "id": 123
    }
  },
  {
    "state": "allPhotos",
    "url": "/photos",
    "template": "allPhotos",
    "endpoint": "collection",
    "params": {
      "type": "photo",
      "posts_per_page": 10
    }
  },
  {
    "state": "authorPhotos",
    "url": "/photos/:authorId",
    "template": "authorPhotos",
    "endpoint": "collection",
    "params": {
      "type": "photo",
      "posts_per_page": 10
    }
  },
  {
    "state": "photo",
    "url": "/photos/:authorId/:photoId",
    "template": "photo",
    "endpoint": "post",
    "params": {}
  }
]

Adding Extra Routes

You can do this with the ln_endpoints_data_routes filter as follows:, (*9)

add_filter( 'ln_endpoints_data_routes', 'add_extra_routes' );

function add_extra_routes( $routes ) {
    $extra_routes = [
        [
            'state' => 'blog',
            'url' => '/blog/',
            'template' => 'blog',
            'endpoint' => 'collection',
            'params' => [
                'type' => 'post',
                'posts_per_page' => 5,
            ]
        ],
    ];

    return array_merge( $routes, $extra_routes );
}

The Versions

05/04 2016

dev-master

9999999-dev https://github.com/moxie-leean/wp-endpoints-routes

Get the set of routes.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Fenton

wordpress api

05/04 2016

0.1.1

0.1.1.0 https://github.com/moxie-leean/wp-endpoints-routes

Get the set of routes.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Fenton

wordpress api

31/03 2016

0.1.0

0.1.0.0 https://github.com/moxie-leean/wp-endpoints-routes

Get the set of routes.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Adam Fenton

wordpress api