Skip to content

Loading…

Undefined index errors for /wp-json.php/posts/POST_ID/comments #5

Merged
merged 2 commits into from

2 participants

@pippinsplugins

Fixes the first issue described on GSoC #382: http://gsoc.trac.wordpress.org/ticket/382

There are undefined index errors thrown in the prepare_comment() function due to $post never being defined.

There is also an instance of $post->comment_date_gmt that is supposed to be $comment->comment_date_gmt.

Adding $post = (array) get_post( $fields['post'] ); at line 966 of class=wp-json-posts.php fixes the undefined index.

And changing line 1033 of class-wp-json-posts.php from$fields['date_gmt'] = date( 'c', strtotime( $post->comment_date_gmt ) ); to $fields['date_gmt'] = date( 'c', strtotime( $comment->comment_date_gmt ) ); fixes the second issue.

@rmccue rmccue merged commit c5251c2 into WP-API:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 9, 2013
  1. @pippinsplugins

    Fix undefined variable

    pippinsplugins committed
  2. @pippinsplugins
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/class-wp-json-posts.php
View
4 lib/class-wp-json-posts.php
@@ -963,6 +963,8 @@ protected function prepare_comment( $comment, $requested_fields = array( 'commen
'post' => (int) $comment->comment_post_ID,
);
+ $post = (array) get_post( $fields['post'] );
+
// Content
$fields['content'] = apply_filters( 'comment_text', $comment->comment_content, $comment );
// $fields['content_raw'] = $comment->comment_content;
@@ -1028,7 +1030,7 @@ protected function prepare_comment( $comment, $requested_fields = array( 'commen
$date = DateTime::createFromFormat( 'Y-m-d H:i:s', $comment->comment_date, $timezone );
$fields['date'] = $date->format( 'c' );
$fields['date_tz'] = $date->format( 'e' );
- $fields['date_gmt'] = date( 'c', strtotime( $post->comment_date_gmt ) );
+ $fields['date_gmt'] = date( 'c', strtotime( $comment->comment_date_gmt ) );
// Meta
$meta = array(
Something went wrong with that request. Please try again.