Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions blockbase/inc/customizer/wp-customize-fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,66 @@ class GlobalStylesFontsCustomizer {
);

function __construct() {
if ( $this->site_editor_is_implementing_google_fonts() ) {
add_action( 'customize_register', array( $this, 'init_deprecation_notice' ) );
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;

if ( defined( 'JETPACK__VERSION' ) ) {
$jetpack_has_google_fonts_module = JETPACK__VERSION === 'wpcom' || version_compare( JETPACK__VERSION, '10.8', '>' );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO:
Remove unnecessary reference to wpcom. We control all versioning for Jetpack, Gutenberg, and jetpack modules for simple sites.

}

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Jetpack::is_module_active always returns true for dotcom simple regardless of what value is passed to it. Unsure why at the moment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeyip yup that is by design. From a code comment on WPCOM_Site::is_module_active:

Always returns true. In Jetpack context it would actually check if a module is active or not because the module loading relies on the 'jetpack_active_modules' option. Here in WordPress.com context however, we always load everything, so in order to enable or disable something we have to check each module's settings.

}

function init_deprecation_notice( $wp_customize ) {
$wp_customize->add_section(
$this->section_key,
array(
'capability' => 'edit_theme_options',
'title' => __( 'Fonts', 'blockbase' ),
)
);

$wp_customize->add_control(
$this->section_key . '-v1-blockbase-font-deprecation-notice',
array(
'type' => 'hidden',
'description' => '<div class="notice notice-info">
<p>' . __( 'Updating fonts for this theme is now even easier! Use the site editor to select and preview different font families.', 'blockbase' ) . '</p>
</div>',
'settings' => array(),
'section' => $this->section_key,
)
);

$wp_customize->add_control(
$this->section_key . '-site-editor-button',
array(
'type' => 'hidden',
'description' => sprintf( '<a class="button button-primary" href=%s style="font-style: normal;" >Use Site Editor</a>', esc_url( admin_url( 'site-editor.php' ) ) ),
'settings' => array(),
'section' => $this->section_key,
)
);
}


function handle_customize_preview_init( $wp_customize ) {
$this->update_font_settings( $wp_customize );
$this->customize_preview_js( $wp_customize );
Expand Down