Skip to content

Commit 2a47c51

Browse files
committed
Merge branch 'develop'
2 parents 438edde + 3f8dd1f commit 2a47c51

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

better-wp-endpoints.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Better WordPress Endpoints
44
Plugin URI: https://github.com/factor1/better-wp-endpoints/
55
Description: Serves up slimmer WordPress Rest API endpoints, with some great enhancements.
6-
Version: 0.1.22
6+
Version: 0.1.23
77
Author: Eric Stout, Factor1 Studios
88
Author URI: https://factor1studios.com/
99
License: GPL3

includes/get_page_by_id.php

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function get_page_by_id( WP_REST_Request $request ){
2121
if( $query->have_posts() ){
2222
while( $query->have_posts() ) {
2323
$query->the_post();
24+
global $post;
2425

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

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

50+
/*
51+
*
52+
* return parent slug if it exists
53+
*
54+
*/
55+
$parents = get_post_ancestors( $post->ID );
56+
/* Get the top Level page->ID count base 1, array base 0 so -1 */
57+
$id = ($parents) ? $parents[count($parents)-1]: $post->ID;
58+
/* Get the parent and set the $class with the page slug (post_name) */
59+
$parent = get_post( $id );
60+
$bwe_page->parent = $parent->post_name != $post->post_name ? $parent->post_name : false;
4961

5062
/*
5163
*

includes/get_pages.php

+14
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function bwe_get_pages( WP_REST_Request $request ) {
4343
while( $query->have_posts() ) {
4444
$query->the_post();
4545

46+
global $post;
47+
4648
// better wordpress endpoint page object
4749
$bwe_page = new stdClass();
4850

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

75+
/*
76+
*
77+
* return parent slug if it exists
78+
*
79+
*/
80+
$parents = get_post_ancestors( $post->ID );
81+
/* Get the top Level page->ID count base 1, array base 0 so -1 */
82+
$id = ($parents) ? $parents[count($parents)-1]: $post->ID;
83+
/* Get the parent and set the $class with the page slug (post_name) */
84+
$parent = get_post( $id );
85+
$bwe_page->parent = $parent->post_name != $post->post_name ? $parent->post_name : false;
86+
7387

7488
// show post content unless parameter is false
7589
if( $show_content === 'true' ) {

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "better-wp-endpoints",
3-
"version": "0.1.22",
3+
"version": "0.1.23",
44
"description": "Serves up slimmer WordPress Rest API endpoints.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)