--- a/wp/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php Tue Dec 15 13:49:49 2020 +0100
@@ -87,13 +87,20 @@
} else {
$taxonomies = get_taxonomies( '', 'objects' );
}
+
foreach ( $taxonomies as $taxonomy ) {
if ( ! empty( $taxonomy->show_in_rest ) && current_user_can( $taxonomy->cap->assign_terms ) ) {
return true;
}
}
- return new WP_Error( 'rest_cannot_view', __( 'Sorry, you are not allowed to manage terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) );
+
+ return new WP_Error(
+ 'rest_cannot_view',
+ __( 'Sorry, you are not allowed to manage terms in this taxonomy.' ),
+ array( 'status' => rest_authorization_required_code() )
+ );
}
+
return true;
}
@@ -115,11 +122,14 @@
} else {
$taxonomies = get_taxonomies( '', 'objects' );
}
+
$data = array();
+
foreach ( $taxonomies as $tax_type => $value ) {
if ( empty( $value->show_in_rest ) || ( 'edit' === $request['context'] && ! current_user_can( $value->cap->assign_terms ) ) ) {
continue;
}
+
$tax = $this->prepare_item_for_response( $value, $request );
$tax = $this->prepare_response_for_collection( $tax );
$data[ $tax_type ] = $tax;
@@ -138,7 +148,7 @@
*
* @since 4.7.0
*
- * @param WP_REST_Request $request Full details about the request.
+ * @param WP_REST_Request $request Full details about the request.
* @return true|WP_Error True if the request has read access for the item, otherwise false or WP_Error object.
*/
public function get_item_permissions_check( $request ) {
@@ -149,8 +159,13 @@
if ( empty( $tax_obj->show_in_rest ) ) {
return false;
}
+
if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->assign_terms ) ) {
- return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to manage terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) );
+ return new WP_Error(
+ 'rest_forbidden_context',
+ __( 'Sorry, you are not allowed to manage terms in this taxonomy.' ),
+ array( 'status' => rest_authorization_required_code() )
+ );
}
}
@@ -167,10 +182,17 @@
*/
public function get_item( $request ) {
$tax_obj = get_taxonomy( $request['taxonomy'] );
+
if ( empty( $tax_obj ) ) {
- return new WP_Error( 'rest_taxonomy_invalid', __( 'Invalid taxonomy.' ), array( 'status' => 404 ) );
+ return new WP_Error(
+ 'rest_taxonomy_invalid',
+ __( 'Invalid taxonomy.' ),
+ array( 'status' => 404 )
+ );
}
+
$data = $this->prepare_item_for_response( $tax_obj, $request );
+
return rest_ensure_response( $data );
}
@@ -179,7 +201,7 @@
*
* @since 4.7.0
*
- * @param stdClass $taxonomy Taxonomy data.
+ * @param WP_Taxonomy $taxonomy Taxonomy data.
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response Response object.
*/
@@ -210,7 +232,7 @@
}
if ( in_array( 'types', $fields, true ) ) {
- $data['types'] = $taxonomy->object_type;
+ $data['types'] = array_values( $taxonomy->object_type );
}
if ( in_array( 'show_cloud', $fields, true ) ) {
@@ -262,7 +284,7 @@
* @since 4.7.0
*
* @param WP_REST_Response $response The response object.
- * @param object $item The original taxonomy object.
+ * @param WP_Taxonomy $item The original taxonomy object.
* @param WP_REST_Request $request Request used to generate the response.
*/
return apply_filters( 'rest_prepare_taxonomy', $response, $taxonomy, $request );
@@ -276,6 +298,10 @@
* @return array Item schema data.
*/
public function get_item_schema() {
+ if ( $this->schema ) {
+ return $this->add_additional_fields_schema( $this->schema );
+ }
+
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'taxonomy',
@@ -373,7 +399,10 @@
),
),
);
- return $this->add_additional_fields_schema( $schema );
+
+ $this->schema = $schema;
+
+ return $this->add_additional_fields_schema( $this->schema );
}
/**