summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-type-taxonomies-endpoint.php')
-rw-r--r--plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-type-taxonomies-endpoint.php28
1 files changed, 22 insertions, 6 deletions
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-type-taxonomies-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-type-taxonomies-endpoint.php
index 69d5bf47..27b1cf0e 100644
--- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-type-taxonomies-endpoint.php
+++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-type-taxonomies-endpoint.php
@@ -39,12 +39,7 @@ class WPCOM_JSON_API_List_Post_Type_Taxonomies_Endpoint extends WPCOM_JSON_API_E
$this->load_theme_functions();
}
- /** This filter is documented in jetpack/json-endpoints/class.wpcom-json-api-list-post-types-endpoint.php */
- if ( apply_filters( 'rest_api_localize_response', false ) ) {
- // API localization occurs after the initial taxonomies have been
- // registered, so re-register if localizing response
- create_initial_taxonomies();
- }
+ $this->localize_initial_taxonomies( $post_type );
$args = $this->query_args();
@@ -79,4 +74,25 @@ class WPCOM_JSON_API_List_Post_Type_Taxonomies_Endpoint extends WPCOM_JSON_API_E
'taxonomies' => $formatted_taxonomy_objects,
);
}
+
+ protected function localize_initial_taxonomies( $post_type ) {
+ /** This filter is documented in jetpack/json-endpoints/class.wpcom-json-api-list-post-types-endpoint.php */
+ if ( ! apply_filters( 'rest_api_localize_response', false ) ) {
+ return;
+ }
+
+ // Since recreating initial taxonomies will restore the default post
+ // types to which they are associated, save post type's taxonomies in
+ // case it was customized via `register_taxonomy_for_object_type`
+ $post_type_taxonomies = get_object_taxonomies( $post_type );
+
+ // API localization occurs after the initial taxonomies have been
+ // registered, so re-register if localizing response
+ create_initial_taxonomies();
+
+ // Restore registered taxonomies for post type
+ foreach ( $post_type_taxonomies as $taxonomy ) {
+ register_taxonomy_for_object_type( $taxonomy, $post_type );
+ }
+ }
}