From dcef9bdd155fc3c0e186e90698ff1cb95f986747 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Mon, 10 Jul 2023 13:58:38 -0500 Subject: [PATCH 1/3] Deprecate and make Fonts API non-functional. With Font Face, the Fonts API is no longer needed. However for sites using Fonts API, the public facing functions, classes, and methods still need to be available in memory to avoid fatal errors. This commit: 1. Adds a bc-layer into the Font Face. 2. Copies each of the Fonts API files into it. 3. Deprecates each file and public function, class, and method. 4. Makes each function and method non-functional. --- .../class-gutenberg-fonts-api-bc-layer.php | 49 +++ .../class-wp-fonts-provider-local.php | 46 +++ .../bc-layer/class-wp-fonts-provider.php | 98 ++++++ .../bc-layer/class-wp-fonts-resolver.php | 64 ++++ .../fonts/bc-layer/class-wp-fonts-utils.php | 74 +++++ .../fonts/bc-layer/class-wp-fonts.php | 199 ++++++++++++ .../fonts/bc-layer/class-wp-web-fonts.php | 190 ++++++++++++ .../class-wp-webfonts-provider-local.php | 65 ++++ .../bc-layer/class-wp-webfonts-provider.php | 53 ++++ .../bc-layer/class-wp-webfonts-utils.php | 82 +++++ .../fonts/bc-layer/class-wp-webfonts.php | 146 +++++++++ .../fonts/bc-layer/webfonts-deprecations.php | 291 ++++++++++++++++++ 12 files changed, 1357 insertions(+) create mode 100644 lib/experimental/fonts/bc-layer/class-gutenberg-fonts-api-bc-layer.php create mode 100644 lib/experimental/fonts/bc-layer/class-wp-fonts-provider-local.php create mode 100644 lib/experimental/fonts/bc-layer/class-wp-fonts-provider.php create mode 100644 lib/experimental/fonts/bc-layer/class-wp-fonts-resolver.php create mode 100644 lib/experimental/fonts/bc-layer/class-wp-fonts-utils.php create mode 100644 lib/experimental/fonts/bc-layer/class-wp-fonts.php create mode 100644 lib/experimental/fonts/bc-layer/class-wp-web-fonts.php create mode 100644 lib/experimental/fonts/bc-layer/class-wp-webfonts-provider-local.php create mode 100644 lib/experimental/fonts/bc-layer/class-wp-webfonts-provider.php create mode 100644 lib/experimental/fonts/bc-layer/class-wp-webfonts-utils.php create mode 100644 lib/experimental/fonts/bc-layer/class-wp-webfonts.php create mode 100644 lib/experimental/fonts/bc-layer/webfonts-deprecations.php diff --git a/lib/experimental/fonts/bc-layer/class-gutenberg-fonts-api-bc-layer.php b/lib/experimental/fonts/bc-layer/class-gutenberg-fonts-api-bc-layer.php new file mode 100644 index 0000000000000..7cf041148eedd --- /dev/null +++ b/lib/experimental/fonts/bc-layer/class-gutenberg-fonts-api-bc-layer.php @@ -0,0 +1,49 @@ +` element for wrapping the `@font-face` CSS. + * + * @since X.X.X + * @deprecated 16.3.0 Get style element is not supported. + * + * @return string Empty string. + */ + protected function get_style_element() { + _deprecated_function( __METHOD__, 'Gutenberg 16.3.0' ); + return ''; + } +} diff --git a/lib/experimental/fonts/bc-layer/class-wp-fonts-resolver.php b/lib/experimental/fonts/bc-layer/class-wp-fonts-resolver.php new file mode 100644 index 0000000000000..c2702348b9523 --- /dev/null +++ b/lib/experimental/fonts/bc-layer/class-wp-fonts-resolver.php @@ -0,0 +1,64 @@ +get_registered_font_families(). + * @deprecated 16.3.0 Register is not supported. + * + * @return array Empty array. + */ + public function get_registered_font_families() { + _deprecated_function( __METHOD__, 'Gutenberg 15.8.0' ); + return array(); + } + + /** + * Gets the list of registered fonts. + * + * @since 6.0.0 + * @deprecated 14.9.1 Use wp_fonts()->get_registered(). + * @deprecated 16.3.0 Register is not supported. + * + * @return array Empty array. + */ + public function get_registered_webfonts() { + _deprecated_function( __METHOD__, 'Gutenberg 14.9.1' ); + + return array(); + } + + /** + * Gets the list of enqueued fonts. + * + * @since 6.0.0 + * @deprecated 14.9.1 Use wp_fonts()->get_enqueued(). + * @deprecated 16.3.0 Enqueue is not supported. + * + * @return array Empty array. + */ + public function get_enqueued_webfonts() { + _deprecated_function( __METHOD__, 'Gutenberg 14.9.1' ); + return array(); + } + + /** + * Gets the list of all fonts. + * + * @since X.X.X + * @deprecated GB 14.9.1 Use wp_fonts()->get_registered(). + * @deprecated 16.3.0 This method is not supported. + * + * @return array[] + */ + public function get_all_webfonts() { + _deprecated_function( __METHOD__, 'Gutenberg 14.9.1', 'wp_fonts()->get_registered()' ); + return array(); + } + + /** + * Registers a webfont. + * + * @since 6.0.0 + * @deprecated GB 14.9.1 Use wp_register_fonts(). + * @deprecated 16.3.0 Register is not supported. + * + * @return bool False. + */ + public function register_webfont() { + _deprecated_function( __METHOD__, 'GB 14.9.1', 'wp_register_fonts()' ); + return false; + } + + /** + * Enqueue a font-family that has been already registered. + * + * @since XX.X + * @deprecated 14.9.1 Use wp_enqueue_fonts(). + * @deprecated 16.3.0 Register is not supported. + * + * @return bool False. + */ + public function enqueue_webfont() { + _deprecated_function( __METHOD__, 'Gutenberg 14.9.1' ); + return false; + } +} diff --git a/lib/experimental/fonts/bc-layer/webfonts-deprecations.php b/lib/experimental/fonts/bc-layer/webfonts-deprecations.php new file mode 100644 index 0000000000000..4de2e6221d50b --- /dev/null +++ b/lib/experimental/fonts/bc-layer/webfonts-deprecations.php @@ -0,0 +1,291 @@ +get_providers(). + * @deprecated 16.3.0 Providers are not supported. + * + * @return array Empty array. + */ + function wp_get_webfont_providers() { + _deprecated_function( __FUNCTION__, '14.9.1' ); + + return array(); + } +} + +if ( ! function_exists( 'wp_register_webfont_provider' ) ) { + /** + * Registers a custom font service provider. + * + * @since X.X.X + * @deprecated 15.1 Use wp_register_font_provider() instead. + * @deprecated 16.3.0 Providers are not supported. + * + * @return bool False. + */ + function wp_register_webfont_provider() { + _deprecated_function( __FUNCTION__, 'GB 15.1', 'wp_register_font_provider' ); + return false; + } +} + +if ( ! function_exists( 'wp_print_webfonts' ) ) { + /** + * Invokes each provider to process and print its styles. + * + * @since 14.9.1 + * @deprecated 15.1 Use wp_print_fonts() instead. + * @deprecated 16.3.0 Webfonts API is not supported. + * + * @return array Empty array. + */ + function wp_print_webfonts() { + _deprecated_function( __FUNCTION__, 'Gutenberg 15.1', 'wp_print_font_faces' ); + return array(); + } +} + +if ( ! function_exists( 'wp_fonts' ) ) { + /** + * Initialize $wp_fonts if it has not been set. + * + * @since X.X.X + * @deprecated 16.3.0 Use Fonts Library and Font Face. Fonts API is not supported. + * + * @global WP_Fonts $wp_fonts + * + * @return WP_Fonts WP_Fonts instance. + */ + function wp_fonts() { + _deprecated_function( __FUNCTION__, 'Gutenberg 16.3' ); + + global $wp_fonts; + + if ( ! ( $wp_fonts instanceof WP_Fonts ) ) { + $wp_fonts = new WP_Fonts(); + } + + return $wp_fonts; + } +} + +if ( ! function_exists( 'wp_register_fonts' ) ) { + /** + * Registers one or more font-families and each of their variations. + * + * @since X.X.X + * @deprecated 16.3.0 Register is not supported. + * + * @return array Empty array. + */ + function wp_register_fonts() { + _deprecated_function( __FUNCTION__, 'Gutenberg 16.3' ); + return array(); + } +} + +if ( ! function_exists( 'wp_enqueue_fonts' ) ) { + /** + * Enqueues one or more font family and all of its variations. + * + * @since X.X.X + * @deprecated 16.3.0 Enqueue is not supported. + */ + function wp_enqueue_fonts() { + _deprecated_function( __FUNCTION__, 'Gutenberg 16.3' ); + } +} + +if ( ! function_exists( 'wp_enqueue_font_variations' ) ) { + /** + * Enqueues a specific set of font variations. + * + * @since X.X.X + * @deprecated 16.3.0 Enqueue is not supported. + */ + function wp_enqueue_font_variations() { + _deprecated_function( __FUNCTION__, 'Gutenberg 16.3' ); + } +} + +if ( ! function_exists( 'wp_deregister_font_family' ) ) { + /** + * Deregisters a font family and all of its registered variations. + * + * @since X.X.X + * @deprecated 16.3.0 Deregister is not supported. + */ + function wp_deregister_font_family() { + _deprecated_function( __FUNCTION__, 'Gutenberg 16.3' ); + } +} + +if ( ! function_exists( 'wp_deregister_font_variation' ) ) { + /** + * Deregisters a font variation. + * + * @since X.X.X + * @deprecated 16.3.0 Deregister is not supported. + */ + function wp_deregister_font_variation() { + _deprecated_function( __FUNCTION__, 'Gutenberg 16.3' ); + } +} + +if ( ! function_exists( 'wp_register_font_provider' ) ) { + /** + * Registers a custom font service provider. + * + * @since X.X.X + * @deprecated 16.3.0 Providers are not supported. + * + * @return bool False. + */ + function wp_register_font_provider() { + _deprecated_function( __FUNCTION__, 'Gutenberg 16.3' ); + return false; + } +} + +if ( ! function_exists( 'wp_print_fonts' ) ) { + /** + * Invokes each provider to process and print its styles. + * + * @since X.X.X + * @deprecated 16.3.0 For classic themes, use wp_print_font_faces(). For all other sites, + * Font Face will automatically print all fonts in theme.json merged data layer, + * including in theme and user activated fonts from the Fonts Library. + * + * @return array Empty array. + */ + function wp_print_fonts() { + _deprecated_function( __FUNCTION__, 'Gutenberg 16.3', 'wp_print_font_faces' ); + return array(); + } +} From 71f09acf1ad6b0453b679a1609a85fa26ed108c0 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Mon, 10 Jul 2023 14:08:51 -0500 Subject: [PATCH 2/3] Load the BC Layer --- lib/load.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/load.php b/lib/load.php index 340a900130405..ef55c547525ae 100644 --- a/lib/load.php +++ b/lib/load.php @@ -142,6 +142,21 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/experimental/fonts/class-wp-font-face.php'; require __DIR__ . '/experimental/fonts/class-wp-font-face-resolver.php'; require __DIR__ . '/experimental/fonts/fonts.php'; + + // Load the BC Layer. Do no backport to WP Core. + require __DIR__ . '/experimental/fonts/bc-layer/class-wp-fonts-provider.php'; + require __DIR__ . '/experimental/fonts/bc-layer/class-wp-fonts-utils.php'; + require __DIR__ . '/experimental/fonts/bc-layer/class-wp-fonts.php'; + require __DIR__ . '/experimental/fonts/bc-layer/class-wp-fonts-provider-local.php'; + require __DIR__ . '/experimental/fonts/bc-layer/class-wp-fonts-resolver.php'; + require __DIR__ . '/experimental/fonts/bc-layer/fonts-api.php'; + require __DIR__ . '/experimental/fonts/bc-layer/class-gutenberg-fonts-api-bc-layer.php'; + require __DIR__ . '/experimental/fonts/bc-layer/webfonts-deprecations.php'; + require __DIR__ . '/experimental/fonts/bc-layer/class-wp-webfonts-utils.php'; + require __DIR__ . '/experimental/fonts/bc-layer/class-wp-webfonts-provider.php'; + require __DIR__ . '/experimental/fonts/bc-layer/class-wp-webfonts-provider-local.php'; + require __DIR__ . '/experimental/fonts/bc-layer/class-wp-webfonts.php'; + require __DIR__ . '/experimental/fonts/bc-layer/class-wp-web-fonts.php'; } } elseif ( ! class_exists( 'WP_Fonts' ) ) { // Fonts API files. From b994215e3421e31550605f56fb9873af5f225c15 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Tue, 11 Jul 2023 15:49:56 -0500 Subject: [PATCH 3/3] Do not load fonts-api.php file --- lib/load.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/load.php b/lib/load.php index ef55c547525ae..7ec11252e72e8 100644 --- a/lib/load.php +++ b/lib/load.php @@ -149,7 +149,6 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/experimental/fonts/bc-layer/class-wp-fonts.php'; require __DIR__ . '/experimental/fonts/bc-layer/class-wp-fonts-provider-local.php'; require __DIR__ . '/experimental/fonts/bc-layer/class-wp-fonts-resolver.php'; - require __DIR__ . '/experimental/fonts/bc-layer/fonts-api.php'; require __DIR__ . '/experimental/fonts/bc-layer/class-gutenberg-fonts-api-bc-layer.php'; require __DIR__ . '/experimental/fonts/bc-layer/webfonts-deprecations.php'; require __DIR__ . '/experimental/fonts/bc-layer/class-wp-webfonts-utils.php';