← All changes
|
json-endpoints/class.wpcom-json-api-comment-endpoint.php
+18
-3
13.5.2
→
16.3-a.1
View file →
| @@ -5,8 +5,13 @@ | ||
| 5 | 5 | * @todo - can this file be written without overriding global variables? |
| 6 | 6 | * |
| 7 | 7 | * @phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited |
| 8 | 8 | */ |
| 9 | + | |
| 10 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 11 | + exit( 0 ); | |
| 12 | +} | |
| 13 | + | |
| 9 | 14 | /** |
| 10 | 15 | * Comment endpoint class. |
| 11 | 16 | */ |
| 12 | 17 | abstract class WPCOM_JSON_API_Comment_Endpoint extends WPCOM_JSON_API_Endpoint { |
| @@ -70,9 +75,19 @@ | ||
| 70 | 75 | if ( ! $comment || is_wp_error( $comment ) ) { |
| 71 | 76 | return new WP_Error( 'unknown_comment', 'Unknown comment', 404 ); |
| 72 | 77 | } |
| 73 | 78 | |
| 74 | - $types = array( '', 'comment', 'pingback', 'trackback', 'review' ); | |
| 79 | + /** | |
| 80 | + * Filter the comment types that are allowed to be returned. | |
| 81 | + * | |
| 82 | + * @since 14.2 | |
| 83 | + * | |
| 84 | + * @module json-api | |
| 85 | + * | |
| 86 | + * @param array $types Array of comment types. | |
| 87 | + */ | |
| 88 | + $types = apply_filters( 'jetpack_json_api_comment_types', array( '', 'comment', 'pingback', 'trackback', 'review' ) ); | |
| 89 | + | |
| 75 | 90 | // @todo - can we make this comparison strict without breaking anything? |
| 76 | 91 | // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict |
| 77 | 92 | if ( ! in_array( $comment->comment_type, $types ) ) { |
| 78 | 93 | return new WP_Error( 'unknown_comment', 'Unknown comment', 404 ); |
| @@ -184,10 +199,10 @@ | ||
| 184 | 199 | case 'status': |
| 185 | 200 | $response[ $key ] = (string) $status; |
| 186 | 201 | break; |
| 187 | 202 | case 'parent': // May be object or false. |
| 188 | - if ( $comment->comment_parent ) { | |
| 189 | - $parent = get_comment( $comment->comment_parent ); | |
| 203 | + $parent = $comment->comment_parent ? get_comment( $comment->comment_parent ) : null; | |
| 204 | + if ( $parent ) { | |
| 190 | 205 | $response[ $key ] = (object) array( |
| 191 | 206 | 'ID' => (int) $parent->comment_ID, |
| 192 | 207 | 'type' => (string) ( $parent->comment_type ? $parent->comment_type : 'comment' ), |
| 193 | 208 | 'link' => (string) $this->links->get_comment_link( $blog_id, $parent->comment_ID ), |