| @@ 289-341 (lines=53) @@ | ||
| 286 | ||
| 287 | $return = array(); |
|
| 288 | $excluded_count = 0; |
|
| 289 | foreach ( array_keys( $this->response_format ) as $key ) { |
|
| 290 | switch ( $key ) { |
|
| 291 | case 'found' : |
|
| 292 | $return[$key] = (int) $wp_query->found_posts; |
|
| 293 | break; |
|
| 294 | case 'posts' : |
|
| 295 | $posts = array(); |
|
| 296 | foreach ( $wp_query->posts as $post_ID ) { |
|
| 297 | $the_post = $this->get_post_by( 'ID', $post_ID, $args['context'] ); |
|
| 298 | if ( $the_post && ! is_wp_error( $the_post ) ) { |
|
| 299 | $posts[] = $the_post; |
|
| 300 | } else { |
|
| 301 | $excluded_count++; |
|
| 302 | } |
|
| 303 | } |
|
| 304 | ||
| 305 | if ( $posts ) { |
|
| 306 | /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */ |
|
| 307 | do_action( 'wpcom_json_api_objects', 'posts', count( $posts ) ); |
|
| 308 | } |
|
| 309 | ||
| 310 | $return[$key] = $posts; |
|
| 311 | break; |
|
| 312 | ||
| 313 | case 'meta' : |
|
| 314 | if ( ! is_array( $args['type'] ) ) { |
|
| 315 | $return[$key] = (object) array( |
|
| 316 | 'links' => (object) array( |
|
| 317 | 'counts' => (string) $this->links->get_site_link( $blog_id, 'post-counts/' . $args['type'] ), |
|
| 318 | ) |
|
| 319 | ); |
|
| 320 | } |
|
| 321 | ||
| 322 | if ( $is_eligible_for_page_handle && $return['posts'] ) { |
|
| 323 | $last_post = end( $return['posts'] ); |
|
| 324 | reset( $return['posts'] ); |
|
| 325 | if ( ( $return['found'] > count( $return['posts'] ) ) && $last_post ) { |
|
| 326 | if ( ! isset( $return[$key] ) ) { |
|
| 327 | $return[$key] = (object) array(); |
|
| 328 | } |
|
| 329 | $return[$key]->next_page = $this->build_page_handle( $last_post, $query ); |
|
| 330 | } |
|
| 331 | } |
|
| 332 | ||
| 333 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 334 | if ( !isset( $return[$key] ) ) |
|
| 335 | $return[$key] = new stdClass; |
|
| 336 | $return[$key]->wpcom = true; |
|
| 337 | } |
|
| 338 | ||
| 339 | break; |
|
| 340 | } |
|
| 341 | } |
|
| 342 | ||
| 343 | $return['found'] -= $excluded_count; |
|
| 344 | ||
| @@ 287-339 (lines=53) @@ | ||
| 284 | ||
| 285 | $return = array(); |
|
| 286 | $excluded_count = 0; |
|
| 287 | foreach ( array_keys( $this->response_format ) as $key ) { |
|
| 288 | switch ( $key ) { |
|
| 289 | case 'found' : |
|
| 290 | $return[$key] = (int) $wp_query->found_posts; |
|
| 291 | break; |
|
| 292 | case 'posts' : |
|
| 293 | $posts = array(); |
|
| 294 | foreach ( $wp_query->posts as $post_ID ) { |
|
| 295 | $the_post = $this->get_post_by( 'ID', $post_ID, $args['context'] ); |
|
| 296 | if ( $the_post && ! is_wp_error( $the_post ) ) { |
|
| 297 | $posts[] = $the_post; |
|
| 298 | } else { |
|
| 299 | $excluded_count++; |
|
| 300 | } |
|
| 301 | } |
|
| 302 | ||
| 303 | if ( $posts ) { |
|
| 304 | /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */ |
|
| 305 | do_action( 'wpcom_json_api_objects', 'posts', count( $posts ) ); |
|
| 306 | } |
|
| 307 | ||
| 308 | $return[$key] = $posts; |
|
| 309 | break; |
|
| 310 | ||
| 311 | case 'meta' : |
|
| 312 | if ( ! is_array( $args['type'] ) ) { |
|
| 313 | $return[$key] = (object) array( |
|
| 314 | 'links' => (object) array( |
|
| 315 | 'counts' => (string) $this->links->get_site_link( $blog_id, 'post-counts/' . $args['type'] ), |
|
| 316 | ) |
|
| 317 | ); |
|
| 318 | } |
|
| 319 | ||
| 320 | if ( $is_eligible_for_page_handle && $return['posts'] ) { |
|
| 321 | $last_post = end( $return['posts'] ); |
|
| 322 | reset( $return['posts'] ); |
|
| 323 | if ( ( $return['found'] > count( $return['posts'] ) ) && $last_post ) { |
|
| 324 | if ( ! isset( $return[$key] ) ) { |
|
| 325 | $return[$key] = (object) array(); |
|
| 326 | } |
|
| 327 | $return[$key]->next_page = $this->build_page_handle( $last_post, $query ); |
|
| 328 | } |
|
| 329 | } |
|
| 330 | ||
| 331 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 332 | if ( !isset( $return[$key] ) ) |
|
| 333 | $return[$key] = new stdClass; |
|
| 334 | $return[$key]->wpcom = true; |
|
| 335 | } |
|
| 336 | ||
| 337 | break; |
|
| 338 | } |
|
| 339 | } |
|
| 340 | ||
| 341 | $return['found'] -= $excluded_count; |
|
| 342 | ||