diff --git a/lib/experimental/class-wp-webfonts-provider-local.php b/lib/experimental/class-wp-webfonts-provider-local.php
index 4959fe6f586c2..bf04108524dd7 100644
--- a/lib/experimental/class-wp-webfonts-provider-local.php
+++ b/lib/experimental/class-wp-webfonts-provider-local.php
@@ -35,18 +35,6 @@ class WP_Webfonts_Provider_Local extends WP_Webfonts_Provider {
*/
protected $id = 'local';
- /**
- * Holds a string which contains the type attribute for style tag.
- *
- * If the active theme does not declare HTML5 support for 'style',
- * then it initializes as `type='text/css'`.
- *
- * @since 6.1.0
- *
- * @var string
- */
- private $type_attr = '';
-
/**
* Constructor.
*
@@ -58,7 +46,7 @@ function_exists( 'is_admin' ) && ! is_admin()
&&
function_exists( 'current_theme_supports' ) && ! current_theme_supports( 'html5', 'style' )
) {
- $this->type_attr = " type='text/css'";
+ $this->style_tag_atts = " type='text/css'";
}
}
@@ -123,12 +111,6 @@ public function get_css() {
$css .= '@font-face{' . $this->build_font_face_css( $webfont ) . '}';
}
- $css = sprintf(
- "\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 5113c0c46c023..2de789bb7bb09 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 2e31092ac8f24..91475837e0e91 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
- ,
+
+ ,
+ ),
),
);
}