Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
erwstout committed Dec 11, 2017
2 parents 438edde + 3f8dd1f commit 2a47c51
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion better-wp-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.22
Version: 0.1.23
Author: Eric Stout, Factor1 Studios
Author URI: https://factor1studios.com/
License: GPL3
Expand Down
12 changes: 12 additions & 0 deletions includes/get_page_by_id.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function get_page_by_id( WP_REST_Request $request ){
if( $query->have_posts() ){
while( $query->have_posts() ) {
$query->the_post();
global $post;

// better wordpress endpoint post object
$bwe_page = new stdClass();
Expand All @@ -46,6 +47,17 @@ function get_page_by_id( WP_REST_Request $request ){

$bwe_page->content = apply_filters('the_content', get_the_content());

/*
*
* return parent slug if it exists
*
*/
$parents = get_post_ancestors( $post->ID );
/* Get the top Level page->ID count base 1, array base 0 so -1 */
$id = ($parents) ? $parents[count($parents)-1]: $post->ID;
/* Get the parent and set the $class with the page slug (post_name) */
$parent = get_post( $id );
$bwe_page->parent = $parent->post_name != $post->post_name ? $parent->post_name : false;

/*
*
Expand Down
14 changes: 14 additions & 0 deletions includes/get_pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function bwe_get_pages( WP_REST_Request $request ) {
while( $query->have_posts() ) {
$query->the_post();

global $post;

// better wordpress endpoint page object
$bwe_page = new stdClass();

Expand Down Expand Up @@ -70,6 +72,18 @@ function bwe_get_pages( WP_REST_Request $request ) {
$bwe_page->template = 'default';
}

/*
*
* return parent slug if it exists
*
*/
$parents = get_post_ancestors( $post->ID );
/* Get the top Level page->ID count base 1, array base 0 so -1 */
$id = ($parents) ? $parents[count($parents)-1]: $post->ID;
/* Get the parent and set the $class with the page slug (post_name) */
$parent = get_post( $id );
$bwe_page->parent = $parent->post_name != $post->post_name ? $parent->post_name : false;


// show post content unless parameter is false
if( $show_content === 'true' ) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "better-wp-endpoints",
"version": "0.1.22",
"version": "0.1.23",
"description": "Serves up slimmer WordPress Rest API endpoints.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 2a47c51

Please sign in to comment.