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 +20 -4 12.7.316.3-a.1 View file →
@@ -2,10 +2,16 @@
2 2 /**
3 3 * Comment endpoint.
4 4 *
5 5 * @todo - can this file be written without overriding global variables?
6 + *
6 7 * @phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited
7 8 */
9 +
10 +if ( ! defined( 'ABSPATH' ) ) {
11 + exit( 0 );
12 +}
13 +
8 14 /**
9 15 * Comment endpoint class.
10 16 */
11 17 abstract class WPCOM_JSON_API_Comment_Endpoint extends WPCOM_JSON_API_Endpoint {
@@ -69,9 +75,19 @@
69 75 if ( ! $comment || is_wp_error( $comment ) ) {
70 76 return new WP_Error( 'unknown_comment', 'Unknown comment', 404 );
71 77 }
72 78
73 - $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 +
74 90 // @todo - can we make this comparison strict without breaking anything?
75 91 // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
76 92 if ( ! in_array( $comment->comment_type, $types ) ) {
77 93 return new WP_Error( 'unknown_comment', 'Unknown comment', 404 );
@@ -183,10 +199,10 @@
183 199 case 'status':
184 200 $response[ $key ] = (string) $status;
185 201 break;
186 202 case 'parent': // May be object or false.
187 - if ( $comment->comment_parent ) {
188 - $parent = get_comment( $comment->comment_parent );
203 + $parent = $comment->comment_parent ? get_comment( $comment->comment_parent ) : null;
204 + if ( $parent ) {
189 205 $response[ $key ] = (object) array(
190 206 'ID' => (int) $parent->comment_ID,
191 207 'type' => (string) ( $parent->comment_type ? $parent->comment_type : 'comment' ),
192 208 'link' => (string) $this->links->get_comment_link( $blog_id, $parent->comment_ID ),
@@ -204,9 +220,9 @@
204 220 }
205 221 break;
206 222 case 'i_like':
207 223 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
208 - $response[ $key ] = (bool) Likes::comment_like_current_user_likes( $blog_id, $comment->comment_ID );
224 + $response[ $key ] = (bool) Likes::comment_like_current_user_likes( $blog_id, (int) $comment->comment_ID );
209 225 }
210 226 break;
211 227 case 'meta':
212 228 $response[ $key ] = (object) array(