Browse Source

Gave up trying to allow for font management without Gutenberg. :(

Jason Crist 3 years ago
parent
commit
12877bfbea

+ 1 - 6
blockbase/functions.php

@@ -94,14 +94,9 @@ if ( class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' ) ) {
 	require get_template_directory() . '/inc/customizer/wp-customize-colors.php';
 	require get_template_directory() . '/inc/customizer/wp-customize-color-palettes.php';
 	require get_template_directory() . '/inc/social-navigation.php';
+	require get_template_directory() . '/inc/fonts/custom-fonts.php';
 }
 
-// Font Migration
-require get_template_directory() . '/inc/fonts/custom-font-migration.php';
-// Font settings deprecation message
-require get_template_directory() . '/inc/customizer/wp-customize-fonts.php';
-// Font Management
-require get_template_directory() . '/inc/fonts/custom-fonts.php';
 
 
 // Force menus to reload

+ 6 - 1
blockbase/inc/fonts/custom-font-migration.php

@@ -8,7 +8,9 @@ function migrate_blockbase_custom_fonts() {
 	$heading_font_slug = null;
 	$body_font_slug    = null;
 
-	$font_settings = wp_get_global_settings( array( 'typography', 'fontFamilies' ) );
+	// Here we must use gutenberg_get_global_* because it introduces clean_cached_data() which we
+	// need to leverage as we are modifying the values of global styles settings and styles on page load.
+	$font_settings = gutenberg_get_global_settings( array( 'typography', 'fontFamilies' ) );
 
 	// Extract font slugs from legacy data structure.
 	// Look first for fonts customized via Customizer, then for fonts configured in the child theme.json "the old way"
@@ -99,10 +101,13 @@ function update_global_styles( $new_settings, $new_styles, $user_custom_post_typ
 	$update_request->set_param( 'styles', $new_styles );
 
 	$global_styles_controller->update_item( $update_request );
+
+	// Ideally the call to update_item would delete all of the appropriate transients and caches
 	delete_transient( 'global_styles' );
 	delete_transient( 'global_styles_' . get_stylesheet() );
 	delete_transient( 'gutenberg_global_styles' );
 	delete_transient( 'gutenberg_global_styles_' . get_stylesheet() );
+	WP_Theme_JSON_Resolver_Gutenberg::clean_cached_data();
 }
 
 /**

+ 9 - 4
blockbase/inc/fonts/custom-fonts.php

@@ -1,5 +1,11 @@
 <?php
 
+// Font Migration
+require get_template_directory() . '/inc/fonts/custom-font-migration.php';
+
+// Font settings deprecation message
+require get_template_directory() . '/inc/customizer/wp-customize-fonts.php';
+
 /**
  * Get the CSS containing font_face values for a given slug
  *
@@ -21,7 +27,8 @@ function get_style_css( $slug ) {
  */
 function collect_fonts_from_global_styles() {
 
-	$global_styles = wp_get_global_styles();
+	// NOTE: We have to use gutenberg_get_global_styles() here due to the potential changes to Global Styles on page load happening in font migration.
+	$global_styles = gutenberg_get_global_styles();
 
 	$found_webfonts = array();
 
@@ -97,9 +104,7 @@ function extract_font_slug_from_setting( $setting ) {
  */
 function collect_fonts_from_blockbase() {
 	$font_family_slugs = array();
-	$global_styles     = wp_get_global_styles();
-	$data              = WP_Theme_JSON_Resolver::get_merged_data()->get_raw_data();
-	$font_families     = $data['settings']['typography']['fontFamilies']['theme'];
+	$font_families     = gutenberg_get_global_settings( array( 'typography' )['fontFamilies'] );
 
 	foreach ( $font_families as $font_family ) {
 		$font_family_slugs[] = $font_family['slug'];