PHPackages                             cuberis/wp-rest-endpoints - 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. [API Development](/categories/api)
4. /
5. cuberis/wp-rest-endpoints

ActiveLibrary[API Development](/categories/api)

cuberis/wp-rest-endpoints
=========================

Add custom Rest API endpoints to your WordPress site.

1.0.0(6y ago)249[1 issues](https://github.com/cuberis/wp-rest-endpoints/issues)GPL-2.0-or-laterPHPPHP &gt;=7

Since Mar 8Pushed 6y ago2 watchersCompare

[ Source](https://github.com/cuberis/wp-rest-endpoints)[ Packagist](https://packagist.org/packages/cuberis/wp-rest-endpoints)[ RSS](/packages/cuberis-wp-rest-endpoints/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (8)DependenciesVersions (10)Used By (0)

REST API Endpoints for WordPress
================================

[](#rest-api-endpoints-for-wordpress)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0370f58f25bf425efa0b80f9e55f1593b717ff592e870100e6b630ded60be765/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f637562657269732f77702d726573742d656e64706f696e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cuberis/wp-rest-endpoints)

Add custom REST API endpoints to your WordPress site. This package provides a basic system for adding simple endpoints to the WP REST API.

Requirements
------------

[](#requirements)

- PHP 5.6+
- WordPress 4.7+

Installing
----------

[](#installing)

1. Install via composer:

```
composer require cuberis/wp-rest-endpoints

```

2. Add your desired endpoint(s)
3. Create your individual result templates for the REST responses (if necessary)

Adding Endpoints
----------------

[](#adding-endpoints)

Note: when adding new endpoints, make sure to hook into `rest_api_init`.

### Add Route for Custom Post Type

[](#add-route-for-custom-post-type)

```
function my_register_rest_routes() {

  new Cuberis\REST_API\Post_Type_Controller('my_post_type_slug', [
    'namespace' => 'cuberis',
    'version'   => 1,
    'endpoint'  => 'my-post-type'
  ]);

}
add_action( 'rest_api_init', 'my_register_rest_routes' );
```

### Extend `Base_Controller` for a Custom Endpoint

[](#extend-base_controller-for-a-custom-endpoint)

```
class My_Custom_Controller extends Cuberis\REST_API\Base_Controller {

  public function __construct() {
    parent::__construct([
      'namespace' => 'cuberis',
      'version'   => 1,
      'endpoint'  => 'whatever'
    ]);
  }

  public function get_items( $request ) {
    return rest_ensure_response(['Testing']);
  }

}

function my_register_rest_routes() {
  new My_Custom_Controller();
}
add_action( 'rest_api_init', 'my_register_rest_routes' );
```

Templates
---------

[](#templates)

### Post Type Endpoints

[](#post-type-endpoints)

If you are using the default reponse from your post type endpoints, each endpoint will need a template. Templates are PHP files that live in the `templates/partials/` directory within your theme. Each template should be named: `partial-{post-type-slug}`. Example:

```
themes/your-theme-name/
├── templates/
│   ├── partials/
│   │   ├── partial-my_post_type.php
```

If you register multiple post types for an endpoint, the library will look for a partial named `partial-all.php`.

In your template file, the only thing you will have available from the post will be the ID in the form of an `$id` variable.

### Custom Endpoints

[](#custom-endpoints)

When defining custom endpoints, you have complete control over your API response so you can define if or how you use templates.

About the endpoints
-------------------

[](#about-the-endpoints)

By default, endpoints will return the following JSON format:

```
[
  {
    "id": 1234,
    "title": "My Post Title",
    "html": "\n\nMy Post Title\n\n\n"
  }
]
```

`id` is the raw post ID, `title` is your post title returned from `get_the_title()` and `html` is the raw HTML returned from your template file.

### Using URL Parameters

[](#using-url-parameters)

Endpoints are powered by URL parameters which should match up almost identically with WP\_Query vars. So for example, you could use:

[https://my-website.com/wp-json/cuberis/v1/my-post-type?posts\_per\_page=4&amp;paged=2&amp;my\_category=slug1,slug2](https://my-website.com/wp-json/cuberis/v1/my-post-type?posts_per_page=4&paged=2&my_category=slug1,slug2)

The API would then return posts from the following WP\_Query:

```
new WP_Query([
  'post_type' => 'my-post-type',
  'posts_per_page' => 4,
  'paged' => 2,
  'tax_query' => [
    [
      'taxonomy' => 'my_category',
      'field' => 'slug',
      'terms' => [
        'slug1',
        'slug2'
      ]
    ]
  ]
])

```

Note: Taxonomy queries via endpoints currently only supports the `slug` field type.

Optional Filters
----------------

[](#optional-filters)

### `cuberis_rest_cpt_result`

[](#cuberis_rest_cpt_result)

```
function cuberis_filter_api_result( $result, $post_id ) {
  return [
    'pageID' => $post_id,
    'testing' => 'yep!'
  ];
}
add_filter('cuberis_rest_cpt_result', 'cuberis_filter_api_result', 10, 2);
```

### `cuberis_rest_api_query_args`

[](#cuberis_rest_api_query_args)

```
function cuberis_filter_api_args( $args, $params ) {
  $args['order'] = 'ASC';
  return $args;
}
add_filter('cuberis_rest_api_query_args', 'cuberis_filter_api_args', 10, 2);
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity66

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~11 days

Recently: every ~21 days

Total

9

Last Release

2534d ago

Major Versions

0.3.1 → 1.0.02019-06-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/26b8b82c6c0336767ad8de1c9934950dbfdb4d03910d6b9de51061535155779a?d=identicon)[cuberis](/maintainers/cuberis)

---

Top Contributors

[![andrewmarino](https://avatars.githubusercontent.com/u/6686529?v=4)](https://github.com/andrewmarino "andrewmarino (1 commits)")

### Embed Badge

![Health badge](/badges/cuberis-wp-rest-endpoints/health.svg)

```
[![Health](https://phpackages.com/badges/cuberis-wp-rest-endpoints/health.svg)](https://phpackages.com/packages/cuberis-wp-rest-endpoints)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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