|
@@ -6,11 +6,13 @@ add_action( 'after_setup_theme', 'migrate_blockbase_custom_fonts', 0 );
|
|
function migrate_blockbase_custom_fonts() {
|
|
function migrate_blockbase_custom_fonts() {
|
|
|
|
|
|
$heading_font_slug = null;
|
|
$heading_font_slug = null;
|
|
- $body_font_slug = null;
|
|
|
|
|
|
+ $body_font_slug = null;
|
|
|
|
|
|
$font_settings = wp_get_global_settings( array( 'typography', 'fontFamilies' ) );
|
|
$font_settings = wp_get_global_settings( array( 'typography', 'fontFamilies' ) );
|
|
|
|
|
|
- // Extract font slugs from legacy data structure.
|
|
|
|
|
|
+ die( var_dump( $font_settings ) );
|
|
|
|
+
|
|
|
|
+ // 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"
|
|
// Look first for fonts customized via Customizer, then for fonts configured in the child theme.json "the old way"
|
|
if ( isset( $font_settings['custom'] ) && is_array( $font_settings['custom'] ) ) {
|
|
if ( isset( $font_settings['custom'] ) && is_array( $font_settings['custom'] ) ) {
|
|
$font_stuff = $font_settings['custom'];
|
|
$font_stuff = $font_settings['custom'];
|
|
@@ -19,25 +21,27 @@ function migrate_blockbase_custom_fonts() {
|
|
}
|
|
}
|
|
|
|
|
|
foreach ( $font_stuff as $font_setting ) {
|
|
foreach ( $font_stuff as $font_setting ) {
|
|
- if ( strpos( $font_setting['slug'], 'heading' ) !== false && array_key_exists('fontSlug', $font_setting) ) {
|
|
|
|
|
|
+ if ( strpos( $font_setting['slug'], 'heading' ) !== false && array_key_exists( 'fontSlug', $font_setting ) ) {
|
|
$heading_font_slug = $font_setting['fontSlug'];
|
|
$heading_font_slug = $font_setting['fontSlug'];
|
|
}
|
|
}
|
|
|
|
|
|
- if ( strpos( $font_setting['slug'], 'body' ) !== false && array_key_exists('fontSlug', $font_setting) ) {
|
|
|
|
|
|
+ if ( strpos( $font_setting['slug'], 'body' ) !== false && array_key_exists( 'fontSlug', $font_setting ) ) {
|
|
$body_font_slug = $font_setting['fontSlug'];
|
|
$body_font_slug = $font_setting['fontSlug'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if( ! $body_font_slug && ! $heading_font_slug ) {
|
|
|
|
|
|
+ die( ':' . $body_font_slug . ':' . $heading_font_slug );
|
|
|
|
+
|
|
|
|
+ if ( ! $body_font_slug && ! $heading_font_slug ) {
|
|
//nothing to convert
|
|
//nothing to convert
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
// Get the user's global styles CPT id
|
|
// Get the user's global styles CPT id
|
|
- $user_custom_post_type_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
|
|
|
|
- $global_styles_controller = new WP_REST_Global_Styles_Controller();
|
|
|
|
- $global_styles = fetch_global_styles( $user_custom_post_type_id, $global_styles_controller );
|
|
|
|
-
|
|
|
|
|
|
+ $user_custom_post_type_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
|
|
|
|
+ $global_styles_controller = new WP_REST_Global_Styles_Controller();
|
|
|
|
+ $global_styles = fetch_global_styles( $user_custom_post_type_id, $global_styles_controller );
|
|
|
|
+
|
|
// converts data to array (in some cases settings and styles are objects insted of arrays)
|
|
// converts data to array (in some cases settings and styles are objects insted of arrays)
|
|
$new_settings = (array) $global_styles->data['settings'];
|
|
$new_settings = (array) $global_styles->data['settings'];
|
|
$new_styles = (array) $global_styles->data['styles'];
|
|
$new_styles = (array) $global_styles->data['styles'];
|
|
@@ -74,9 +78,9 @@ function migrate_blockbase_custom_fonts() {
|
|
}
|
|
}
|
|
|
|
|
|
// Set new typography settings (copy from Blockbase theme.json file)
|
|
// Set new typography settings (copy from Blockbase theme.json file)
|
|
- $parent_theme_json_data = json_decode( file_get_contents( get_template_directory() . '/theme.json'), true );
|
|
|
|
- $parent_theme = new WP_Theme_JSON( $parent_theme_json_data );
|
|
|
|
- $parent_font_families = $parent_theme->get_data()['settings']['typography']['fontFamilies'];
|
|
|
|
|
|
+ $parent_theme_json_data = json_decode( file_get_contents( get_template_directory() . '/theme.json' ), true );
|
|
|
|
+ $parent_theme = new WP_Theme_JSON( $parent_theme_json_data );
|
|
|
|
+ $parent_font_families = $parent_theme->get_data()['settings']['typography']['fontFamilies'];
|
|
$new_settings['typography']['fontFamilies'] = $parent_font_families;
|
|
$new_settings['typography']['fontFamilies'] = $parent_font_families;
|
|
|
|
|
|
update_global_styles( $new_settings, $new_styles, $user_custom_post_type_id, $global_styles_controller );
|
|
update_global_styles( $new_settings, $new_styles, $user_custom_post_type_id, $global_styles_controller );
|
|
@@ -119,4 +123,4 @@ function fetch_global_styles( $user_custom_post_type_id, $global_styles_controll
|
|
$global_styles = $global_styles_controller->get_item( $get_request );
|
|
$global_styles = $global_styles_controller->get_item( $get_request );
|
|
|
|
|
|
return $global_styles;
|
|
return $global_styles;
|
|
-}
|
|
|
|
|
|
+}
|