← All changes
|
json-endpoints/class.wpcom-json-api-list-comments-endpoint.php
+21
-10
13.7.2
→
16.3-a.1
View file →
| @@ -1,6 +1,10 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | + exit( 0 ); | |
| 5 | +} | |
| 6 | + | |
| 3 | 7 | /** |
| 4 | 8 | * Comments Walker Class. |
| 5 | 9 | */ |
| 6 | 10 | class WPCOM_JSON_API_List_Comments_Walker extends Walker { |
| @@ -136,8 +140,10 @@ | ||
| 136 | 140 | * /sites/%s/posts/%d/replies/ -> $blog_id, $post_id |
| 137 | 141 | * /sites/%s/comments/%d/replies/ -> $blog_id, $comment_id |
| 138 | 142 | * |
| 139 | 143 | * @todo permissions |
| 144 | + * | |
| 145 | + * @phan-constructor-used-for-side-effects | |
| 140 | 146 | */ |
| 141 | 147 | class WPCOM_JSON_API_List_Comments_Endpoint extends WPCOM_JSON_API_Comment_Endpoint { // phpcs:ignore |
| 142 | 148 | |
| 143 | 149 | /** |
| @@ -160,22 +166,22 @@ | ||
| 160 | 166 | parent::__construct( $args ); |
| 161 | 167 | $this->query = array_merge( |
| 162 | 168 | $this->query, |
| 163 | 169 | array( |
| 164 | - 'number' => '(int=20) The number of comments to return. Limit: 100. When using hierarchical=1, number refers to the number of top-level comments returned.', | |
| 165 | - 'offset' => '(int=0) 0-indexed offset. Not available if using hierarchical=1.', | |
| 166 | - 'page' => '(int) Return the Nth 1-indexed page of comments. Takes precedence over the <code>offset</code> parameter. When using hierarchical=1, pagination is a bit different. See the note on the number parameter.', | |
| 167 | - 'order' => array( | |
| 170 | + 'number' => '(int=20) The number of comments to return. Limit: 100. When using hierarchical=1, number refers to the number of top-level comments returned.', | |
| 171 | + 'offset' => '(int=0) 0-indexed offset. Not available if using hierarchical=1.', | |
| 172 | + 'page' => '(int) Return the Nth 1-indexed page of comments. Takes precedence over the <code>offset</code> parameter. When using hierarchical=1, pagination is a bit different. See the note on the number parameter.', | |
| 173 | + 'order' => array( | |
| 168 | 174 | 'DESC' => 'Return comments in descending order from newest to oldest.', |
| 169 | 175 | 'ASC' => 'Return comments in ascending order from oldest to newest.', |
| 170 | 176 | ), |
| 171 | - 'hierarchical' => array( | |
| 177 | + 'hierarchical' => array( | |
| 172 | 178 | 'false' => '', |
| 173 | 179 | 'true' => '(BETA) Order the comment list hierarchically.', |
| 174 | 180 | ), |
| 175 | - 'after' => '(ISO 8601 datetime) Return comments dated on or after the specified datetime. Not available if using hierarchical=1.', | |
| 176 | - 'before' => '(ISO 8601 datetime) Return comments dated on or before the specified datetime. Not available if using hierarchical=1.', | |
| 177 | - 'type' => array( | |
| 181 | + 'after' => '(ISO 8601 datetime) Return comments dated on or after the specified datetime. Not available if using hierarchical=1.', | |
| 182 | + 'before' => '(ISO 8601 datetime) Return comments dated on or before the specified datetime. Not available if using hierarchical=1.', | |
| 183 | + 'type' => array( | |
| 178 | 184 | 'any' => 'Return all comments regardless of type.', |
| 179 | 185 | 'comment' => 'Return only regular comments.', |
| 180 | 186 | 'trackback' => 'Return only trackbacks.', |
| 181 | 187 | 'pingback' => 'Return only pingbacks.', |
| @@ -180,9 +186,9 @@ | ||
| 180 | 186 | 'trackback' => 'Return only trackbacks.', |
| 181 | 187 | 'pingback' => 'Return only pingbacks.', |
| 182 | 188 | 'pings' => 'Return both trackbacks and pingbacks.', |
| 183 | 189 | ), |
| 184 | - 'status' => array( | |
| 190 | + 'status' => array( | |
| 185 | 191 | 'approved' => 'Return only approved comments.', |
| 186 | 192 | 'unapproved' => 'Return only comments in the moderation queue.', |
| 187 | 193 | 'spam' => 'Return only comments marked as spam.', |
| 188 | 194 | 'trash' => 'Return only comments in the trash.', |
| @@ -187,8 +193,12 @@ | ||
| 187 | 193 | 'spam' => 'Return only comments marked as spam.', |
| 188 | 194 | 'trash' => 'Return only comments in the trash.', |
| 189 | 195 | 'all' => 'Return comments of all statuses.', |
| 190 | 196 | ), |
| 197 | + 'author_wpcom_data' => array( | |
| 198 | + 'false' => 'Do not add wpcom_id and wpcom_login fields to comment author responses (default)', | |
| 199 | + 'true' => 'Add wpcom_id and wpcom_login fields to comment author responses', | |
| 200 | + ), | |
| 191 | 201 | ) |
| 192 | 202 | ); |
| 193 | 203 | } |
| 194 | 204 | |
| @@ -333,9 +343,10 @@ | ||
| 333 | 343 | $comments = get_comments( $query ); |
| 334 | 344 | |
| 335 | 345 | if ( $args['hierarchical'] ) { |
| 336 | 346 | $walker = new WPCOM_JSON_API_List_Comments_Walker(); |
| 337 | - $comment_ids = $walker->paged_walk( $comments, get_option( 'thread_comments_depth', -1 ), isset( $args['page'] ) ? $args['page'] : 1, $args['number'] ); | |
| 347 | + $comment_ids = $walker->paged_walk( $comments, get_option( 'thread_comments_depth', -1 ), $args['page'] ?? 1, $args['number'] ); | |
| 348 | + '@phan-var int[] $comment_ids'; | |
| 338 | 349 | if ( ! empty( $comment_ids ) ) { |
| 339 | 350 | $comments = array_map( 'get_comment', $comment_ids ); |
| 340 | 351 | } |
| 341 | 352 | } |