Ei kuvausta

class.wpcom-json-api-get-taxonomy-endpoint.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. new WPCOM_JSON_API_Get_Taxonomy_Endpoint( array(
  3. 'description' => 'Get information about a single category.',
  4. 'group' => 'taxonomy',
  5. 'stat' => 'categories:1',
  6. 'method' => 'GET',
  7. 'path' => '/sites/%s/categories/slug:%s',
  8. 'path_labels' => array(
  9. '$site' => '(int|string) Site ID or domain',
  10. '$category' => '(string) The category slug'
  11. ),
  12. 'allow_fallback_to_jetpack_blog_token' => true,
  13. 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/categories/slug:community'
  14. ) );
  15. new WPCOM_JSON_API_Get_Taxonomy_Endpoint( array(
  16. 'description' => 'Get information about a single tag.',
  17. 'group' => 'taxonomy',
  18. 'stat' => 'tags:1',
  19. 'method' => 'GET',
  20. 'path' => '/sites/%s/tags/slug:%s',
  21. 'path_labels' => array(
  22. '$site' => '(int|string) Site ID or domain',
  23. '$tag' => '(string) The tag slug'
  24. ),
  25. 'allow_fallback_to_jetpack_blog_token' => true,
  26. 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/tags/slug:wordpresscom'
  27. ) );
  28. class WPCOM_JSON_API_Get_Taxonomy_Endpoint extends WPCOM_JSON_API_Taxonomy_Endpoint {
  29. // /sites/%s/tags/slug:%s -> $blog_id, $tag_id
  30. // /sites/%s/categories/slug:%s -> $blog_id, $tag_id
  31. function callback( $path = '', $blog_id = 0, $taxonomy_id = 0 ) {
  32. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
  33. if ( is_wp_error( $blog_id ) ) {
  34. return $blog_id;
  35. }
  36. $args = $this->query_args();
  37. if ( preg_match( '#/tags/#i', $path ) ) {
  38. $taxonomy_type = "post_tag";
  39. } else {
  40. $taxonomy_type = "category";
  41. }
  42. $return = $this->get_taxonomy( $taxonomy_id, $taxonomy_type, $args['context'] );
  43. if ( !$return || is_wp_error( $return ) ) {
  44. return $return;
  45. }
  46. /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
  47. do_action( 'wpcom_json_api_objects', 'taxonomies' );
  48. return $return;
  49. }
  50. }