Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPCOM merge: list post type taxonomies endpoint #9428

Merged
merged 3 commits into from
Apr 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ function callback( $path = '', $blog_id = 0, $post_type = 'post' ) {
$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();

Expand Down Expand Up @@ -79,4 +74,25 @@ function callback( $path = '', $blog_id = 0, $post_type = 'post' ) {
'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 );
}
}
}