PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | json-endpoints/class.wpcom-json-api-comment-endpoint.php +18 -3 13.7.216.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 ),