Skip to content

Commit

Permalink
Font Library: Avoid running init functions when font library is avail…
Browse files Browse the repository at this point in the history
…able 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
  • Loading branch information
matiasbenedetto authored Feb 8, 2024
1 parent 884c494 commit 11fe025
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/compat/wordpress-6.5/fonts/fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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' );
Expand Down

0 comments on commit 11fe025

Please sign in to comment.