mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
REST API: Introduce WP_Post_Type::get_rest_controller() caching method to prevent unnecessary REST controller construction.
Cache REST controller references on their associated post type object to prevent unnecessary controller re-instantiation, which previously caused "rest_prepare_{$post_type}" and "rest_{$post_type}_query" to run twice per request.
Props TimothyBlynJacobs, patrelentlesstechnologycom.
Fixes #45677.
git-svn-id: https://develop.svn.wordpress.org/trunk@46272 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -192,13 +192,9 @@ function rest_api_default_filters() {
|
||||
*/
|
||||
function create_initial_rest_routes() {
|
||||
foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
|
||||
$class = ! empty( $post_type->rest_controller_class ) ? $post_type->rest_controller_class : 'WP_REST_Posts_Controller';
|
||||
$controller = $post_type->get_rest_controller();
|
||||
|
||||
if ( ! class_exists( $class ) ) {
|
||||
continue;
|
||||
}
|
||||
$controller = new $class( $post_type->name );
|
||||
if ( ! is_subclass_of( $controller, 'WP_REST_Controller' ) ) {
|
||||
if ( ! $controller ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user