From dec6a3e792c7a9a445d6af55f8671f5dd0015fd5 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Thu, 1 Dec 2022 11:31:59 -0600 Subject: [PATCH] Separate style element from get_css() Moves the \n", - $this->type_attr, - $css - ); - return $css; } diff --git a/lib/experimental/class-wp-webfonts-provider.php b/lib/experimental/class-wp-webfonts-provider.php index 5113c0c46c023a..2de789bb7bb09d 100644 --- a/lib/experimental/class-wp-webfonts-provider.php +++ b/lib/experimental/class-wp-webfonts-provider.php @@ -34,6 +34,15 @@ */ abstract class WP_Webfonts_Provider { + /** + * The provider's unique ID. + * + * @since X.X.X + * + * @var string + */ + protected $id = ''; + /** * Webfonts to be processed. * @@ -43,6 +52,15 @@ abstract class WP_Webfonts_Provider { */ protected $webfonts = array(); + /** + * Font-face style tag's attribute(s). + * + * @since X.X.X + * + * @var string + */ + protected $style_tag_atts = ''; + /** * Sets this provider's webfonts property. * @@ -57,6 +75,18 @@ public function set_webfonts( array $webfonts ) { $this->webfonts = $webfonts; } + /** + * Prints the generated styles. + * + * @since X.X.X + */ + public function print_styles() { + printf( + $this->get_style_element(), + $this->get_css() + ); + } + /** * Gets the `@font-face` CSS for the provider's webfonts. * @@ -71,11 +101,13 @@ public function set_webfonts( array $webfonts ) { abstract public function get_css(); /** - * Prints the generated styles. + * Gets the `\n"; } } diff --git a/phpunit/fixtures/mock-provider.php b/phpunit/fixtures/mock-provider.php index 2e31092ac8f248..91475837e0e916 100644 --- a/phpunit/fixtures/mock-provider.php +++ b/phpunit/fixtures/mock-provider.php @@ -8,15 +8,20 @@ class Mock_Provider extends WP_Webfonts_Provider { */ protected $id = 'mock'; - /** - * CSS to print. - * - * @var string - */ - public $css = '%s\n'; - public function get_css() { $handles = array_keys( $this->webfonts ); + return implode( '; ', $handles ); return sprintf( $this->css, implode( '; ', $handles ) ); } + + /** + * Gets the `\n", + 'font-face-css' => << - CSS - , + , + ), ), 'woff2 format' => array( 'webfonts' => array( @@ -119,13 +136,14 @@ public function data_get_css() { 'src' => 'http://example.org/assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2', ), ), - 'expected' => << + 'expected' => array( + 'style-element' => "\n", + 'font-face-css' => << - CSS - , + + , + ), ), ); }