From b3d834c132c9f4a1293ae02a34efb64571b69914 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 8 Feb 2024 07:36:36 +0000 Subject: [PATCH] Editor: Register the Google Font collection. By default, users will see a tab in the editor indicating the possibility to active Google Fonts and install Fonts from there. Props youknowriad, get_dave, mcsf. Fixes #59166. git-svn-id: https://develop.svn.wordpress.org/trunk@57558 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/default-filters.php | 1 + src/wp-includes/fonts.php | 10 ++++++++++ tests/phpunit/includes/functions.php | 11 +++++++++++ 3 files changed, 22 insertions(+) diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 19a9285ed2..2d9f5368d4 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -750,5 +750,6 @@ add_action( 'wp_restore_post_revision', 'wp_restore_post_revision_meta', 10, 2 ) add_action( 'wp_head', 'wp_print_font_faces', 50 ); add_action( 'deleted_post', '_wp_after_delete_font_family', 10, 2 ); add_action( 'before_delete_post', '_wp_before_delete_font_face', 10, 2 ); +add_action( 'init', '_wp_register_default_font_collections' ); unset( $filter, $action ); diff --git a/src/wp-includes/fonts.php b/src/wp-includes/fonts.php index dae5283d65..dfd0b45857 100644 --- a/src/wp-includes/fonts.php +++ b/src/wp-includes/fonts.php @@ -188,3 +188,13 @@ function _wp_before_delete_font_face( $post_id, $post ) { wp_delete_file( $font_dir . '/' . $font_file ); } } + +/** + * Register the default font collections. + * + * @access private + * @since 6.5.0 + */ +function _wp_register_default_font_collections() { + wp_register_font_collection( 'google-fonts', 'https://s.w.org/images/fonts/17.7/collections/google-fonts-with-preview.json' ); +} diff --git a/tests/phpunit/includes/functions.php b/tests/phpunit/includes/functions.php index 0fdff9c71a..c2976dba9f 100644 --- a/tests/phpunit/includes/functions.php +++ b/tests/phpunit/includes/functions.php @@ -351,3 +351,14 @@ function _unhook_block_registration() { remove_action( 'init', '_register_block_bindings_post_meta_source' ); } tests_add_filter( 'init', '_unhook_block_registration', 1000 ); + +/** + * After the init action has been run once, trying to re-register font collections can cause + * errors. To avoid this, unhook the font registration functions. + * + * @since 6.5.0 + */ +function _unhook_font_registration() { + remove_action( 'init', '_wp_register_default_font_collections' ); +} +tests_add_filter( 'init', '_unhook_font_registration', 1000 );