WPCOM_JSON_API_Get_Post_Endpoint

The Jetpack by WordPress.com WPCOM JSON API Get Post Endpoint class.

Defined (1)

The class is defined in the following location(s).

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