From 19024e1b469aaa60da9d1f30c0cd484b84854df1 Mon Sep 17 00:00:00 2001 From: Max Cutler Date: Fri, 1 Aug 2014 13:31:51 -0400 Subject: [PATCH] post 'parent' value should be null rather than zero if unset Having a field be either an integer or a nested object makes parsing more complicated. Furthermore, knowing that a parent ID of "0" means that a post has no parent is WordPress inside knowledge that should not leak through the API. --- lib/class-wp-json-posts.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/class-wp-json-posts.php b/lib/class-wp-json-posts.php index f9f936197b..1cefcf9bed 100644 --- a/lib/class-wp-json-posts.php +++ b/lib/class-wp-json-posts.php @@ -786,6 +786,10 @@ protected function prepare_post( $post, $context = 'view' ) { if ( empty( $post_fields['format'] ) ) { $post_fields['format'] = 'standard'; } + + if ( 0 === $post['post_parent'] ) { + $post_fields['parent'] = null; + } if ( ( 'view' === $context || 'view-revision' == $context ) && 0 !== $post['post_parent'] ) { // Avoid nesting too deeply