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
This commit is contained in:
Riad Benguella
2024-02-08 07:36:36 +00:00
parent 435155f22a
commit b3d834c132
3 changed files with 22 additions and 0 deletions

View File

@@ -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 );

View File

@@ -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' );
}

View File

@@ -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 );