Skip to content
This repository has been archived by the owner on Sep 24, 2018. It is now read-only.

Commit

Permalink
post 'parent' value should be null rather than zero if unset
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
maxcutler committed Aug 1, 2014
1 parent 8a035d2 commit 7d6f6dd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/class-wp-json-posts.php
Expand Up @@ -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
Expand Down

0 comments on commit 7d6f6dd

Please sign in to comment.