WPCOM_JSON_API_List_Post_Types_Endpoint

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

Defined (1)

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

/json-endpoints/class.wpcom-json-api-get-site-endpoint.php  
  1. class WPCOM_JSON_API_List_Post_Types_Endpoint extends WPCOM_JSON_API_Endpoint { 
  2. static $post_type_keys_to_include = array( 
  3. 'name' => 'name',  
  4. 'label' => 'label',  
  5. 'labels' => 'labels',  
  6. 'description' => 'description',  
  7. 'map_meta_cap' => 'map_meta_cap',  
  8. 'cap' => 'capabilities',  
  9. ); 
  10.  
  11. // /sites/%s/post-types -> $blog_id 
  12. function callback( $path = '', $blog_id = 0 ) { 
  13. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); 
  14. if ( is_wp_error( $blog_id ) ) { 
  15. return $blog_id; 
  16.  
  17. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { 
  18. $this->load_theme_functions(); 
  19.  
  20. $args = $this->query_args(); 
  21. $queryable_only = isset( $args['api_queryable'] ) && $args['api_queryable']; 
  22.  
  23. // Get a list of available post types 
  24. $post_types = get_post_types( array( 'public' => true ) ); 
  25. $formatted_post_type_objects = array(); 
  26.  
  27. // Retrieve post type object for each post type 
  28. foreach ( $post_types as $post_type ) { 
  29. // Skip non-queryable if filtering on queryable only 
  30. $is_queryable = $this->is_post_type_allowed( $post_type ); 
  31. if ( $queryable_only && ! $is_queryable ) { 
  32. continue; 
  33.  
  34. $post_type_object = get_post_type_object( $post_type ); 
  35. $formatted_post_type_object = array(); 
  36.  
  37. // Include only the desired keys in the response 
  38. foreach ( self::$post_type_keys_to_include as $key => $value ) { 
  39. $formatted_post_type_object[ $value ] = $post_type_object->{ $key }; 
  40. $formatted_post_type_object['api_queryable'] = $is_queryable; 
  41. $formatted_post_type_object['supports'] = get_all_post_type_supports( $post_type ); 
  42. $formatted_post_type_objects[] = $formatted_post_type_object; 
  43.  
  44. return array( 
  45. 'found' => count( $formatted_post_type_objects ),  
  46. 'post_types' => $formatted_post_type_objects 
  47. );