Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,57 @@ Also, please bear in mind that B3 is a work in progress and can't (yet) be consi

The B3 REST API Extensions plugin enables the following additional endpoints.

To make it easier to tell B3 extensions apart from the other endpoints, all of our additions are prepended by `b3:`.
To make it easier to tell B3 extensions apart from the other endpoints, all of our additions are prepended by `b3_`.

### Comments

We provide an alternative implementation of the Comments resource that allows retrieving comments without having to know which post they belong to.

* `GET` `/b3:comments/<id>`
* `GET` `/b3:comments/<id>/b3:replies`
* `POST` `/b3:comments/<id>/b3:replies`
* `GET` `/media/<id>/b3:replies`
* `POST` `/media/<id>/b3:replies`
* `GET` `/pages/<id>/b3:replies`
* `POST` `/pages/<id>/b3:replies`
* `GET` `/posts/<id>/b3:replies`
* `POST` `/posts/<id>/b3:replies`
* `GET` `/b3_comments/<id>`
* `GET` `/b3_comments/<id>/b3_replies`
* `POST` `/b3_comments/<id>/b3_replies`
* `GET` `/media/<id>/b3_replies`
* `POST` `/media/<id>/b3_replies`
* `GET` `/pages/<id>/b3_replies`
* `POST` `/pages/<id>/b3_replies`
* `GET` `/posts/<id>/b3_replies`
* `POST` `/posts/<id>/b3_replies`

### Media

This endpoint provides a way to fetch a media attachment by its slug.

* `GET` `/media/b3:slug:<slug>`
* `GET` `/media/b3_slug:<slug>`

### Posts

This endpoint provides a way to fetch a post by its slug.

* `GET` `/posts/b3:slug:<slug>`
* `GET` `/posts/b3_slug:<slug>`

### Menus

We provide endpoints to fetch all Menus registered by the theme as well as the menu items configured in the WordPress Admin.

* `GET` `/b3:menus`
* `GET` `/b3:menus/<location>`
* `GET` `/b3_menus`
* `GET` `/b3_menus/<location>`

### Sidebars

Similar to Menus, we allow fetching all widget areas registered by the theme as well as their widgets and widget content.

* `GET` `/b3:sidebars`
* `GET` `/b3:sidebars/<index>`
* `GET` `/b3_sidebars`
* `GET` `/b3_sidebars/<index>`

### Settings

Finally, this plugin exposes WordPress settings through the API. It wraps the `get_bloginfo()` function but exposes a few additional site options as well as the pretty permalinks table.

* `GET` `/b3:settings`
* `GET` `/b3:settings/<option>`
* `GET` `/b3_settings`
* `GET` `/b3_settings/<option>`

### ACF (Advanced Custom Fields) Options Page fields

Exposes all fields from a ACF options page if available.

* `GET` `/b3_acf/options`
1 change: 1 addition & 0 deletions b3-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function __construct() {
'B3_Post' => null,
'B3_Settings' => null,
'B3_Sidebar' => null,
'B3_ACF_Options' => null
);

add_action( 'init', array( $this, 'init' ), 99 );
Expand Down
89 changes: 89 additions & 0 deletions resources/B3_ACF_Options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* @package B3
* @subpackage B3/API
*/

if (!defined('WPINC')) {
die;
}

/**
* Extends the default Post resource API.
*/
class B3_ACF_Options extends B3_API {

/**
* Register new API routes for the Post resource.
*
* @param array $routes API routes.
* @return array Changed API routes.
*/
public function register_routes($routes) {

$option_routes = array(
'/b3_acf/options' => array(
array(array($this, 'get_options'), WP_JSON_Server::READABLE),
)
// ,
// '/B3_acf/options/(?P<slug>\w+)' => array(
// array(array($this, 'get_options'), WP_JSON_Server::READABLE),
// )
);

return array_merge($routes, $option_routes);
}

/**
* Retrieve all ACF options.
*
* @param string $context Context in which the post appears.
*
* @return array|WP_Error Options entity, or error.
*/
public function get_options($context = 'view') {
global $wp_json_posts;

$option = get_fields('option', false);

if (!$option) {
return B3_JSON_REST_API::error('json_option_invalid_slug',
__('Invalid option slug.', 'b3-rest-api'), 404);
}

return $option;
}





/**
* Retrieve all ACF options by slug.
*
* @param string $slug Options slug.
* @param string $context Context in which the post appears.
*
* @return array|WP_Error Options entity, or error.
*/
// public function get_options($slug, $context = 'view') {
// global $wp_json_posts;

// // if (empty($slug)) {
// // return B3_JSON_REST_API::error('json_option_invalid_slug',
// // __('Invalid option slug.'), 404);
// // }

// $option = get_fields('option', false);

// if (!$option) {
// return B3_JSON_REST_API::error('json_option_invalid_slug',
// __('Invalid option slug.', 'b3-rest-api'), 404);
// }

// return $option;

// // return $wp_json_posts->get_options($post->ID, $context);
// }

}
Loading