From d60f5256dfebd5c07d6252a5e3c9c74662363cef Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Tue, 27 Feb 2024 05:32:43 -0600 Subject: [PATCH] Font Library: create post types on init hook (#59333) --- lib/compat/wordpress-6.5/fonts/fonts.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/compat/wordpress-6.5/fonts/fonts.php b/lib/compat/wordpress-6.5/fonts/fonts.php index 8307d5217ad42..3911f61ceaec4 100644 --- a/lib/compat/wordpress-6.5/fonts/fonts.php +++ b/lib/compat/wordpress-6.5/fonts/fonts.php @@ -86,18 +86,21 @@ function gutenberg_create_initial_post_types() { /** * Initializes REST routes. - * - * @since 6.5 */ function gutenberg_create_initial_rest_routes() { - $font_collections_controller = new WP_REST_Font_Collections_Controller(); - $font_collections_controller->register_routes(); + global $wp_version; + + // Runs only if the Font Library is not available in core ( i.e. in core < 6.5-alpha ). + if ( version_compare( $wp_version, '6.5-alpha', '<' ) ) { + $font_collections_controller = new WP_REST_Font_Collections_Controller(); + $font_collections_controller->register_routes(); + } } +add_action( 'rest_api_init', 'gutenberg_create_initial_rest_routes' ); + /** * Initializes REST routes and post types. - * - * @since 6.5 */ function gutenberg_init_font_library() { global $wp_version; @@ -105,11 +108,10 @@ function gutenberg_init_font_library() { // Runs only if the Font Library is not available in core ( i.e. in core < 6.5-alpha ). if ( version_compare( $wp_version, '6.5-alpha', '<' ) ) { gutenberg_create_initial_post_types(); - gutenberg_create_initial_rest_routes(); } } -add_action( 'rest_api_init', 'gutenberg_init_font_library' ); +add_action( 'init', 'gutenberg_init_font_library' ); if ( ! function_exists( 'wp_register_font_collection' ) ) {