Skip to content

Commit

Permalink
Enqueue all fonts for editor
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyip committed May 24, 2022
1 parent df5262d commit 1ed7cdb
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions blockbase/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function blockbase_editor_styles() {
// Enqueue editor styles.
add_editor_style(
array(
blockbase_fonts_url(),
blockbase_fonts_url( true ),
)
);

Expand All @@ -93,7 +93,7 @@ function blockbase_editor_styles() {
*/
function blockbase_scripts() {
// Enqueue Google fonts
wp_enqueue_style( 'blockbase-fonts', blockbase_fonts_url(), array(), null );
wp_enqueue_style( 'blockbase-fonts', blockbase_fonts_url( false ), array(), null );
wp_enqueue_style( 'blockbase-ponyfill', get_template_directory_uri() . '/assets/ponyfill.css', array(), wp_get_theme()->get( 'Version' ) );

// Add the child theme CSS if it exists.
Expand Down Expand Up @@ -162,18 +162,26 @@ function blockbase_core_navigation_render_fallback() {
*
* @return string
*/
function blockbase_fonts_url() {
function blockbase_fonts_url( $load_all_font_options ) {
global $blockbase_block_font_families;

$font_families = [];
$global_styles_fonts = \Automattic\Jetpack\Fonts\Introspectors\Global_Styles::collect_fonts_from_global_styles();
$fonts_to_load = array_merge( $blockbase_block_font_families, $global_styles_fonts );
$fonts_to_load = array_unique( $fonts_to_load );
$font_settings = blockbase_get_font_settings();

foreach( $fonts_to_load as $font_slug ) {
if ( isset( $font_settings[ $font_slug ]['google'] ) ) {
$font_families[] = $font_settings[ $font_slug ]['google'];

if ( $load_all_font_options ) {
foreach( $font_settings as $font_slug ) {
$font_families[] = $font_slug ['google'];
}
} else {
// Only load fonts that appear in the site's frontend
$global_styles_fonts = \Automattic\Jetpack\Fonts\Introspectors\Global_Styles::collect_fonts_from_global_styles();
$fonts_to_load = array_merge( $blockbase_block_font_families, $global_styles_fonts );
$fonts_to_load = array_unique( $fonts_to_load );

foreach( $fonts_to_load as $font_slug ) {
if ( isset( $font_settings[ $font_slug ]['google'] ) ) {
$font_families[] = $font_settings[ $font_slug ]['google'];
}
}
}

Expand Down

0 comments on commit 1ed7cdb

Please sign in to comment.