| @@ 363-417 (lines=55) @@ | ||
| 360 | ||
| 361 | $return = array(); |
|
| 362 | $excluded_count = 0; |
|
| 363 | foreach ( array_keys( $this->response_format ) as $key ) { |
|
| 364 | switch ( $key ) { |
|
| 365 | case 'found': |
|
| 366 | $return[ $key ] = (int) $wp_query->found_posts; |
|
| 367 | break; |
|
| 368 | case 'posts': |
|
| 369 | $posts = array(); |
|
| 370 | foreach ( $wp_query->posts as $post_ID ) { |
|
| 371 | $the_post = $this->get_post_by( 'ID', $post_ID, $args['context'] ); |
|
| 372 | if ( $the_post && ! is_wp_error( $the_post ) ) { |
|
| 373 | $posts[] = $the_post; |
|
| 374 | } else { |
|
| 375 | $excluded_count++; |
|
| 376 | } |
|
| 377 | } |
|
| 378 | ||
| 379 | if ( $posts ) { |
|
| 380 | /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */ |
|
| 381 | do_action( 'wpcom_json_api_objects', 'posts', count( $posts ) ); |
|
| 382 | } |
|
| 383 | ||
| 384 | $return[ $key ] = $posts; |
|
| 385 | break; |
|
| 386 | ||
| 387 | case 'meta': |
|
| 388 | if ( ! is_array( $args['type'] ) ) { |
|
| 389 | $return[ $key ] = (object) array( |
|
| 390 | 'links' => (object) array( |
|
| 391 | 'counts' => (string) $this->links->get_site_link( $blog_id, 'post-counts/' . $args['type'] ), |
|
| 392 | ), |
|
| 393 | ); |
|
| 394 | } |
|
| 395 | ||
| 396 | if ( $is_eligible_for_page_handle && $return['posts'] ) { |
|
| 397 | $last_post = end( $return['posts'] ); |
|
| 398 | reset( $return['posts'] ); |
|
| 399 | if ( ( $return['found'] > count( $return['posts'] ) ) && $last_post ) { |
|
| 400 | if ( ! isset( $return[ $key ] ) ) { |
|
| 401 | $return[ $key ] = (object) array(); |
|
| 402 | } |
|
| 403 | if ( isset( $last_post['ID'] ) ) { |
|
| 404 | $return[ $key ]->next_page = $this->build_page_handle( $last_post, $query ); |
|
| 405 | } |
|
| 406 | } |
|
| 407 | } |
|
| 408 | ||
| 409 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 410 | if ( ! isset( $return[ $key ] ) ) { |
|
| 411 | $return[ $key ] = new stdClass(); |
|
| 412 | } |
|
| 413 | $return[ $key ]->wpcom = true; |
|
| 414 | } |
|
| 415 | ||
| 416 | break; |
|
| 417 | } |
|
| 418 | } |
|
| 419 | ||
| 420 | $return['found'] -= $excluded_count; |
|
| @@ 357-412 (lines=56) @@ | ||
| 354 | ||
| 355 | $return = array(); |
|
| 356 | $excluded_count = 0; |
|
| 357 | foreach ( array_keys( $this->response_format ) as $key ) { |
|
| 358 | switch ( $key ) { |
|
| 359 | case 'found': |
|
| 360 | $return[ $key ] = (int) $wp_query->found_posts; |
|
| 361 | break; |
|
| 362 | case 'posts': |
|
| 363 | $posts = array(); |
|
| 364 | foreach ( $wp_query->posts as $post_ID ) { |
|
| 365 | $the_post = $this->get_post_by( 'ID', $post_ID, $args['context'] ); |
|
| 366 | if ( $the_post && ! is_wp_error( $the_post ) ) { |
|
| 367 | $posts[] = $the_post; |
|
| 368 | } else { |
|
| 369 | $excluded_count++; |
|
| 370 | } |
|
| 371 | } |
|
| 372 | ||
| 373 | if ( $posts ) { |
|
| 374 | /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */ |
|
| 375 | do_action( 'wpcom_json_api_objects', 'posts', count( $posts ) ); |
|
| 376 | } |
|
| 377 | ||
| 378 | $return[ $key ] = $posts; |
|
| 379 | break; |
|
| 380 | ||
| 381 | case 'meta': |
|
| 382 | if ( ! is_array( $args['type'] ) ) { |
|
| 383 | $return[ $key ] = (object) array( |
|
| 384 | 'links' => (object) array( |
|
| 385 | 'counts' => (string) $this->links->get_site_link( $blog_id, 'post-counts/' . $args['type'] ), |
|
| 386 | ), |
|
| 387 | ); |
|
| 388 | } |
|
| 389 | ||
| 390 | if ( $is_eligible_for_page_handle && $return['posts'] ) { |
|
| 391 | $last_post = end( $return['posts'] ); |
|
| 392 | reset( $return['posts'] ); |
|
| 393 | if ( ( $return['found'] > count( $return['posts'] ) ) && $last_post ) { |
|
| 394 | if ( ! isset( $return[ $key ] ) ) { |
|
| 395 | $return[ $key ] = (object) array(); |
|
| 396 | } |
|
| 397 | ||
| 398 | if ( isset( $last_post['ID'] ) ) { |
|
| 399 | $return[ $key ]->next_page = $this->build_page_handle( $last_post, $query ); |
|
| 400 | } |
|
| 401 | } |
|
| 402 | } |
|
| 403 | ||
| 404 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
|
| 405 | if ( ! isset( $return[ $key ] ) ) { |
|
| 406 | $return[ $key ] = new stdClass(); |
|
| 407 | } |
|
| 408 | $return[ $key ]->wpcom = true; |
|
| 409 | } |
|
| 410 | ||
| 411 | break; |
|
| 412 | } |
|
| 413 | } |
|
| 414 | ||
| 415 | $return['found'] -= $excluded_count; |
|