equal
deleted
inserted
replaced
47 * @var int |
47 * @var int |
48 */ |
48 */ |
49 protected $total_terms; |
49 protected $total_terms; |
50 |
50 |
51 /** |
51 /** |
|
52 * Whether the controller supports batching. |
|
53 * |
|
54 * @since 5.9.0 |
|
55 * @var array |
|
56 */ |
|
57 protected $allow_batch = array( 'v1' => true ); |
|
58 |
|
59 /** |
52 * Constructor. |
60 * Constructor. |
53 * |
61 * |
54 * @since 4.7.0 |
62 * @since 4.7.0 |
55 * |
63 * |
56 * @param string $taxonomy Taxonomy key. |
64 * @param string $taxonomy Taxonomy key. |
57 */ |
65 */ |
58 public function __construct( $taxonomy ) { |
66 public function __construct( $taxonomy ) { |
59 $this->taxonomy = $taxonomy; |
67 $this->taxonomy = $taxonomy; |
60 $this->namespace = 'wp/v2'; |
|
61 $tax_obj = get_taxonomy( $taxonomy ); |
68 $tax_obj = get_taxonomy( $taxonomy ); |
62 $this->rest_base = ! empty( $tax_obj->rest_base ) ? $tax_obj->rest_base : $tax_obj->name; |
69 $this->rest_base = ! empty( $tax_obj->rest_base ) ? $tax_obj->rest_base : $tax_obj->name; |
|
70 $this->namespace = ! empty( $tax_obj->rest_namespace ) ? $tax_obj->rest_namespace : 'wp/v2'; |
63 |
71 |
64 $this->meta = new WP_REST_Term_Meta_Fields( $taxonomy ); |
72 $this->meta = new WP_REST_Term_Meta_Fields( $taxonomy ); |
65 } |
73 } |
66 |
74 |
67 /** |
75 /** |
87 'methods' => WP_REST_Server::CREATABLE, |
95 'methods' => WP_REST_Server::CREATABLE, |
88 'callback' => array( $this, 'create_item' ), |
96 'callback' => array( $this, 'create_item' ), |
89 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
97 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
90 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
98 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
91 ), |
99 ), |
92 'schema' => array( $this, 'get_public_item_schema' ), |
100 'allow_batch' => $this->allow_batch, |
|
101 'schema' => array( $this, 'get_public_item_schema' ), |
93 ) |
102 ) |
94 ); |
103 ); |
95 |
104 |
96 register_rest_route( |
105 register_rest_route( |
97 $this->namespace, |
106 $this->namespace, |
98 '/' . $this->rest_base . '/(?P<id>[\d]+)', |
107 '/' . $this->rest_base . '/(?P<id>[\d]+)', |
99 array( |
108 array( |
100 'args' => array( |
109 'args' => array( |
101 'id' => array( |
110 'id' => array( |
102 'description' => __( 'Unique identifier for the term.' ), |
111 'description' => __( 'Unique identifier for the term.' ), |
103 'type' => 'integer', |
112 'type' => 'integer', |
104 ), |
113 ), |
105 ), |
114 ), |
127 'default' => false, |
136 'default' => false, |
128 'description' => __( 'Required to be true, as terms do not support trashing.' ), |
137 'description' => __( 'Required to be true, as terms do not support trashing.' ), |
129 ), |
138 ), |
130 ), |
139 ), |
131 ), |
140 ), |
132 'schema' => array( $this, 'get_public_item_schema' ), |
141 'allow_batch' => $this->allow_batch, |
|
142 'schema' => array( $this, 'get_public_item_schema' ), |
133 ) |
143 ) |
134 ); |
144 ); |
135 } |
145 } |
136 |
146 |
137 /** |
147 /** |
912 } |
922 } |
913 |
923 |
914 $post_type_links = array(); |
924 $post_type_links = array(); |
915 |
925 |
916 foreach ( $taxonomy_obj->object_type as $type ) { |
926 foreach ( $taxonomy_obj->object_type as $type ) { |
917 $post_type_object = get_post_type_object( $type ); |
927 $rest_path = rest_get_route_for_post_type_items( $type ); |
918 |
928 |
919 if ( empty( $post_type_object->show_in_rest ) ) { |
929 if ( empty( $rest_path ) ) { |
920 continue; |
930 continue; |
921 } |
931 } |
922 |
932 |
923 $rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name; |
|
924 $post_type_links[] = array( |
933 $post_type_links[] = array( |
925 'href' => add_query_arg( $this->rest_base, $term->term_id, rest_url( sprintf( 'wp/v2/%s', $rest_base ) ) ), |
934 'href' => add_query_arg( $this->rest_base, $term->term_id, rest_url( $rest_path ) ), |
926 ); |
935 ); |
927 } |
936 } |
928 |
937 |
929 if ( ! empty( $post_type_links ) ) { |
938 if ( ! empty( $post_type_links ) ) { |
930 $links['https://api.w.org/post_type'] = $post_type_links; |
939 $links['https://api.w.org/post_type'] = $post_type_links; |