← All changes
|
json-endpoints/class.wpcom-json-api-list-posts-v1-2-endpoint.php
+10
-2
13.3.3
→
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 | * List posts v1_2 endpoint. |
| 5 | 9 | */ |
| 6 | 10 | new WPCOM_JSON_API_List_Posts_v1_2_Endpoint( |
| @@ -16,8 +20,10 @@ | ||
| 16 | 20 | 'path' => '/sites/%s/posts/', |
| 17 | 21 | 'path_labels' => array( |
| 18 | 22 | '$site' => '(int|string) Site ID or domain', |
| 19 | 23 | ), |
| 24 | + 'rest_route' => '/posts', | |
| 25 | + 'rest_min_jp_version' => '15.9', | |
| 20 | 26 | |
| 21 | 27 | 'allow_fallback_to_jetpack_blog_token' => true, |
| 22 | 28 | |
| 23 | 29 | 'query_parameters' => array( |
| @@ -68,8 +74,10 @@ | ||
| 68 | 74 | /** |
| 69 | 75 | * List posts v1_2 endpoint. |
| 70 | 76 | * |
| 71 | 77 | * /sites/%s/posts/ -> $blog_id |
| 78 | + * | |
| 79 | + * @phan-constructor-used-for-side-effects | |
| 72 | 80 | */ |
| 73 | 81 | class WPCOM_JSON_API_List_Posts_v1_2_Endpoint extends WPCOM_JSON_API_List_Posts_v1_1_Endpoint { // phpcs:ignore |
| 74 | 82 | |
| 75 | 83 | /** |
| @@ -177,9 +185,9 @@ | ||
| 177 | 185 | 'order' => $args['order'], |
| 178 | 186 | 'orderby' => $args['order_by'], |
| 179 | 187 | 'post_type' => $args['type'], |
| 180 | 188 | 'post_status' => $status, |
| 181 | - 'post_parent' => isset( $args['parent_id'] ) ? $args['parent_id'] : null, | |
| 189 | + 'post_parent' => $args['parent_id'] ?? null, | |
| 182 | 190 | 'author' => isset( $args['author'] ) && 0 < $args['author'] ? $args['author'] : null, |
| 183 | 191 | 's' => isset( $args['search'] ) && '' !== $args['search'] ? $args['search'] : null, |
| 184 | 192 | 'fields' => 'ids', |
| 185 | 193 | ); |
| @@ -403,9 +411,9 @@ | ||
| 403 | 411 | ), |
| 404 | 412 | ); |
| 405 | 413 | } |
| 406 | 414 | |
| 407 | - if ( $is_eligible_for_page_handle && $return['posts'] ) { | |
| 415 | + if ( $is_eligible_for_page_handle && $return['posts'] && is_array( $return['posts'] ) ) { | |
| 408 | 416 | $last_post = end( $return['posts'] ); |
| 409 | 417 | reset( $return['posts'] ); |
| 410 | 418 | $post_count = is_countable( $return['posts'] ) ? count( $return['posts'] ) : 0; |
| 411 | 419 | if ( ( $return['found'] > $post_count ) && $last_post ) { |