From 0e5448c571961c0d80249561c1246e9ca9b05446 Mon Sep 17 00:00:00 2001 From: Jeremy Yip Date: Thu, 5 May 2022 18:47:08 -0700 Subject: [PATCH 1/5] Only disply blockbase font customizer settings if not enabled in site editor --- .../inc/customizer/wp-customize-fonts.php | 59 +++++++++++++------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/blockbase/inc/customizer/wp-customize-fonts.php b/blockbase/inc/customizer/wp-customize-fonts.php index c2457292f2..c2b9871c5e 100644 --- a/blockbase/inc/customizer/wp-customize-fonts.php +++ b/blockbase/inc/customizer/wp-customize-fonts.php @@ -210,10 +210,28 @@ class GlobalStylesFontsCustomizer { function __construct() { add_action( 'customize_register', array( $this, 'initialize' ) ); - add_action( 'customize_preview_init', array( $this, 'handle_customize_preview_init' ) ); - add_action( 'customize_register', array( $this, 'enqueue_google_fonts' ) ); - add_action( 'customize_save_after', array( $this, 'handle_customize_save_after' ) ); - add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_control_js' ) ); + + if ( !$this->site_editor_is_implementing_google_fonts() ) { + add_action( 'customize_preview_init', array( $this, 'handle_customize_preview_init' ) ); + add_action( 'customize_register', array( $this, 'enqueue_google_fonts' ) ); + add_action( 'customize_save_after', array( $this, 'handle_customize_save_after' ) ); + add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_control_js' ) ); + } + } + + function site_editor_is_implementing_google_fonts() { + $jetpack_has_google_fonts_module = false; + $gutenberg_webfonts_api_supports_enqueueing = false; + + if ( defined( 'JETPACK__VERSION' ) ) { + $jetpack_has_google_fonts_module = JETPACK__VERSION === 'wpcom' || version_compare( JETPACK__VERSION, '10.8', '>' ); + } + + if ( defined( 'GUTENBERG_VERSION' ) ) { + $gutenberg_webfonts_api_supports_enqueueing = version_compare( GUTENBERG_VERSION, '13.0', '>=' ); + } + + return $jetpack_has_google_fonts_module && $gutenberg_webfonts_api_supports_enqueueing && Jetpack::is_module_active( 'google-fonts' ); } function handle_customize_preview_init( $wp_customize ) { @@ -396,21 +414,26 @@ function( $font_family ) { // Add a reset button $this->font_control_default_body = $body_font_default['fontSlug']; $this->font_control_default_heading = $heading_font_default['fontSlug']; - $wp_customize->add_control( - $this->section_key . '-reset-button', - array( - 'type' => 'button', - 'settings' => array(), - 'section' => $this->section_key, - 'input_attrs' => array( - 'value' => __( 'Reset to Default', 'blockbase' ), - 'class' => 'button button-link', - ), - ) - ); - $this->add_setting_and_control( $wp_customize, 'body', __( 'Body font', 'blockbase' ), $body_font_default['fontSlug'], $body_font_selected_font_slug, 'sanitize_title' ); - $this->add_setting_and_control( $wp_customize, 'heading', __( 'Heading font', 'blockbase' ), $heading_font_default['fontSlug'], $heading_font_selected_font_slug, 'sanitize_title' ); + if ( $this->site_editor_is_implementing_google_fonts() ) { + // TODO: Render HTML notification to user to use google fonts in the site editor instead of the customizer + } else { + $wp_customize->add_control( + $this->section_key . '-reset-button', + array( + 'type' => 'button', + 'settings' => array(), + 'section' => $this->section_key, + 'input_attrs' => array( + 'value' => __( 'Reset to Default', 'blockbase' ), + 'class' => 'button button-link', + ), + ) + ); + + $this->add_setting_and_control( $wp_customize, 'body', __( 'Body font', 'blockbase' ), $body_font_default['fontSlug'], $body_font_selected_font_slug, 'sanitize_title' ); + $this->add_setting_and_control( $wp_customize, 'heading', __( 'Heading font', 'blockbase' ), $heading_font_default['fontSlug'], $heading_font_selected_font_slug, 'sanitize_title' ); + } } function get_font_family( $array, $configuration ) { From 1d641fe5b8838672297486c8c50e6f50520d57fd Mon Sep 17 00:00:00 2001 From: Jeremy Yip Date: Fri, 6 May 2022 14:31:02 -0700 Subject: [PATCH 2/5] Add notification for users to use the site editor --- .../inc/customizer/wp-customize-fonts.php | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/blockbase/inc/customizer/wp-customize-fonts.php b/blockbase/inc/customizer/wp-customize-fonts.php index c2b9871c5e..a2cefd3ac7 100644 --- a/blockbase/inc/customizer/wp-customize-fonts.php +++ b/blockbase/inc/customizer/wp-customize-fonts.php @@ -209,16 +209,18 @@ class GlobalStylesFontsCustomizer { ); function __construct() { - add_action( 'customize_register', array( $this, 'initialize' ) ); - - if ( !$this->site_editor_is_implementing_google_fonts() ) { - add_action( 'customize_preview_init', array( $this, 'handle_customize_preview_init' ) ); - add_action( 'customize_register', array( $this, 'enqueue_google_fonts' ) ); - add_action( 'customize_save_after', array( $this, 'handle_customize_save_after' ) ); - add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_control_js' ) ); + if ( $this->site_editor_is_implementing_google_fonts() ) { + add_action( 'customize_register', array( $this, 'display_section_redirecting_users_to_site_editor' ) ); + return; } + + add_action( 'customize_register', array( $this, 'initialize' ) ); + add_action( 'customize_preview_init', array( $this, 'handle_customize_preview_init' ) ); + add_action( 'customize_register', array( $this, 'enqueue_google_fonts' ) ); + add_action( 'customize_save_after', array( $this, 'handle_customize_save_after' ) ); + add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_control_js' ) ); } - + function site_editor_is_implementing_google_fonts() { $jetpack_has_google_fonts_module = false; $gutenberg_webfonts_api_supports_enqueueing = false; @@ -234,6 +236,34 @@ function site_editor_is_implementing_google_fonts() { return $jetpack_has_google_fonts_module && $gutenberg_webfonts_api_supports_enqueueing && Jetpack::is_module_active( 'google-fonts' ); } + function display_section_redirecting_users_to_site_editor( $wp_customize ) { + $wp_customize->add_section( + $this->section_key, + array( + 'capability' => 'edit_theme_options', + 'description' => 'Updating fonts for this theme is now even easier! Please use the site editor to select and preview different font families.', + 'title' => __( 'Fonts', 'blockbase' ), + ) + ); + + $wp_customize->add_control( + $this->section_key . '-site-editor-button', + array( + 'type' => 'button', + 'settings' => array(), + 'section' => $this->section_key, + 'input_attrs' => array( + 'value' => __( 'Use Site Editor', 'blockbase' ), + 'class' => 'button button-link', + 'data-action' => sprintf("%s", esc_url( admin_url( 'site-editor.php' ) ) ), + ), + ) + ); + + $wp_customize->get_section( $this->section_key ); + } + + function handle_customize_preview_init( $wp_customize ) { $this->update_font_settings( $wp_customize ); $this->customize_preview_js( $wp_customize ); From 004718f4a9b52889b1cab75a4a5771e0dcc00112 Mon Sep 17 00:00:00 2001 From: Jeremy Yip Date: Fri, 6 May 2022 14:32:53 -0700 Subject: [PATCH 3/5] Revert changes to init function --- .../inc/customizer/wp-customize-fonts.php | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/blockbase/inc/customizer/wp-customize-fonts.php b/blockbase/inc/customizer/wp-customize-fonts.php index a2cefd3ac7..568d199d1b 100644 --- a/blockbase/inc/customizer/wp-customize-fonts.php +++ b/blockbase/inc/customizer/wp-customize-fonts.php @@ -445,25 +445,21 @@ function( $font_family ) { $this->font_control_default_body = $body_font_default['fontSlug']; $this->font_control_default_heading = $heading_font_default['fontSlug']; - if ( $this->site_editor_is_implementing_google_fonts() ) { - // TODO: Render HTML notification to user to use google fonts in the site editor instead of the customizer - } else { - $wp_customize->add_control( - $this->section_key . '-reset-button', - array( - 'type' => 'button', - 'settings' => array(), - 'section' => $this->section_key, - 'input_attrs' => array( - 'value' => __( 'Reset to Default', 'blockbase' ), - 'class' => 'button button-link', - ), - ) - ); - - $this->add_setting_and_control( $wp_customize, 'body', __( 'Body font', 'blockbase' ), $body_font_default['fontSlug'], $body_font_selected_font_slug, 'sanitize_title' ); - $this->add_setting_and_control( $wp_customize, 'heading', __( 'Heading font', 'blockbase' ), $heading_font_default['fontSlug'], $heading_font_selected_font_slug, 'sanitize_title' ); - } + $wp_customize->add_control( + $this->section_key . '-reset-button', + array( + 'type' => 'button', + 'settings' => array(), + 'section' => $this->section_key, + 'input_attrs' => array( + 'value' => __( 'Reset to Default', 'blockbase' ), + 'class' => 'button button-link', + ), + ) + ); + + $this->add_setting_and_control( $wp_customize, 'body', __( 'Body font', 'blockbase' ), $body_font_default['fontSlug'], $body_font_selected_font_slug, 'sanitize_title' ); + $this->add_setting_and_control( $wp_customize, 'heading', __( 'Heading font', 'blockbase' ), $heading_font_default['fontSlug'], $heading_font_selected_font_slug, 'sanitize_title' ); } function get_font_family( $array, $configuration ) { From 9b9b688148ea3aa8895e490e0a19bdf9cdb5aea4 Mon Sep 17 00:00:00 2001 From: Jeremy Yip Date: Fri, 6 May 2022 14:34:19 -0700 Subject: [PATCH 4/5] Remove newline --- blockbase/inc/customizer/wp-customize-fonts.php | 1 - 1 file changed, 1 deletion(-) diff --git a/blockbase/inc/customizer/wp-customize-fonts.php b/blockbase/inc/customizer/wp-customize-fonts.php index 568d199d1b..d8b7194074 100644 --- a/blockbase/inc/customizer/wp-customize-fonts.php +++ b/blockbase/inc/customizer/wp-customize-fonts.php @@ -444,7 +444,6 @@ function( $font_family ) { // Add a reset button $this->font_control_default_body = $body_font_default['fontSlug']; $this->font_control_default_heading = $heading_font_default['fontSlug']; - $wp_customize->add_control( $this->section_key . '-reset-button', array( From 443bf63e88647ff485fa6f62853bb82bdb5f25f9 Mon Sep 17 00:00:00 2001 From: Jeremy Yip Date: Fri, 6 May 2022 15:55:28 -0700 Subject: [PATCH 5/5] Refactor deprecation notice --- .../inc/customizer/wp-customize-fonts.php | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/blockbase/inc/customizer/wp-customize-fonts.php b/blockbase/inc/customizer/wp-customize-fonts.php index d8b7194074..e4313dfc38 100644 --- a/blockbase/inc/customizer/wp-customize-fonts.php +++ b/blockbase/inc/customizer/wp-customize-fonts.php @@ -209,8 +209,8 @@ class GlobalStylesFontsCustomizer { ); function __construct() { - if ( $this->site_editor_is_implementing_google_fonts() ) { - add_action( 'customize_register', array( $this, 'display_section_redirecting_users_to_site_editor' ) ); + if ( $this->site_editor_is_implementing_google_fonts() ) { + add_action( 'customize_register', array( $this, 'init_deprecation_notice' ) ); return; } @@ -236,31 +236,36 @@ function site_editor_is_implementing_google_fonts() { return $jetpack_has_google_fonts_module && $gutenberg_webfonts_api_supports_enqueueing && Jetpack::is_module_active( 'google-fonts' ); } - function display_section_redirecting_users_to_site_editor( $wp_customize ) { + function init_deprecation_notice( $wp_customize ) { $wp_customize->add_section( $this->section_key, array( 'capability' => 'edit_theme_options', - 'description' => 'Updating fonts for this theme is now even easier! Please use the site editor to select and preview different font families.', 'title' => __( 'Fonts', 'blockbase' ), ) ); $wp_customize->add_control( - $this->section_key . '-site-editor-button', + $this->section_key . '-v1-blockbase-font-deprecation-notice', array( - 'type' => 'button', + 'type' => 'hidden', + 'description' => '
+

' . __( 'Updating fonts for this theme is now even easier! Use the site editor to select and preview different font families.', 'blockbase' ) . '

+
', 'settings' => array(), 'section' => $this->section_key, - 'input_attrs' => array( - 'value' => __( 'Use Site Editor', 'blockbase' ), - 'class' => 'button button-link', - 'data-action' => sprintf("%s", esc_url( admin_url( 'site-editor.php' ) ) ), - ), ) ); - $wp_customize->get_section( $this->section_key ); + $wp_customize->add_control( + $this->section_key . '-site-editor-button', + array( + 'type' => 'hidden', + 'description' => sprintf( 'Use Site Editor', esc_url( admin_url( 'site-editor.php' ) ) ), + 'settings' => array(), + 'section' => $this->section_key, + ) + ); }