Skip to content

Commit 0ecd619

Browse files
authored
Merge pull request #14 from brainstormforce/css-embed
Version 1.0.9 - Improvement: Use CSS embed method for enqueueing TypeKit fonts. This should remove the slight delay in displaying the TypeKit fonts on the page, - Fix: Post URL in the Block Editor goes behind the Editor Top Bar.
2 parents dfaf826 + 3357867 commit 0ecd619

File tree

5 files changed

+36
-24
lines changed

5 files changed

+36
-24
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
**Tags:** custom typekit fonts, theme custom fonts, unlimited typekit custom fonts
55
**Requires at least:** 4.4
66
**Tested up to:** 5.0
7-
**Stable tag:** 1.0.8
7+
**Stable tag:** 1.0.9
88
**License:** GPLv2 or later
99
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -49,6 +49,10 @@ If you're not using any of the supported plugins and theme, you can write the cu
4949

5050
## Changelog ##
5151

52+
### v1.0.9 ###
53+
- Improvement: Use CSS embed method for enqueueing TypeKit fonts. This should remove the slight delay in displaying the TypeKit fonts on the page,
54+
- Fix: Post URL in the Block Editor goes behind the Editor Top Bar.
55+
5256
### v1.0.8 ###
5357
- Fixed: A few TypeKit fonts not being rendered correctly.
5458

classes/class-custom-typekit-fonts-render.php

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
class Custom_Typekit_Fonts_Render {
1717

18+
const TYPEKIT_EMBED_BASE = 'https://use.typekit.net/%s.css';
19+
1820
/**
1921
* Instance of Custom_Typekit_Fonts_Render
2022
*
@@ -62,7 +64,7 @@ public static function get_instance() {
6264
*/
6365
public function __construct() {
6466

65-
add_action( 'wp_head', array( $this, 'typekit_embed_head' ) );
67+
add_action( 'wp_enqueue_scripts', array( $this, 'typekit_embed_css' ) );
6668
// add Custom Font list into Astra customizer.
6769
add_action( 'astra_customizer_font_list', array( $this, 'add_customizer_font_list' ) );
6870
add_action( 'astra_render_fonts', array( $this, 'render_fonts' ) );
@@ -74,7 +76,7 @@ public function __construct() {
7476
add_filter( 'elementor/fonts/groups', array( $this, 'elementor_group' ) );
7577
add_filter( 'elementor/fonts/additional_fonts', array( $this, 'add_elementor_fonts' ) );
7678

77-
add_action( 'enqueue_block_editor_assets', array( $this, 'typekit_embed_head' ) );
79+
add_action( 'enqueue_block_editor_assets', array( $this, 'typekit_embed_css' ) );
7880
}
7981

8082
/**
@@ -115,28 +117,30 @@ public function add_elementor_fonts( $fonts ) {
115117
}
116118

117119
/**
118-
* Add Script into wp head
120+
* Enqueue Typekit CSS.
119121
*
120-
* @since 1.0.0
122+
* @return void
121123
*/
122-
function typekit_embed_head() {
124+
public function typekit_embed_css() {
125+
126+
if ( false !== $this->get_typekit_embed_url() ) {
127+
wp_enqueue_style( 'custom-typekit-css', $this->get_typekit_embed_url(), array() );
128+
}
129+
130+
}
131+
132+
/**
133+
* Get Typekit CSS embed URL
134+
*
135+
* @return String|Boolean If Kit ID is available the URL for typekit embed is returned.
136+
*/
137+
private function get_typekit_embed_url() {
123138
$kit_info = get_option( 'custom-typekit-fonts' );
124139
if ( empty( $kit_info['custom-typekit-font-details'] ) ) {
125-
return;
140+
return false;
126141
}
127-
?>
128-
<script type="text/javascript">
129-
(function(d) {
130-
var config = {
131-
kitId : '<?php echo esc_js( $kit_info['custom-typekit-font-id'] ); ?>',
132-
scriptTimeout : 3000,
133-
async : true
134-
},
135-
h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\bwf-loading\b/g,"")+" wf-inactive";},config.scriptTimeout),tk=d.createElement("script"),f=false,s=d.getElementsByTagName("script")[0],a;h.className+=" wf-loading";tk.src='https://use.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!="complete"&&a!="loaded")return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s)
136-
})(document);
137-
</script>
138-
139-
<?php
142+
143+
return sprintf( self::TYPEKIT_EMBED_BASE, $kit_info['custom-typekit-font-id'] );
140144
}
141145

142146
/**

custom-typekit-fonts.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Author: Brainstorm Force
77
* Author URI: http://www.brainstormforce.com
88
* Text Domain: custom-typekit-fonts
9-
* Version: 1.0.8
9+
* Version: 1.0.9
1010
*
1111
* @package Typekit_Custom_Fonts
1212
*/
@@ -25,7 +25,7 @@
2525
define( 'CUSTOM_TYPEKIT_FONTS_BASE', plugin_basename( CUSTOM_TYPEKIT_FONTS_FILE ) );
2626
define( 'CUSTOM_TYPEKIT_FONTS_DIR', plugin_dir_path( CUSTOM_TYPEKIT_FONTS_FILE ) );
2727
define( 'CUSTOM_TYPEKIT_FONTS_URI', plugins_url( '/', CUSTOM_TYPEKIT_FONTS_FILE ) );
28-
define( 'CUSTOM_TYPEKIT_FONTS_VER', '1.0.8' );
28+
define( 'CUSTOM_TYPEKIT_FONTS_VER', '1.0.9' );
2929
/**
3030
* BSF Custom Fonts
3131
*/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "custom-typekit-fonts",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"main": "Gruntfile.js",
55
"author": "YOUR NAME HERE",
66
"devDependencies": {

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://wpastra.com/
44
Tags: custom typekit fonts, theme custom fonts, unlimited typekit custom fonts
55
Requires at least: 4.4
66
Tested up to: 5.0
7-
Stable tag: 1.0.8
7+
Stable tag: 1.0.9
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -49,6 +49,10 @@ If you're not using any of the supported plugins and theme, you can write the cu
4949

5050
== Changelog ==
5151

52+
= v1.0.9 =
53+
- Improvement: Use CSS embed method for enqueueing TypeKit fonts. This should remove the slight delay in displaying the TypeKit fonts on the page,
54+
- Fix: Post URL in the Block Editor goes behind the Editor Top Bar.
55+
5256
= v1.0.8 =
5357
- Fixed: A few TypeKit fonts not being rendered correctly.
5458

0 commit comments

Comments
 (0)