PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
← All changes | json-endpoints/class.wpcom-json-api-get-taxonomy-endpoint.php +85 -0 16.2-beta → 16.3 View file →
@@ -1,0 +1,85 @@
1 +<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 +
3 +if ( ! defined( 'ABSPATH' ) ) {
4 + exit( 0 );
5 +}
6 +
7 +new WPCOM_JSON_API_Get_Taxonomy_Endpoint(
8 + array(
9 + 'description' => 'Get information about a single category.',
10 + 'group' => 'taxonomy',
11 + 'stat' => 'categories:1',
12 +
13 + 'method' => 'GET',
14 + 'path' => '/sites/%s/categories/slug:%s',
15 + 'path_labels' => array(
16 + '$site' => '(int|string) Site ID or domain',
17 + '$category' => '(string) The category slug',
18 + ),
19 +
20 + 'allow_fallback_to_jetpack_blog_token' => true,
21 +
22 + 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/categories/slug:community',
23 + )
24 +);
25 +
26 +new WPCOM_JSON_API_Get_Taxonomy_Endpoint(
27 + array(
28 + 'description' => 'Get information about a single tag.',
29 + 'group' => 'taxonomy',
30 + 'stat' => 'tags:1',
31 +
32 + 'method' => 'GET',
33 + 'path' => '/sites/%s/tags/slug:%s',
34 + 'path_labels' => array(
35 + '$site' => '(int|string) Site ID or domain',
36 + '$tag' => '(string) The tag slug',
37 + ),
38 +
39 + 'allow_fallback_to_jetpack_blog_token' => true,
40 +
41 + 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/tags/slug:wordpresscom',
42 + )
43 +);
44 +
45 +/**
46 + * GET Taxonomy endpoint class.
47 + *
48 + * @phan-constructor-used-for-side-effects
49 + */
50 +class WPCOM_JSON_API_Get_Taxonomy_Endpoint extends WPCOM_JSON_API_Taxonomy_Endpoint {
51 + /**
52 + *
53 + * API callback.
54 + *
55 + * /sites/%s/tags/slug:%s -> $blog_id, $tag_id
56 + * /sites/%s/categories/slug:%s -> $blog_id, $tag_id
57 + *
58 + * @param string $path - the path.
59 + * @param int $blog_id - the blog ID.
60 + * @param int $taxonomy_id - the taxonomy ID.
61 + */
62 + public function callback( $path = '', $blog_id = 0, $taxonomy_id = 0 ) {
63 + $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
64 + if ( is_wp_error( $blog_id ) ) {
65 + return $blog_id;
66 + }
67 +
68 + $args = $this->query_args();
69 + if ( preg_match( '#/tags/#i', $path ) ) {
70 + $taxonomy_type = 'post_tag';
71 + } else {
72 + $taxonomy_type = 'category';
73 + }
74 +
75 + $return = $this->get_taxonomy( $taxonomy_id, $taxonomy_type, $args['context'] );
76 + if ( ! $return || is_wp_error( $return ) ) {
77 + return $return;
78 + }
79 +
80 + /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
81 + do_action( 'wpcom_json_api_objects', 'taxonomies' );
82 +
83 + return $return;
84 + }
85 +}