Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fonts API missing Theme JSON data layer integration #51369

Closed
webd-uk opened this issue Jun 9, 2023 · 1 comment
Closed

Fonts API missing Theme JSON data layer integration #51369

webd-uk opened this issue Jun 9, 2023 · 1 comment
Labels
[Type] Bug An existing feature does not function as intended

Comments

@webd-uk
Copy link

webd-uk commented Jun 9, 2023

Description

When using wp_deregister_font_family() (and I assume wp_deregister_font_variation() although I've not tested that) to attempt to deregister fonts that have been registered by theme.json the fonts remain.

We have done the following to remove fonts from theme.json which works nicely ...

        function wp_theme_json_data_theme_wp_deregister_font_family($theme_json_data_object) {

        	// Twenty Twenty-Three font slugs
        	$font_family_handles = array('dm-sans', 'ibm-plex-mono', 'inter', 'system-font', 'source-serif-pro');

                $theme_json_data = $theme_json_data_object->get_data();

                if (
                    isset($theme_json_data['settings']['typography']['fontFamilies']['theme']) &&
                    is_array($theme_json_data['settings']['typography']['fontFamilies']['theme']) &&
                    $theme_json_data['settings']['typography']['fontFamilies']['theme']
                ) {

                    foreach ($font_family_handles as $font_family_handle) {

                        foreach ($theme_json_data['settings']['typography']['fontFamilies']['theme'] as $key => $value) {

                            if (isset($value['slug']) && $font_family_handle === $value['slug']) {

                                unset($theme_json_data['settings']['typography']['fontFamilies']['theme'][$key]);
                                break;

                            }

                        }

                    }

                    $theme_json_data['settings']['typography']['fontFamilies']['theme'] = array_values($theme_json_data['settings']['typography']['fontFamilies']['theme']);

                    $theme_json_data_object->update_with($theme_json_data);

            }

            return $theme_json_data_object;

        }
            add_filter('wp_theme_json_data_theme', 'wp_theme_json_data_theme_wp_deregister_font_family');

Note that array_values() has to be used to re-order the theme array keys otherwise an error is observed in the site editor.

I'm not entirely sure how this would fit in with the wp_deregister_font_family() and wp_deregister_font_variation() functions but it's a start.

Step-by-step reproduction instructions

  1. Add the following in a custom plugin when using Twenty Twenty-Three theme ...
        function init_wp_deregister_font_family() {

        	$font_family_handles = array('dm-sans', 'ibm-plex-mono', 'inter', 'system-font', 'source-serif-pro');

                foreach ($font_family_handles as $font_family_handle) {

                    wp_deregister_font_family($font_family_handle);

                }

        }
         add_action('init', 'init_wp_deregister_font_family');
  1. Expected behaviour is that the "Dashboard - Appearance - Editor - Styles - Typography - Text - Typography" dropdown will not show and no font CSS / files will be enqueued because no fonts should be registered but the dropdown, CSS and files remain.

Screenshots, screen recording, code snippet

No response

Environment info

  • Wordpress v6.2.2, Gutenberg v15.9.1, Twenty Twenty-Three
  • All browsers
  • All devices

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@ndiego ndiego added [Feature] Fonts API [Type] Bug An existing feature does not function as intended labels Jun 13, 2023
@hellofromtonya
Copy link
Contributor

The Fonts API will be removed and replaced by Font Face (which is in trunk) when the Fonts Library is merged. Font Face does not have a register, enqueue, or remove (deregister, etc). Thus, this issue can be closed.

Thank you @webd-uk for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

3 participants