Skip to content

Commit

Permalink
Merge branch 'feature/permalinks' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
erwstout committed Jun 4, 2018
2 parents 5edef6f + 34c87ca commit 1001923
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
n/a

## [1.2.1] - 2018-06-04
### Added
- Permalinks to all page/post endpoints

## [1.2.0] - 2018-02-07
### Added
- ACF query in endpoint url to hide acf values from the response where applicable (all collections)
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,19 @@ It returns a JSON response with the following (returns an empty array if no post
- Tags
- Tag IDs
- ACF fields, if applicable

## Hooks and Filters

### Filter the Custom Post Types endpoints

```php
add_filter('better_rest_endpoints_cpt_collection', function($cpt_collection){
$cpt_collection = array_flip($cpt_collection);
unset($cpt_collection['oembed_cache']);
unset($cpt_collection['_pods_template']);
unset($cpt_collection['_pods_pod']);
unset($cpt_collection['_pods_field']);
$cpt_collection = array_values( array_flip($cpt_collection) );
return $cpt_collection;
});
```
2 changes: 1 addition & 1 deletion better-wp-endpoints.php → better-rest-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Better Rest Endpoints
Plugin URI: https://github.com/factor1/better-rest-endpoints/
Description: Serves up slimmer WordPress Rest API endpoints, with some great enhancements.
Version: 1.2.0
Version: 1.2.1
Author: Eric Stout, Factor1 Studios
Author URI: https://factor1studios.com/
License: GPL3
Expand Down
4 changes: 3 additions & 1 deletion includes/create_cpt_endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ function bre_build_cpt_endpoints() {
$bre_post = new stdClass();

// get post data
$permalink = get_permalink();
$bre_post->id = get_the_ID();
$bre_post->title = get_the_title();
$bre_post->slug = basename(get_permalink());
$bre_post->slug = basename($permalink);
$bre_post->permalink = $permalink;
$bre_post->date = get_the_date('c');
$bre_post->excerpt = get_the_excerpt();

Expand Down
4 changes: 3 additions & 1 deletion includes/get_cpt_by_id.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ function bre_build_single_cpt_endpoints() {


// get post data
$permalink = get_permalink();
$bre_cpt_post->id = get_the_ID();
$bre_cpt_post->title = get_the_title();
$bre_cpt_post->slug = basename(get_permalink());
$bre_cpt_post->slug = basename($permalink);
$bre_cpt_post->permalink = $permalink;
$bre_cpt_post->date = get_the_date('c');
$bre_cpt_post->excerpt = get_the_excerpt();
$bre_cpt_post->content = apply_filters('the_content', get_the_content());
Expand Down
4 changes: 3 additions & 1 deletion includes/get_cpt_by_slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ function bre_build_single_cpt_endpoints_slug() {


// get post data
$permalink = get_permalink();
$bre_cpt_post->id = get_the_ID();
$bre_cpt_post->title = get_the_title();
$bre_cpt_post->slug = basename(get_permalink());
$bre_cpt_post->slug = basename($permalink);
$bre_cpt_post->permalink = $permalink;
$bre_cpt_post->date = get_the_date('c');
$bre_cpt_post->excerpt = get_the_excerpt();
$bre_cpt_post->content = apply_filters('the_content', get_the_content());
Expand Down
2 changes: 2 additions & 0 deletions includes/get_cpts.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function bre_get_cpts() {
}
}

$bre_cpts = apply_filters( 'better_rest_endpoints_cpt_collection', $bre_cpts );

// check if array is empty, returns array if data exists, return false if empty
if( !empty($bre_cpts) ){
return $bre_cpts;
Expand Down
4 changes: 3 additions & 1 deletion includes/get_page_by_id.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ function get_page_by_id( WP_REST_Request $request ){
// better wordpress endpoint post object
$bre_page = new stdClass();

$permalink = get_permalink();
$bre_page->id = get_the_ID();
$bre_page->title = get_the_title();
$bre_page->slug = basename(get_permalink());
$bre_page->slug = basename($permalink);
$bre_page->permalink = $permalink;

/*
*
Expand Down
4 changes: 3 additions & 1 deletion includes/get_pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ function bre_get_pages( WP_REST_Request $request ) {
* get page data
*
*/
$permalink = get_permalink();
$bre_page->id = get_the_ID();
$bre_page->title = get_the_title();
$bre_page->slug = basename(get_permalink());
$bre_page->slug = basename($permalink);
$bre_page->permalink = $permalink;

/*
*
Expand Down
4 changes: 3 additions & 1 deletion includes/get_post_by_id.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ function get_post_by_id( $data ) {
// better wordpress endpoint post object
$bre_post = new stdClass();

$permalink = get_permalink();
$bre_post->id = get_the_ID();
$bre_post->title = get_the_title();
$bre_post->slug = basename(get_permalink());
$bre_post->slug = basename($permalink);
$bre_post->permalink = $permalink;
$bre_post->date = get_the_date('c');
$bre_post->excerpt = get_the_excerpt();
$bre_post->content = apply_filters('the_content', get_the_content());
Expand Down
4 changes: 3 additions & 1 deletion includes/get_post_by_slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ function get_post_by_slug( WP_REST_Request $request ) {
// better wordpress endpoint post object
$bre_post = new stdClass();

$permalink = get_permalink();
$bre_post->id = get_the_ID();
$bre_post->title = get_the_title();
$bre_post->slug = basename(get_permalink());
$bre_post->slug = basename($permalink);
$bre_post->permalink = $permalink;
$bre_post->date = get_the_date('c');
$bre_post->excerpt = get_the_excerpt();
$bre_post->content = apply_filters('the_content', get_the_content());
Expand Down
4 changes: 3 additions & 1 deletion includes/get_posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ function bre_get_posts( WP_REST_Request $request ) {
$bre_post = new stdClass();

// get post data
$permalink = get_permalink();
$bre_post->id = get_the_ID();
$bre_post->title = get_the_title();
$bre_post->slug = basename(get_permalink());
$bre_post->slug = basename($permalink);
$bre_post->permalink = $permalink;
$bre_post->date = get_the_date('c');
$bre_post->excerpt = get_the_excerpt();

Expand Down
4 changes: 3 additions & 1 deletion includes/get_posts_tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ function bre_build_custom_tax_endpoint() {
$bre_tax_post = new stdClass();

// get post data
$permalink = get_permalink();
$bre_tax_post->id = get_the_ID();
$bre_tax_post->title = get_the_title();
$bre_tax_post->slug = basename(get_permalink());
$bre_tax_post->slug = basename($permalink);
$bre_tax_post->permalink = $permalink;
$bre_tax_post->date = get_the_date('c');
$bre_tax_post->excerpt = get_the_excerpt();

Expand Down
4 changes: 3 additions & 1 deletion includes/get_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ function bre_get_search( WP_REST_Request $request ) {
$bre_post = new stdClass();

// get post data
$permalink = get_permalink();
$bre_post->id = get_the_ID();
$bre_post->title = get_the_title();
$bre_post->slug = basename(get_permalink());
$bre_post->slug = basename($permalink);
$bre_post->permalink = $permalink;
$bre_post->date = get_the_date('c');
$bre_post->excerpt = get_the_excerpt();

Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Contributors: factor1, erwstout
Tags: rest, api, endpoints, acf, json
Requires at least: 4.7.1
Tested up to: 4.9.4
Stable Tag: 1.2.0
Stable Tag: 1.2.1
License: GNU Version 3 or Any Later Version

A WordPress plugin that serves up slimmer WP Rest API endpoints.
Expand Down Expand Up @@ -42,6 +42,9 @@ apps endpoints to use Better Rest Endpoints.

== Changelog ==

= 1.2.1, June 4, 2018 =
* Add: Permalinks to all post/page endpoints

= 1.2.0, Febuary 7, 2018 =
* Add: ACF query in endpoint url to hide acf values from the response where applicable (all collections)
* Add: Media query in endpoint url to hide featured media from the response where applicable (all collections)
Expand Down

0 comments on commit 1001923

Please sign in to comment.