From 11fe025cb03e14d56e87bdb888a46c707e8ce253 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 8 Feb 2024 09:32:54 -0300 Subject: [PATCH] Font Library: Avoid running init functions when font library is available in core. (#58793) * add a conditional to initialize font library post types and rest routes only if the WP_Font_Library class is not available, for example when the plugin run on WordPress < 6.5 * remove comment no longer needed because the font library was already merged into core * fix conditional * format php * update comment text --- lib/compat/wordpress-6.5/fonts/fonts.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/compat/wordpress-6.5/fonts/fonts.php b/lib/compat/wordpress-6.5/fonts/fonts.php index bf7691bafc5e9..1f29645a9c2b9 100644 --- a/lib/compat/wordpress-6.5/fonts/fonts.php +++ b/lib/compat/wordpress-6.5/fonts/fonts.php @@ -90,7 +90,6 @@ function gutenberg_create_initial_post_types() { * @since 6.5 */ function gutenberg_create_initial_rest_routes() { - // @core-merge: This code will go into Core's `create_initial_rest_routes()`. $font_collections_controller = new WP_REST_Font_Collections_Controller(); $font_collections_controller->register_routes(); } @@ -101,8 +100,13 @@ function gutenberg_create_initial_rest_routes() { * @since 6.5 */ function gutenberg_init_font_library() { - gutenberg_create_initial_post_types(); - gutenberg_create_initial_rest_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', '<' ) ) { + gutenberg_create_initial_post_types(); + gutenberg_create_initial_rest_routes(); + } } add_action( 'rest_api_init', 'gutenberg_init_font_library' );