/json-endpoints/class.wpcom-json-api-get-post-endpoint.php

  1. <?php 
  2. class WPCOM_JSON_API_Get_Post_Endpoint extends WPCOM_JSON_API_Post_Endpoint { 
  3. // /sites/%s/posts/%d -> $blog_id, $post_id 
  4. // /sites/%s/posts/name:%s -> $blog_id, $post_id // not documented 
  5. // /sites/%s/posts/slug:%s -> $blog_id, $post_id 
  6. function callback( $path = '', $blog_id = 0, $post_id = 0 ) { 
  7. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); 
  8. if ( is_wp_error( $blog_id ) ) { 
  9. return $blog_id; 
  10.  
  11. $args = $this->query_args(); 
  12.  
  13. if ( false === strpos( $path, '/posts/slug:' ) && false === strpos( $path, '/posts/name:' ) ) { 
  14. $get_by = 'ID'; 
  15. } else { 
  16. $get_by = 'name'; 
  17.  
  18. $return = $this->get_post_by( $get_by, $post_id, $args['context'] ); 
  19. if ( !$return || is_wp_error( $return ) ) { 
  20. return $return; 
  21.  
  22. /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */ 
  23. do_action( 'wpcom_json_api_objects', 'posts' ); 
  24.  
  25. return $return; 
.