forked from dimadin/disable-google-fonts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisable-google-fonts.php
154 lines (139 loc) · 4.73 KB
/
disable-google-fonts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
* The Disable Google Fonts Plugin
*
* Disable enqueuing of Open Sans and other fonts used by WordPress from Google.
*
* @package Disable_Google_Fonts
* @subpackage Main
*/
/**
* Plugin Name: Disable Google Fonts
* Plugin URI: http://blog.milandinic.com/wordpress/plugins/disable-google-fonts/
* Description: Disable enqueuing of Open Sans and other fonts used by WordPress from Google.
* Author: Milan Dinić
* Author URI: http://blog.milandinic.com/
* Version: 1.0
* License: GPL
*/
/* Exit if accessed directly */
if ( ! defined( 'ABSPATH' ) ) exit;
class Disable_Google_Fonts {
/**
* Hook actions and filters.
*
* @since 1.0
* @access public
*/
public function __construct() {
add_filter( 'gettext_with_context', array( $this, 'disable_open_sans' ), 888, 4 );
add_action( 'after_setup_theme', array( $this, 'register_theme_fonts_disabler' ), 1 );
}
/**
* Force 'off' as a result of Open Sans font toggler string translation.
*
* @since 1.0
* @access public
*
* @param string $translations Translated text.
* @param string $text Text to translate.
* @param string $context Context information for the translators.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @return string $translations Translated text.
*/
public function disable_open_sans( $translations, $text, $context, $domain ) {
if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}
return $translations;
}
/**
* Force 'off' as a result of Lato font toggler string translation.
*
* @since 1.0
* @access public
*
* @param string $translations Translated text.
* @param string $text Text to translate.
* @param string $context Context information for the translators.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @return string $translations Translated text.
*/
public function disable_lato( $translations, $text, $context, $domain ) {
if ( 'Lato font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}
return $translations;
}
/**
* Force 'off' as a result of Source Sans Pro font toggler string translation.
*
* @since 1.0
* @access public
*
* @param string $translations Translated text.
* @param string $text Text to translate.
* @param string $context Context information for the translators.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @return string $translations Translated text.
*/
public function disable_source_sans_pro( $translations, $text, $context, $domain ) {
if ( 'Source Sans Pro font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}
return $translations;
}
/**
* Force 'off' as a result of Bitter font toggler string translation.
*
* @since 1.0
* @access public
*
* @param string $translations Translated text.
* @param string $text Text to translate.
* @param string $context Context information for the translators.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @return string $translations Translated text.
*/
public function disable_bitter( $translations, $text, $context, $domain ) {
if ( 'Bitter font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}
return $translations;
}
/**
* Register filters that disable fonts for bundled themes.
*
* This filters can be directly hooked as Disable_Google_Fonts::disable_open_sans()
* but that would mean that comparison is done on each string
* for each font which creates performance issues.
*
* Instead we check active template's name very late and just once
* and hook appropriate filters.
*
* Note that Open Sans disabler is used for both WordPress core
* and for Twenty Twelve theme.
*
* @since 1.0
* @access public
*
* @uses get_template() To get name of the active parent theme.
* @uses add_filter() To hook theme specific fonts disablers.
*/
public function register_theme_fonts_disabler() {
$template = get_template();
switch ( $template ) {
case 'twentyfourteen' :
add_filter( 'gettext_with_context', array( $this, 'disable_lato' ), 888, 4 );
break;
case 'twentythirteen' :
add_filter( 'gettext_with_context', array( $this, 'disable_source_sans_pro' ), 888, 4 );
add_filter( 'gettext_with_context', array( $this, 'disable_bitter' ), 888, 4 );
break;
}
}
}
/* Although it would be preferred to do this on hook,
* load early to make sure Open Sans is removed
*/
$disable_google_fonts = new Disable_Google_Fonts;