Disable Google Fonts - Version 1.0

Version Description

Download this release

Release Info

Developer dimadin
Plugin Icon wp plugin Disable Google Fonts
Version 1.0
Comparing to
See all releases

Version 1.0

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