From 51e0f22566b70d32145fd514dccb7c2a5c6f39e9 Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 11:36:23 -0700 Subject: [PATCH 01/18] Add exclude to get_posts_tax --- includes/get_posts_tax.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/get_posts_tax.php b/includes/get_posts_tax.php index f201ff6..f9f716b 100644 --- a/includes/get_posts_tax.php +++ b/includes/get_posts_tax.php @@ -37,6 +37,7 @@ function bwe_build_custom_tax_endpoint() { $page = $request['page']?: '1'; $show_content = $request['content']?: 'true'; $orderby = $request['orderby']? : null; + $exclude = $request['exclude']?: null; // WP_Query Arguments $args = array( @@ -50,7 +51,8 @@ function bwe_build_custom_tax_endpoint() { 'field' => 'slug' ) ), - 'orderby' => $orderby + 'orderby' => $orderby, + 'post__not_in' => array($exclude) ); // The Query From 344b39c8ae004c91ef558500c7dafdeddde52a7d Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 11:39:26 -0700 Subject: [PATCH 02/18] Add exclude callbacks --- README.md | 3 ++- includes/get_posts_tax.php | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 528d2df..6417c26 100644 --- a/README.md +++ b/README.md @@ -158,12 +158,13 @@ Returns the following JSON Response: ### Get Posts Belonging To A Taxonomy Term **`better-wp-endpoints/v1/{taxonomy}/{term}`** -Gets posts from a taxonomy term. Accepts rthe following parameters: +Gets posts from a taxonomy term. Accepts the following parameters: - per_page (int) - page (int) - content (boolean - setting to false omits `the_content` from being returned) - orderby (string) - see the [codex](https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters) for options, currently does not support multiple values +- exclude (int) a post ID to exclude from the response Returns the following JSON Response: diff --git a/includes/get_posts_tax.php b/includes/get_posts_tax.php index f9f716b..3a0120c 100644 --- a/includes/get_posts_tax.php +++ b/includes/get_posts_tax.php @@ -185,6 +185,14 @@ function bwe_build_custom_tax_endpoint() { }, 'sanitize_callback' => 'sanitize_text_field' ), + 'exclude' => array( + 'description' => 'Exclude a post by ID.', + 'type' => 'integer', + 'validate_callback' => function( $param, $request, $key ) { + return is_numeric( $param ); + }, + 'sanitize_callback' => 'absint' + ), ), )); } From 4820bc350e2d0d11d5f61bee42655d825eb29a97 Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 12:17:22 -0700 Subject: [PATCH 03/18] Add exclude to cpt endpoints --- README.md | 1 + copy.js | 2 +- includes/create_cpt_endpoints.php | 10 ++++++++++ includes/get_posts.php | 8 ++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6417c26..b8a0053 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ Gets a collection of posts from a custom post type. Accepts the following parame - page (int) - content (boolean - setting to false omits `the_content` from being returned) - orderby (string) - see the [codex](https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters) for options, currently does not support multiple values +- exclude (int) a post ID to exclude from the response Returns the following JSON response: diff --git a/copy.js b/copy.js index 0caa9ca..15c2004 100644 --- a/copy.js +++ b/copy.js @@ -1,5 +1,5 @@ const fs = require('fs-extra'), - target = '/Users/ericstout/Documents/projects/tallwave/app/public/wp-content/plugins/better-wp-endpoints', + target = '/Users/ericstout/Documents/projects/better-wp-endpoints-wp/app/public/wp-content/plugins/better-wp-endpoints', files = './'; fs.copy(files, target) diff --git a/includes/create_cpt_endpoints.php b/includes/create_cpt_endpoints.php index 36727d5..32b90f9 100644 --- a/includes/create_cpt_endpoints.php +++ b/includes/create_cpt_endpoints.php @@ -28,6 +28,7 @@ function bwe_build_cpt_endpoints() { $page = $request['page']?: '1'; $show_content = $request['content']?: 'true'; $orderby = $request['orderby']? : null; + $exclude = $request['exclude']?: null; // WP_Query arguments $args = array( @@ -35,6 +36,7 @@ function bwe_build_cpt_endpoints() { 'nopaging' => false, 'posts_per_page' => $posts_per_page, 'paged' => $page, + 'post__not_in' => array($exclude), 'orderby' => $orderby ); @@ -170,6 +172,14 @@ function bwe_build_cpt_endpoints() { }, 'sanitize_callback' => 'sanitize_text_field' ), + 'exclude' => array( + 'description' => 'Exclude a post by ID.', + 'type' => 'integer', + 'validate_callback' => function( $param, $request, $key ) { + return is_numeric( $param ); + }, + 'sanitize_callback' => 'absint' + ), ), ) ); diff --git a/includes/get_posts.php b/includes/get_posts.php index 5828111..a5b5659 100644 --- a/includes/get_posts.php +++ b/includes/get_posts.php @@ -196,6 +196,14 @@ function bwe_get_posts( WP_REST_Request $request ) { }, 'sanitize_callback' => 'absint' ), + 'exclude' => array( + 'description' => 'Exclude a post by ID.', + 'type' => 'integer', + 'validate_callback' => function( $param, $request, $key ) { + return is_numeric( $param ); + }, + 'sanitize_callback' => 'absint' + ), 'content' => array( 'description' => 'Hide or show the_content from the collection.', 'type' => 'boolean', From b48cd645e7eaa0854707c8c00a26df3abc2a2a9b Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 13:16:28 -0700 Subject: [PATCH 04/18] Add exclude to get_pages and update doc --- README.md | 1 + includes/get_pages.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b8a0053..761588c 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ Gets a collection of pages. Accepts the following parameters: - per_page (int) - page (int) - content (boolean - setting to false hides the content from the response) +- exclude (int) a post ID to exclude from the response Returns the following JSON Response: diff --git a/includes/get_pages.php b/includes/get_pages.php index ab571ad..27ff4c1 100644 --- a/includes/get_pages.php +++ b/includes/get_pages.php @@ -25,7 +25,8 @@ function bwe_get_pages( WP_REST_Request $request ) { 'posts_per_page' => $posts_per_page, 'paged' => $page, 'order' => $order?:'DESC', - 'orderby' => $orderby?:'date' + 'orderby' => $orderby?:'date', + 'post__not_in' => array($exclude), ); $query = new WP_Query( $args ); From 36e112563f32ab0372b0b6a79e6a63fd7fa1f747 Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 13:25:56 -0700 Subject: [PATCH 05/18] Add order and orderby params in relation to issue #5 --- includes/create_cpt_endpoints.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/includes/create_cpt_endpoints.php b/includes/create_cpt_endpoints.php index 32b90f9..3514bff 100644 --- a/includes/create_cpt_endpoints.php +++ b/includes/create_cpt_endpoints.php @@ -27,7 +27,8 @@ function bwe_build_cpt_endpoints() { $posts_per_page = $request['per_page']?: '10'; $page = $request['page']?: '1'; $show_content = $request['content']?: 'true'; - $orderby = $request['orderby']? : null; + $orderby = $request['orderby']?: null; + $order = $request['order']?: null; $exclude = $request['exclude']?: null; // WP_Query arguments @@ -37,7 +38,8 @@ function bwe_build_cpt_endpoints() { 'posts_per_page' => $posts_per_page, 'paged' => $page, 'post__not_in' => array($exclude), - 'orderby' => $orderby + 'order' => $order?:'DESC', + 'orderby' => $orderby?:'date' ); // The Query @@ -164,6 +166,14 @@ function bwe_build_cpt_endpoints() { return is_bool( $param ); } ), + 'order' => array( + 'description' => 'Change order of the collection.', + 'type' => 'string', + 'validate_callback' => function($param, $request, $key) { + return is_string( $param ); + }, + 'sanitize_callback' => 'sanitize_text_field', + ), 'orderby' => array( 'description' => 'The sort order of the collection.', 'type' => 'string', From 5002e7e813a9c8ca2dfb42536e68e8a65fa65a4c Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 13:27:37 -0700 Subject: [PATCH 06/18] Remove commented code --- includes/get_posts_tax.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/get_posts_tax.php b/includes/get_posts_tax.php index 3a0120c..0a7369e 100644 --- a/includes/get_posts_tax.php +++ b/includes/get_posts_tax.php @@ -13,8 +13,6 @@ function bwe_build_custom_tax_endpoint() { // store the custom tax collections we have $custom_tax_collection = bwe_get_custom_tax(); - //print_r($custom_tax_collection); - foreach ($custom_tax_collection as $key => $tax) { $tax_terms = get_terms(array( From c83e5ff879f39d6b8d4bfd6d95641c6ae8b06af5 Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 13:28:37 -0700 Subject: [PATCH 07/18] Add order, orderby per issue #5 --- includes/get_posts_tax.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/includes/get_posts_tax.php b/includes/get_posts_tax.php index 0a7369e..5d0aa5d 100644 --- a/includes/get_posts_tax.php +++ b/includes/get_posts_tax.php @@ -34,7 +34,8 @@ function bwe_build_custom_tax_endpoint() { $posts_per_page = $request['per_page']?: '10'; $page = $request['page']?: '1'; $show_content = $request['content']?: 'true'; - $orderby = $request['orderby']? : null; + $orderby = $request['orderby']?: null; + $order = $request['order']?: null; $exclude = $request['exclude']?: null; // WP_Query Arguments @@ -49,7 +50,8 @@ function bwe_build_custom_tax_endpoint() { 'field' => 'slug' ) ), - 'orderby' => $orderby, + 'order' => $order?:'DESC', + 'orderby' => $orderby?:'date', 'post__not_in' => array($exclude) ); @@ -175,6 +177,14 @@ function bwe_build_custom_tax_endpoint() { return is_bool( $param ); } ), + 'order' => array( + 'description' => 'Change order of the collection.', + 'type' => 'string', + 'validate_callback' => function($param, $request, $key) { + return is_string( $param ); + }, + 'sanitize_callback' => 'sanitize_text_field', + ), 'orderby' => array( 'description' => 'The sort order of the collection.', 'type' => 'string', From 1c88e0615b5b3ac76b15f7c3d94aaf96d2fc20bd Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 13:56:33 -0700 Subject: [PATCH 08/18] Initial commit of taxonomies endpoint per issue #3 --- better-wp-endpoints.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/better-wp-endpoints.php b/better-wp-endpoints.php index c6ad22a..526ee46 100644 --- a/better-wp-endpoints.php +++ b/better-wp-endpoints.php @@ -109,6 +109,9 @@ private function includes() { // get search endpoint include_once self::$plugin_dir . 'includes/get_search.php'; + + // get taxonomies endpoint + include_once self::$plugin_dir . 'includes/get_taxonomies.php'; } } From 672bbfe0507327d42648a1cf5adaa2141275c2b4 Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 13:56:40 -0700 Subject: [PATCH 09/18] Initial commit of taxonomies endpoint per issue #3 --- includes/get_taxonomies.php | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 includes/get_taxonomies.php diff --git a/includes/get_taxonomies.php b/includes/get_taxonomies.php new file mode 100644 index 0000000..4cc0884 --- /dev/null +++ b/includes/get_taxonomies.php @@ -0,0 +1,50 @@ +name = $tax->label; + $bwe_tax_obj->slug = $tax->name; + $bwe_tax_obj->description = $tax->description; + $bwe_tax_obj->hierarchical = $tax->hierarchical; + + // push the data to the array + array_push($bwe_taxonomies, $bwe_tax_obj); + } + + /* + * + * Register Rest API Endpoint + * + */ + + register_rest_route( 'better-wp-endpoints/v1', '/taxonomies/', array( + 'methods' => 'GET', + 'callback' => function ( WP_REST_Request $request ) use($bwe_taxonomies) { + return $bwe_taxonomies; + }, + )); +} + +/* + * + * Add action for taxonomies + * + */ +add_action( 'rest_api_init', 'bwe_get_taxonomies' ); From f34f05e01666e2830971c6aa0868dd6244bb9dde Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 14:11:27 -0700 Subject: [PATCH 10/18] Add documentation for taxonomies endpoint, close #3 --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 761588c..87a6370 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,17 @@ Returns the following JSON Response in each item object: - classes (array) - menu item parent +### Taxonomies +**`better-wp-endpoints/v1/taxonomies`** +Gets a list of taxonomies used by WordPress. Accepts no parameters. + +Returns the following JSON response in each item object: + +- Name +- Slug +- Description +- Hierarchical (true/false) + ### Search **`better-wp-endpoints/v1/search`** Gets a collection of posts and pages based on the search parameter. Accepts the following parameters: From 232e6736a5a4d63ae7fe82b7accdf7838a68c734 Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 15:36:58 -0700 Subject: [PATCH 11/18] Fix content param on posts from issue #6 --- includes/get_posts.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/includes/get_posts.php b/includes/get_posts.php index a5b5659..7d3e329 100644 --- a/includes/get_posts.php +++ b/includes/get_posts.php @@ -15,7 +15,8 @@ function bwe_get_posts( WP_REST_Request $request ) { $category = $request['category']?: null; $category_name = $request['category_name']?: ''; $tag = $request['tag']?: null; - $show_content = $request['content']?: true; + $content = $request['content']; + $show_content = filter_var($content, FILTER_VALIDATE_BOOLEAN); $orderby = $request['orderby']?: null; $order = $request['order']?: null; $exclude = $request['exclude']?: null; @@ -61,7 +62,7 @@ function bwe_get_posts( WP_REST_Request $request ) { $bwe_post->excerpt = get_the_excerpt(); // show post content unless parameter is false - if( $show_content == true ) { + if( $content === null || $show_content === true ) { $bwe_post->content = apply_filters('the_content', get_the_content()); } @@ -210,12 +211,14 @@ function bwe_get_posts( WP_REST_Request $request ) { 'validate_callback' => function( $param, $request, $key ) { if ( $param == 'true' || $param == 'TRUE' ) { - $param = true; + // $param = true; + $status = true; } else if( $param == 'false' || $param == 'FALSE') { - $param = false; + //$param = false; + $status = false; } - return is_bool( $param ); + return is_bool( $status ); } ), 'order' => array( From 76a8f54d8d8bb8b040702996992c78fb48599f9e Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 15:58:20 -0700 Subject: [PATCH 12/18] Add content param to cpt endpoints per issue #6 --- includes/create_cpt_endpoints.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/create_cpt_endpoints.php b/includes/create_cpt_endpoints.php index 3514bff..ca51892 100644 --- a/includes/create_cpt_endpoints.php +++ b/includes/create_cpt_endpoints.php @@ -26,7 +26,8 @@ function bwe_build_cpt_endpoints() { // check for params $posts_per_page = $request['per_page']?: '10'; $page = $request['page']?: '1'; - $show_content = $request['content']?: 'true'; + $content = $request['content']; + $show_content = filter_var($content, FILTER_VALIDATE_BOOLEAN); $orderby = $request['orderby']?: null; $order = $request['order']?: null; $exclude = $request['exclude']?: null; @@ -69,7 +70,7 @@ function bwe_build_cpt_endpoints() { $bwe_post->excerpt = get_the_excerpt(); // show post content unless parameter is false - if( $show_content === 'true' ) { + if( $content === null || $show_content === true ) { $bwe_post->content = apply_filters('the_content', get_the_content()); } From b78cc385d0322778866dd6df5393a0685015564c Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 16:00:38 -0700 Subject: [PATCH 13/18] Add working content param to pages per issue #6 --- includes/get_pages.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/includes/get_pages.php b/includes/get_pages.php index 27ff4c1..9372645 100644 --- a/includes/get_pages.php +++ b/includes/get_pages.php @@ -13,7 +13,8 @@ function bwe_get_pages( WP_REST_Request $request ) { // check for params $posts_per_page = $request['per_page']?: '10'; $page = $request['page']?: '1'; - $show_content = $request['content']?: 'true'; + $content = $request['content']; + $show_content = filter_var($content, FILTER_VALIDATE_BOOLEAN); $orderby = $request['orderby']?: null; $order = $request['order']?: null; $exclude = $request['exclude']?: null; @@ -87,7 +88,7 @@ function bwe_get_pages( WP_REST_Request $request ) { // show post content unless parameter is false - if( $show_content === 'true' ) { + if( $content === null || $show_content === true ) { $bwe_page->content = apply_filters('the_content', get_the_content()); } @@ -187,6 +188,22 @@ function bwe_get_pages( WP_REST_Request $request ) { }, 'sanitize_callback' => 'sanitize_text_field', ), + 'content' => array( + 'description' => 'Hide or show the_content from the collection.', + 'type' => 'boolean', + 'validate_callback' => function( $param, $request, $key ) { + + if ( $param == 'true' || $param == 'TRUE' ) { + // $param = true; + $status = true; + } else if( $param == 'false' || $param == 'FALSE') { + //$param = false; + $status = false; + } + + return is_bool( $status ); + } + ), ), ) ); } ); From bfdf5a4e06e6fc7ac9fc6024323e3c4ebeebeb0c Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 16:01:52 -0700 Subject: [PATCH 14/18] Add working content param to posts by tax, issue #6 --- includes/get_posts_tax.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/get_posts_tax.php b/includes/get_posts_tax.php index 5d0aa5d..7071692 100644 --- a/includes/get_posts_tax.php +++ b/includes/get_posts_tax.php @@ -33,7 +33,8 @@ function bwe_build_custom_tax_endpoint() { // check for params $posts_per_page = $request['per_page']?: '10'; $page = $request['page']?: '1'; - $show_content = $request['content']?: 'true'; + $content = $request['content']; + $show_content = filter_var($content, FILTER_VALIDATE_BOOLEAN); $orderby = $request['orderby']?: null; $order = $request['order']?: null; $exclude = $request['exclude']?: null; @@ -79,7 +80,7 @@ function bwe_build_custom_tax_endpoint() { $bwe_tax_post->date = get_the_date('c'); $bwe_tax_post->excerpt = get_the_excerpt(); - if( $show_content ){ + if( $content === null || $show_content === true ){ $bwe_tax_post->content = apply_filters('the_content', get_the_content()); } From 895763b64aee401d78e77e8fffefb3b8d72f310d Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 16:08:35 -0700 Subject: [PATCH 15/18] Add working content param to search endpoint, issue #6 --- includes/get_search.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/get_search.php b/includes/get_search.php index c710591..481f887 100644 --- a/includes/get_search.php +++ b/includes/get_search.php @@ -14,7 +14,8 @@ function bwe_get_search( WP_REST_Request $request ) { $page = $request['page']?: '1'; $category = $request['category']?: null; $tag = $request['tag']?: null; - $show_content = $request['content']?: true; + $content = $request['content']; + $show_content = filter_var($content, FILTER_VALIDATE_BOOLEAN); $search = $request['search']?: null; // WP_Query arguments @@ -53,7 +54,7 @@ function bwe_get_search( WP_REST_Request $request ) { $bwe_post->excerpt = get_the_excerpt(); // show post content unless parameter is false - if( $show_content == true ) { + if( $content === null || $show_content === true ) { $bwe_post->content = apply_filters('the_content', get_the_content()); } From b76b0900200f5e8117fc82b5e6890b59d4f0365d Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 16:17:41 -0700 Subject: [PATCH 16/18] Bump plugin version --- better-wp-endpoints.php | 2 +- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/better-wp-endpoints.php b/better-wp-endpoints.php index 526ee46..c9826ca 100644 --- a/better-wp-endpoints.php +++ b/better-wp-endpoints.php @@ -3,7 +3,7 @@ Plugin Name: Better WordPress Endpoints Plugin URI: https://github.com/factor1/better-wp-endpoints/ Description: Serves up slimmer WordPress Rest API endpoints, with some great enhancements. -Version: 0.1.23 +Version: 0.2.0 Author: Eric Stout, Factor1 Studios Author URI: https://factor1studios.com/ License: GPL3 diff --git a/package-lock.json b/package-lock.json index 00be7b7..a0ca7d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "better-wp-endpoints", - "version": "0.1.23", + "version": "0.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 19f2d33..fcf08f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "better-wp-endpoints", - "version": "0.1.23", + "version": "0.2.0", "description": "Serves up slimmer WordPress Rest API endpoints.", "main": "index.js", "scripts": { From 3c795ef62256f7eb2d0818a612db4b2d288f758c Mon Sep 17 00:00:00 2001 From: Eric Stout Date: Thu, 11 Jan 2018 16:25:09 -0700 Subject: [PATCH 17/18] Rename plugin instances --- better-wp-endpoints.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/better-wp-endpoints.php b/better-wp-endpoints.php index c9826ca..4a51d38 100644 --- a/better-wp-endpoints.php +++ b/better-wp-endpoints.php @@ -1,6 +1,6 @@ Date: Thu, 11 Jan 2018 16:26:35 -0700 Subject: [PATCH 18/18] Rename all instances of better-wp-endpoints to better-rest-endpoints --- README.md | 24 ++++++++++++------------ better-wp-endpoints.php | 4 ++-- copy.js | 2 +- includes/create_cpt_endpoints.php | 2 +- includes/get_cpt_by_id.php | 2 +- includes/get_cpt_by_slug.php | 2 +- includes/get_page_by_id.php | 2 +- includes/get_pages.php | 2 +- includes/get_post_by_id.php | 2 +- includes/get_posts.php | 2 +- includes/get_posts_tax.php | 2 +- includes/get_search.php | 2 +- includes/get_taxonomies.php | 2 +- includes/wp_nav_menus.php | 2 +- package-lock.json | 2 +- package.json | 8 ++++---- 16 files changed, 31 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 87a6370..f006a84 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# better-wp-endpoints +# better-rest-endpoints A WordPress plugin that serves up slimmer WP Rest API endpoints - WIP ## Endpoints ### Posts -**`better-wp-endpoints/v1/posts`** +**`better-rest-endpoints/v1/posts`** Gets a collection of posts. Accepts the following parameters: - page (int) @@ -34,7 +34,7 @@ It returns a JSON response with the following: - ACF fields, if applicable ### Post -**`better-wp-endpoints/v1/post/{id}`** +**`better-rest-endpoints/v1/post/{id}`** Get a post by ID. Accepts the following parameters: @@ -58,7 +58,7 @@ Returns a JSON response with the following: - ACF fields, if applicable ### Pages -**`better-wp-endpoints/v1/pages`** +**`better-rest-endpoints/v1/pages`** Gets a collection of pages. Accepts the following parameters: - exclude (int) @@ -80,7 +80,7 @@ Returns the following JSON Response: - all possible thumbnail sizes & URLs ### Page by ID -**`better-wp-endpoints/v1/page/{id}`** +**`better-rest-endpoints/v1/page/{id}`** Get a page by ID. Accepts the following parameters: @@ -98,7 +98,7 @@ Returns a JSON response with the following: - ACF fields, if applicable ### Custom Post Type Collection -**`better-wp-endpoints/v1/{custom_post_type}`** +**`better-rest-endpoints/v1/{custom_post_type}`** Gets a collection of posts from a custom post type. Accepts the following parameters: - per_page (int) @@ -121,7 +121,7 @@ Returns the following JSON response: - ACF fields if applicable ### Custom Post Type Post by ID -**`better-wp-endpoints/v1/{custom_post_type}/{id}`** +**`better-rest-endpoints/v1/{custom_post_type}/{id}`** Gets a single custom post type item. Accepts the following parameters: - ID @@ -140,7 +140,7 @@ Returns the following JSON Response: - ACF Fields, if applicable ### Custom Post Type Post by Slug -**`better-wp-endpoints/v1/{custom_post_type}/{slug}`** +**`better-rest-endpoints/v1/{custom_post_type}/{slug}`** Gets a single custom post type item. Accepts the following parameters: - slug @@ -159,7 +159,7 @@ Returns the following JSON Response: - ACF Fields, if applicable ### Get Posts Belonging To A Taxonomy Term -**`better-wp-endpoints/v1/{taxonomy}/{term}`** +**`better-rest-endpoints/v1/{taxonomy}/{term}`** Gets posts from a taxonomy term. Accepts the following parameters: - per_page (int) @@ -182,7 +182,7 @@ Returns the following JSON Response: - ACF Fields, if applicable ### Menus -**`better-wp-endpoints/v1/menus/{menu-slug}`** +**`better-rest-endpoints/v1/menus/{menu-slug}`** Gets a WordPress Menu by slug. Accepts no parameters. Returns the following JSON Response in each item object: @@ -198,7 +198,7 @@ Returns the following JSON Response in each item object: - menu item parent ### Taxonomies -**`better-wp-endpoints/v1/taxonomies`** +**`better-rest-endpoints/v1/taxonomies`** Gets a list of taxonomies used by WordPress. Accepts no parameters. Returns the following JSON response in each item object: @@ -209,7 +209,7 @@ Returns the following JSON response in each item object: - Hierarchical (true/false) ### Search -**`better-wp-endpoints/v1/search`** +**`better-rest-endpoints/v1/search`** Gets a collection of posts and pages based on the search parameter. Accepts the following parameters: - page (int) diff --git a/better-wp-endpoints.php b/better-wp-endpoints.php index 4a51d38..90613b6 100644 --- a/better-wp-endpoints.php +++ b/better-wp-endpoints.php @@ -1,14 +1,14 @@ 'GET', 'callback' => function ( WP_REST_Request $request ) use($cpt) { diff --git a/includes/get_cpt_by_id.php b/includes/get_cpt_by_id.php index 480e8e4..37bf1ec 100644 --- a/includes/get_cpt_by_id.php +++ b/includes/get_cpt_by_id.php @@ -20,7 +20,7 @@ function bwe_build_single_cpt_endpoints() { * Register Rest API Endpoint * */ - register_rest_route( 'better-wp-endpoints/v1', '/'.$cpt.'/(?P\d+)', array( + register_rest_route( 'better-rest-endpoints/v1', '/'.$cpt.'/(?P\d+)', array( 'methods' => 'GET', 'callback' => function ( WP_REST_Request $request ) use ($cpt) { diff --git a/includes/get_cpt_by_slug.php b/includes/get_cpt_by_slug.php index d3a4ea1..5f1ec43 100644 --- a/includes/get_cpt_by_slug.php +++ b/includes/get_cpt_by_slug.php @@ -20,7 +20,7 @@ function bwe_build_single_cpt_endpoints_slug() { * Register Rest API Endpoint * */ - register_rest_route( 'better-wp-endpoints/v1', '/'.$cpt.'/(?P\S+)', array( + register_rest_route( 'better-rest-endpoints/v1', '/'.$cpt.'/(?P\S+)', array( 'methods' => 'GET', 'callback' => function ( WP_REST_Request $request ) use ($cpt) { diff --git a/includes/get_page_by_id.php b/includes/get_page_by_id.php index 2a5faa1..a9095e4 100644 --- a/includes/get_page_by_id.php +++ b/includes/get_page_by_id.php @@ -98,7 +98,7 @@ function get_page_by_id( WP_REST_Request $request ){ } add_action( 'rest_api_init', function () { - register_rest_route( 'better-wp-endpoints/v1', '/page/(?P\d+)', array( + register_rest_route( 'better-rest-endpoints/v1', '/page/(?P\d+)', array( 'methods' => 'GET', 'callback' => 'get_page_by_id', ) ); diff --git a/includes/get_pages.php b/includes/get_pages.php index 9372645..9eff0a5 100644 --- a/includes/get_pages.php +++ b/includes/get_pages.php @@ -144,7 +144,7 @@ function bwe_get_pages( WP_REST_Request $request ) { * */ add_action( 'rest_api_init', function () { - register_rest_route( 'better-wp-endpoints/v1', '/pages/', array( + register_rest_route( 'better-rest-endpoints/v1', '/pages/', array( 'methods' => 'GET', 'callback' => 'bwe_get_pages', 'args' => array( diff --git a/includes/get_post_by_id.php b/includes/get_post_by_id.php index 43ea20f..f456d77 100644 --- a/includes/get_post_by_id.php +++ b/includes/get_post_by_id.php @@ -115,7 +115,7 @@ function get_post_by_id( $data ) { } add_action( 'rest_api_init', function () { - register_rest_route( 'better-wp-endpoints/v1', '/post/(?P\d+)', array( + register_rest_route( 'better-rest-endpoints/v1', '/post/(?P\d+)', array( 'methods' => 'GET', 'callback' => 'get_post_by_id', ) ); diff --git a/includes/get_posts.php b/includes/get_posts.php index 7d3e329..0087dff 100644 --- a/includes/get_posts.php +++ b/includes/get_posts.php @@ -161,7 +161,7 @@ function bwe_get_posts( WP_REST_Request $request ) { * */ add_action( 'rest_api_init', function () { - register_rest_route( 'better-wp-endpoints/v1', '/posts/', array( + register_rest_route( 'better-rest-endpoints/v1', '/posts/', array( 'methods' => 'GET', 'callback' => 'bwe_get_posts', 'args' => array( diff --git a/includes/get_posts_tax.php b/includes/get_posts_tax.php index 7071692..5358002 100644 --- a/includes/get_posts_tax.php +++ b/includes/get_posts_tax.php @@ -26,7 +26,7 @@ function bwe_build_custom_tax_endpoint() { * Register Rest API Endpoint * */ - register_rest_route( 'better-wp-endpoints/v1', '/'.$tax.'/'.$tax_term->slug.'/', array( + register_rest_route( 'better-rest-endpoints/v1', '/'.$tax.'/'.$tax_term->slug.'/', array( 'methods' => 'GET', 'callback' => function ( WP_REST_Request $request ) use ($tax, $tax_term) { diff --git a/includes/get_search.php b/includes/get_search.php index 481f887..1b2fc91 100644 --- a/includes/get_search.php +++ b/includes/get_search.php @@ -153,7 +153,7 @@ function bwe_get_search( WP_REST_Request $request ) { * */ add_action( 'rest_api_init', function () { - register_rest_route( 'better-wp-endpoints/v1', '/search/', array( + register_rest_route( 'better-rest-endpoints/v1', '/search/', array( 'methods' => 'GET', 'callback' => 'bwe_get_search', 'args' => array( diff --git a/includes/get_taxonomies.php b/includes/get_taxonomies.php index 4cc0884..6993059 100644 --- a/includes/get_taxonomies.php +++ b/includes/get_taxonomies.php @@ -34,7 +34,7 @@ function bwe_get_taxonomies() { * */ - register_rest_route( 'better-wp-endpoints/v1', '/taxonomies/', array( + register_rest_route( 'better-rest-endpoints/v1', '/taxonomies/', array( 'methods' => 'GET', 'callback' => function ( WP_REST_Request $request ) use($bwe_taxonomies) { return $bwe_taxonomies; diff --git a/includes/wp_nav_menus.php b/includes/wp_nav_menus.php index 2920ba1..66666e5 100644 --- a/includes/wp_nav_menus.php +++ b/includes/wp_nav_menus.php @@ -46,7 +46,7 @@ function bwe_get_menus() { * */ - register_rest_route( 'better-wp-endpoints/v1', '/menus/'.$menu->slug.'/', array( + register_rest_route( 'better-rest-endpoints/v1', '/menus/'.$menu->slug.'/', array( 'methods' => 'GET', 'callback' => function ( WP_REST_Request $request ) use($slim_menu_items) { return $slim_menu_items; diff --git a/package-lock.json b/package-lock.json index a0ca7d6..990b9ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "better-wp-endpoints", + "name": "better-rest-endpoints", "version": "0.2.0", "lockfileVersion": 1, "requires": true, diff --git a/package.json b/package.json index fcf08f5..e27276d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "better-wp-endpoints", + "name": "better-rest-endpoints", "version": "0.2.0", "description": "Serves up slimmer WordPress Rest API endpoints.", "main": "index.js", @@ -9,7 +9,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/factor1/better-wp-endpoints.git" + "url": "git+https://github.com/factor1/better-rest-endpoints.git" }, "keywords": [ "WordPress", @@ -24,9 +24,9 @@ "author": "Eric Stout", "license": "GPL-3.0", "bugs": { - "url": "https://github.com/factor1/better-wp-endpoints/issues" + "url": "https://github.com/factor1/better-rest-endpoints/issues" }, - "homepage": "https://github.com/factor1/better-wp-endpoints#readme", + "homepage": "https://github.com/factor1/better-rest-endpoints#readme", "devDependencies": { "fs-extra": "^4.0.2" }