| @@ 345-397 (lines=53) @@ | ||
| 342 | ||
| 343 | $return = array(); |
|
| 344 | $excluded_count = 0; |
|
| 345 | foreach ( array_keys( $this->response_format ) as $key ) { |
|
| 346 | switch ( $key ) { |
|
| 347 | case 'found' : |
|
| 348 | $return[$key] = (int) $wp_query->found_posts; |
|
| 349 | break; |
|
| 350 | case 'posts' : |
|
| 351 | $posts = array(); |
|
| 352 | foreach ( $wp_query->posts as $post_ID ) { |
|
| 353 | $the_post = $this->get_post_by( 'ID', $post_ID, $args['context'] ); |
|
| 354 | if ( $the_post && ! is_wp_error( $the_post ) ) { |
|
| 355 | $posts[] = $the_post; |
|
| 356 | } else { |
|
| 357 | $excluded_count++; |
|
| 358 | } |
|
| 359 | } |
|
| 360 | ||
| 361 | if ( $posts ) { |
|
| 362 | /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */ |
|
| 363 | do_action( 'wpcom_json_api_objects', 'posts', count( $posts ) ); |
|
| 364 | } |
|
| 365 | ||
| 366 | $return[$key] = $posts; |
|
| 367 | break; |
|
| 368 | ||
| 369 | case 'meta' : |
|
| 370 | if ( ! is_array( $args['type'] ) ) { |
|
| 371 | $return[$key] = (object) array( |
|
| 372 | 'links' => (object) array( |
|
| 373 | 'counts' => (string) $this->links->get_site_link( $blog_id, 'post-counts/' . $args['type'] ), |
|
| 374 | ) |
|
| 375 | ); |
|
| 376 | } |
|
| 377 | ||
| 378 | if ( $is_eligible_for_page_handle && $return['posts'] ) { |
|
| 379 | $last_post = end( $return['posts'] ); |
|
| 380 | reset( $return['posts'] ); |
|
| 381 | if ( ( $return['found'] > count( $return['posts'] ) ) && $last_post ) { |
|
| 382 | if ( ! isset( $return[$key] ) ) { |
|
| 383 | $return[$key] = (object) array(); |
|
| 384 | } |
|
| 385 | $return[$key]->next_page = $this->build_page_handle( $last_post, $query ); |
|
| 386 | } |
|
| 387 | } |
|
| 388 | ||
| 389 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 390 | if ( !isset( $return[$key] ) ) |
|
| 391 | $return[$key] = new stdClass; |
|
| 392 | $return[$key]->wpcom = true; |
|
| 393 | } |
|
| 394 | ||
| 395 | break; |
|
| 396 | } |
|
| 397 | } |
|
| 398 | ||
| 399 | $return['found'] -= $excluded_count; |
|
| 400 | ||
| @@ 338-390 (lines=53) @@ | ||
| 335 | ||
| 336 | $return = array(); |
|
| 337 | $excluded_count = 0; |
|
| 338 | foreach ( array_keys( $this->response_format ) as $key ) { |
|
| 339 | switch ( $key ) { |
|
| 340 | case 'found' : |
|
| 341 | $return[$key] = (int) $wp_query->found_posts; |
|
| 342 | break; |
|
| 343 | case 'posts' : |
|
| 344 | $posts = array(); |
|
| 345 | foreach ( $wp_query->posts as $post_ID ) { |
|
| 346 | $the_post = $this->get_post_by( 'ID', $post_ID, $args['context'] ); |
|
| 347 | if ( $the_post && ! is_wp_error( $the_post ) ) { |
|
| 348 | $posts[] = $the_post; |
|
| 349 | } else { |
|
| 350 | $excluded_count++; |
|
| 351 | } |
|
| 352 | } |
|
| 353 | ||
| 354 | if ( $posts ) { |
|
| 355 | /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */ |
|
| 356 | do_action( 'wpcom_json_api_objects', 'posts', count( $posts ) ); |
|
| 357 | } |
|
| 358 | ||
| 359 | $return[$key] = $posts; |
|
| 360 | break; |
|
| 361 | ||
| 362 | case 'meta' : |
|
| 363 | if ( ! is_array( $args['type'] ) ) { |
|
| 364 | $return[$key] = (object) array( |
|
| 365 | 'links' => (object) array( |
|
| 366 | 'counts' => (string) $this->links->get_site_link( $blog_id, 'post-counts/' . $args['type'] ), |
|
| 367 | ) |
|
| 368 | ); |
|
| 369 | } |
|
| 370 | ||
| 371 | if ( $is_eligible_for_page_handle && $return['posts'] ) { |
|
| 372 | $last_post = end( $return['posts'] ); |
|
| 373 | reset( $return['posts'] ); |
|
| 374 | if ( ( $return['found'] > count( $return['posts'] ) ) && $last_post ) { |
|
| 375 | if ( ! isset( $return[$key] ) ) { |
|
| 376 | $return[$key] = (object) array(); |
|
| 377 | } |
|
| 378 | $return[$key]->next_page = $this->build_page_handle( $last_post, $query ); |
|
| 379 | } |
|
| 380 | } |
|
| 381 | ||
| 382 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 383 | if ( !isset( $return[$key] ) ) |
|
| 384 | $return[$key] = new stdClass; |
|
| 385 | $return[$key]->wpcom = true; |
|
| 386 | } |
|
| 387 | ||
| 388 | break; |
|
| 389 | } |
|
| 390 | } |
|
| 391 | ||
| 392 | $return['found'] -= $excluded_count; |
|
| 393 | ||