Disable and Remove Google Fonts - Version 1.4.8

Version Description

Download this release

Release Info

Developer DannyCooper
Plugin Icon wp plugin Disable and Remove Google Fonts
Version 1.4.8
Comparing to
See all releases

Code changes from version 1.4.7 to 1.4.8

admin/class-drgf-admin.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * DRGF Admin Page.
4
+ *
5
+ * @package disable-remove-google-fonts
6
+ */
7
+
8
+ /**
9
+ * Create the admin pages.
10
+ */
11
+ class DRGF_Admin {
12
+
13
+ /**
14
+ * Start up
15
+ */
16
+ public function __construct() {
17
+ register_activation_hook( DRGF_PLUGIN_FILE, array( $this, 'activate' ) );
18
+
19
+ add_action( 'admin_menu', array( $this, 'add_submenu' ), 10 );
20
+ add_action( 'admin_init', array( $this, 'admin_redirect' ) );
21
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
22
+ add_action( 'wp_ajax_ogf_dismiss_guide', array( $this, 'dismiss_guide' ) );
23
+ }
24
+
25
+ function activate() {
26
+ add_option( 'drgf_do_activation_redirect', true );
27
+ }
28
+
29
+ /**
30
+ * Redirect to the Google Fonts Welcome page.
31
+ */
32
+ function admin_redirect() {
33
+ if ( get_option( 'drgf_do_activation_redirect', false ) ) {
34
+ delete_option( 'drgf_do_activation_redirect' );
35
+ if ( ! isset( $_GET['activate-multi'] ) && ! is_network_admin() ) {
36
+ wp_redirect( admin_url('themes.php?page=drgf') );
37
+ exit;
38
+ }
39
+ }
40
+ }
41
+
42
+
43
+ /**
44
+ * Add options page
45
+ */
46
+ public function add_submenu() {
47
+ add_submenu_page(
48
+ 'themes.php',
49
+ __( 'Google Fonts', 'disable-remove-google-fonts' ),
50
+ __( 'Google Fonts', 'disable-remove-google-fonts' ),
51
+ 'manage_options',
52
+ 'drgf',
53
+ array( $this, 'render_welcome_page' ),
54
+ 50
55
+ );
56
+ }
57
+
58
+ /**
59
+ * Add options page
60
+ */
61
+ public function enqueue() {
62
+ wp_enqueue_style( 'drgf-admin', esc_url( DRGF_DIR_URL . 'admin/style.css' ), false, DRGF_VERSION );
63
+ wp_enqueue_script( 'drgf-admin', esc_url( DRGF_DIR_URL . 'admin/scripts.js' ), 'jquery', DRGF_VERSION, false );
64
+ }
65
+
66
+ /**
67
+ * Options page callback
68
+ */
69
+ public function render_welcome_page() {
70
+ $site_url = site_url( '', 'https' );
71
+ $url = preg_replace( '(^https?://)', '', $site_url );
72
+ ?>
73
+ <style>
74
+ .notice {
75
+ display: none;
76
+ }
77
+ </style>
78
+ <div class="drgf-admin__wrap">
79
+ <div class="drgf-admin__content">
80
+ <div class="drgf-admin__content__header">
81
+ <h1>Your Quickstart Guide</h1>
82
+ </div>
83
+ <div class="drgf-admin__content__inner">
84
+ <p>Thank you for installing the <em>Remove Google Fonts</em> plugin!</p>
85
+ <p><strong>Now the plugin is active, it will begin working right away.</strong></p>
86
+ <p>To confirm it's working as expected, you can test your website here: <a target="_blank" href="https://fontsplugin.com/google-fonts-checker/">Google Fonts Checker</a>.</p>
87
+ <p>If there are any font requests still present, please <a href="https://wordpress.org/support/plugin/disable-remove-google-fonts/#new-post">create a support ticket</a> and our team will happily look into it for you</a>.</p>
88
+ <h3>How This Plugin Works</h3>
89
+ <p>This plugin completely removes all references to Google Fonts from your website. That means that your website will no longer render Google Fonts and will instead revert to a <a target="_blank" href="https://fontsplugin.com/web-safe-system-fonts/">fallback font</a>.</p>
90
+ <p>However, some services load Google Fonts within an embedded iFrame. These include YouTube, Google Maps and ReCaptcha. It's not possible for this plugin to remove those services for the reasons <a target="_blank" href="https://fontsplugin.com/remove-disable-google-fonts/#youtube">outlined here</a>.</p>
91
+ <?php if ( function_exists( 'ogf_initiate' ) ) : ?>
92
+ <h3>⭐️ Fonts Plugin Pro</h3>
93
+ <p>Instead of removing the fonts completely, <a target="_blank" href="https://fontsplugin.com/drgf-upgrade">Fonts Plugin Pro</a> enables you to host the fonts from your <strong>own domain</strong> (<?php echo $url; ?>) with the click of a button. Locally hosted fonts are more efficient, quicker to load and don't connect to any third-parties (GDPR & DSGVO-friendly).</p>
94
+ <a class="drgf-admin__button button" href="https://fontsplugin.com/drgf-upgrade" target="_blank">Learn More</a>
95
+ <?php else : ?>
96
+ <h3>⭐️ Host Google Fonts Locally</h3>
97
+ <p>Instead of removing the fonts completely, our <a href="https://fontsplugin.com/drgf-upgrade" target="_blank">Pro upgrade</a> enables you to host the fonts from your <strong>own domain</strong> (<?php echo $url; ?>) with the click of a button. Locally hosted fonts are more efficient, quicker to load and don't connect to any third-parties (GDPR & DSGVO-friendly).</p>
98
+ <a class="drgf-admin__button button" href="https://fontsplugin.com/drgf-upgrade" target="_blank">Get Started</a>
99
+ <?php endif; ?>
100
+ </div>
101
+ </div>
102
+ </div>
103
+ <?php
104
+ }
105
+
106
+ /**
107
+ * AJAX handler to store the state of dismissible notices.
108
+ */
109
+ public function dismiss_guide() {
110
+ // Store it in the options table.
111
+ update_option( 'drgf_dismiss_guide', true );
112
+ }
113
+ }
114
+
115
+ if ( is_admin() ) {
116
+ $drgf_admin = new DRGF_Admin();
117
+ }
admin/class-drgf-notice.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Welcome Notice Class.
4
+ *
5
+ * @package disable-remove-google-fonts
6
+ * @copyright Copyright (c) 2020, Fonts Plugin
7
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
8
+ */
9
+
10
+ if ( ! class_exists( 'DRGF_Notice' ) ) :
11
+ /**
12
+ * The welcome.
13
+ */
14
+ class DRGF_Notice {
15
+
16
+ /**
17
+ * Slug.
18
+ *
19
+ * @var string $slug
20
+ */
21
+ private $slug;
22
+
23
+ /**
24
+ * Message.
25
+ *
26
+ * @var string $message
27
+ */
28
+ private $message;
29
+
30
+ /**
31
+ * Type.
32
+ *
33
+ * @var string $type
34
+ */
35
+ private $type;
36
+
37
+ /**
38
+ * Class constructor.
39
+ *
40
+ * @param string $slug Slug.
41
+ * @param string $message Message.
42
+ * @param string $type Type.
43
+ */
44
+ public function __construct( $slug, $message, $type = 'success' ) {
45
+ $this->slug = $slug;
46
+ $this->message = $message;
47
+ $this->type = $type;
48
+
49
+ // Add actions.
50
+ add_action( 'admin_notices', array( $this, 'display_admin_notice' ) );
51
+ add_action( 'wp_ajax_drgf_dismiss_notice', array( $this, 'dismiss_notice' ) );
52
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
53
+ }
54
+
55
+ /**
56
+ * Enqeue the styles and scripts.
57
+ */
58
+ public function enqueue() {
59
+ wp_enqueue_script( 'drgf-scripts', esc_url( DRGF_DIR_URL . 'admin/scripts.js' ), array( 'jquery' ), DRGF_VERSION, false );
60
+ }
61
+
62
+ /**
63
+ * AJAX handler to store the state of dismissible notices.
64
+ */
65
+ public function dismiss_notice() {
66
+ if ( isset( $_POST['type'] ) ) {
67
+ // Pick up the notice "type" - passed via jQuery (the "data-notice" attribute on the notice).
68
+ $type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
69
+ // Store it in the options table.
70
+ update_option( 'dismissed-' . $type, true );
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Display the admin notice.
76
+ */
77
+ public function display_admin_notice() {
78
+ if ( get_option( 'dismissed-' . $this->slug, false ) ) {
79
+ return;
80
+ }
81
+ ?>
82
+
83
+ <div class="notice notice-<?php echo esc_attr( $this->type ); ?> is-dismissible notice-dismiss-drgf" data-notice="<?php echo esc_attr( $this->slug ); ?>">
84
+ <p>
85
+ <?php
86
+ echo $this->message; // WPCS: XSS ok.
87
+ ?>
88
+ </p>
89
+ </div>
90
+ <?php
91
+ }
92
+ }
93
+ endif;
94
+
95
+ $message = sprintf(
96
+ // translators: %s Link to DRGF welcome page.
97
+ __( 'Thank you for installing <strong>Disable & Remove Google Fonts</strong>! <a href="%s">Finish the setup process.</a>.', 'olympus-google-fonts' ),
98
+ esc_url( admin_url( '/themes.php?page=drgf' ) )
99
+ );
100
+
101
+ /*
102
+ * Instantiate the DRGF_Notice class.
103
+ */
104
+ new DRGF_Notice( 'drgf-welcome', $message, 'success' );
admin/scripts.js ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* global ajaxurl */
2
+ jQuery( document ).ready( function() {
3
+
4
+ // Hook into the "notice-dismiss-welcome" class we added to the notice, so
5
+ // Only listen to YOUR notices being dismissed
6
+ jQuery( document ).on(
7
+ 'click',
8
+ '.notice-dismiss-drgf .notice-dismiss',
9
+ function() {
10
+ // Read the "data-notice" information to track which notice
11
+ // is being dismissed and send it via AJAX
12
+ const type = jQuery( this ).closest( '.notice-dismiss-drgf' ).data( 'notice' );
13
+ // Make an AJAX call
14
+ // Since WP 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
15
+ jQuery.ajax(
16
+ ajaxurl,
17
+ {
18
+ type: 'POST',
19
+ data: {
20
+ action: 'drgf_dismiss_notice',
21
+ type: type,
22
+ },
23
+ }
24
+ );
25
+ }
26
+ );
27
+ } );
admin/style.css ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .drgf-admin__wrap {
2
+ margin: 50px 35px;
3
+ max-width: 960px;
4
+ }
5
+
6
+ .drgf-admin__wrap p {
7
+ font-size: 16px;
8
+ margin-top: 0;
9
+ font-family: 'Source Sans Pro', 'Helvetica Neue', sans-serif;
10
+ }
11
+
12
+ .drgf-admin__wrap p {
13
+ line-height: 1.6;
14
+ }
15
+
16
+ .drgf-admin__wrap h3 {
17
+ font-size: 1.1rem !important;
18
+ margin: 1.5em 0 1em;
19
+ font-weight: bold;
20
+ }
21
+
22
+ .drgf-admin__wrap ul {
23
+ list-style: disc;
24
+ margin-left: 32px
25
+ }
26
+
27
+ .drgf-admin__wrap ul li {
28
+ margin-bottom: 8px
29
+ }
30
+
31
+ .drgf-admin__content {
32
+ background: #fff;
33
+ border-radius: 3px;
34
+ box-sizing: border-box;
35
+ margin: 0 auto;
36
+ max-width: 740px;
37
+ box-shadow: 0 5px 20px rgba(0, 0, 0, 0.07);
38
+ }
39
+
40
+ .drgf-admin__content__header {
41
+ border-top: 5px solid #b43534;
42
+ border-radius: 5px 5px 0 0;
43
+ }
44
+
45
+ .drgf-admin__content__header h1 {
46
+ font-size: 24px;
47
+ padding: 50px 50px 0;
48
+ margin: 0
49
+ }
50
+
51
+ .drgf-admin__content__inner {
52
+ background-color: #fff;
53
+ padding: 25px 50px 50px;
54
+ }
55
+
56
+ .drgf-admin__sidebar__inner {
57
+ background-color: white;
58
+ }
59
+
60
+ .drgf-admin__sidebar__header {
61
+ background-color: #0d72a7
62
+ }
63
+
64
+ .drgf-admin__sidebar__plugin {
65
+ padding: 30px;
66
+ }
67
+
68
+ .drgf-admin__sidebar__header h2 {
69
+ color: #fff;
70
+ font-size: 16px;
71
+ padding: 20px 30px;
72
+ margin: 0
73
+ }
74
+
75
+ .drgf-admin__button.button {
76
+ color: #fff;
77
+ border-color: #a10000;
78
+ background: #a10000;
79
+ padding: 4px 16px;
80
+ font-size: 16px;
81
+ font-weight: 600;
82
+ height: auto
83
+ }
84
+ .drgf-admin__button.button:hover {
85
+ color: #fff;
86
+ border-color: #a10000;
87
+ background: #a10000;
88
+ padding: 4px 16px;
89
+
90
+ }
91
+
92
+ @media only screen and (max-width: 960px) {
93
+
94
+ .drgf-admin__content {
95
+ max-width: 98%;
96
+ float: none;
97
+ }
98
+
99
+ .drgf-admin__wrap {
100
+ margin: 1%;
101
+ }
102
+
103
+ }
104
+ @media only screen and (max-width: 480px) {
105
+
106
+ .drgf-admin__wrap .button {
107
+ width: 100%;
108
+ margin-left: 0;
109
+ }
110
+
111
+ }
changelog.txt CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  = 1.4.7 =
2
 
3
  * Add compatibility for Kadence theme.
1
+ = 1.4.8 =
2
+
3
+ * Add welcome page and test instructions.
4
+
5
  = 1.4.7 =
6
 
7
  * Add compatibility for Kadence theme.
disable-remove-google-fonts.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Optimize frontend performance by disabling Google Fonts. GDPR-friendly.
6
  * Author: Fonts Plugin
7
  * Author URI: https://fontsplugin.com
8
- * Version: 1.4.7
9
  * License: GPLv2 or later
10
  * License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
11
  *
@@ -17,216 +17,34 @@ if ( ! defined( 'ABSPATH' ) ) {
17
  exit;
18
  }
19
 
20
- /**
21
- * Dequeue Google Fonts based on URL.
22
- */
23
- function drgf_dequeueu_fonts() {
24
-
25
- // Remove fonts added by the Divi Extra theme
26
- remove_action( 'wp_footer', 'et_builder_print_font' );
27
-
28
- // Dequeue Google Fonts loaded by Revolution Slider.
29
- remove_action( 'wp_footer', array( 'RevSliderFront', 'load_google_fonts' ) );
30
-
31
- // Dequeue the Jupiter theme font loader.
32
- wp_dequeue_script( 'mk-webfontloader' );
33
-
34
- // Remove the aThemes resource hints.
35
- remove_action( 'wp_head', 'sydney_preconnect_google_fonts' );
36
- remove_action( 'wp_head', 'botiga_preconnect_google_fonts' );
37
-
38
- global $wp_styles;
39
-
40
- if ( ! ( $wp_styles instanceof WP_Styles ) ) {
41
- return;
42
- }
43
-
44
- $allowed = apply_filters(
45
- 'drgf_exceptions',
46
- [ 'olympus-google-fonts' ]
47
- );
48
-
49
- foreach ( $wp_styles->registered as $style ) {
50
- $handle = $style->handle;
51
- $src = $style->src;
52
-
53
- if ( strpos( $src, 'fonts.googleapis' ) !== false ) {
54
- if ( ! array_key_exists( $handle, array_flip( $allowed ) ) ) {
55
- wp_dequeue_style( $handle );
56
- }
57
- }
58
- }
59
-
60
- /**
61
- * Some themes set the Google Fonts URL as a dependency, so we need to replace
62
- * it with a blank value rather than removing it entirely. As that would
63
- * remove the stylesheet too.
64
- */
65
- foreach ( $wp_styles->registered as $style ) {
66
- foreach( $style->deps as $dep ) {
67
- if ( ( strpos( $dep, 'google-fonts' ) !== false ) || ( strpos( $dep, 'google_fonts' ) !== false ) || ( strpos( $dep, 'googlefonts' ) !== false ) ) {
68
- $wp_styles->remove( $dep );
69
- $wp_styles->add( $dep, '' );
70
- }
71
- }
72
- }
73
- remove_action( 'wp_head', 'hu_print_gfont_head_link', 2 );
74
-
75
- remove_action('wp_head', 'appointment_load_google_font');
76
-
77
-
78
- }
79
-
80
- add_action( 'wp_enqueue_scripts', 'drgf_dequeueu_fonts', PHP_INT_MAX );
81
- add_action( 'wp_print_styles', 'drgf_dequeueu_fonts', PHP_INT_MAX );
82
-
83
- /**
84
- * Dequeue Google Fonts loaded by Elementor.
85
- */
86
- add_filter( 'elementor/frontend/print_google_fonts', '__return_false' );
87
-
88
- /**
89
- * Dequeue Google Fonts loaded by Beaver Builder.
90
- */
91
- add_filter(
92
- 'fl_builder_google_fonts_pre_enqueue',
93
- function( $fonts ) {
94
- return array();
95
- }
96
- );
97
-
98
- /**
99
- * Dequeue Google Fonts loaded by JupiterX theme.
100
- */
101
- add_filter(
102
- 'jupiterx_register_fonts',
103
- function( $fonts ) {
104
- return array();
105
- },
106
- 99999
107
- );
108
-
109
- /**
110
- * Dequeue Google Fonts loaded by the Hustle plugin.
111
- */
112
- add_filter( 'hustle_load_google_fonts', '__return_false' );
113
 
114
  /**
115
- * Dequeue Google Fonts loaded by the Vantage theme.
116
  */
117
- add_filter( 'vantage_import_google_fonts', '__return_false' );
118
-
119
-
120
- /**
121
- * Dequeue Google Fonts loaded by the Hustle plugin.
122
- */
123
- add_filter( 'mailpoet_display_custom_fonts', '__return_false' );
124
-
125
- if ( ! function_exists( 'apollo13framework_get_web_fonts_dynamic' ) ) {
126
- /**
127
- * Dequeue Google Fonts loaded by the Apollo13 Themes Framework.
128
- */
129
- function apollo13framework_get_web_fonts_dynamic() {
130
- return;
131
- }
132
  }
133
 
134
- if ( ! function_exists( 'apollo13framework_get_web_fonts_static' ) ) {
135
- /**
136
- * Dequeue Google Fonts loaded by the Apollo13 Themes Framework.
137
- */
138
- function apollo13framework_get_web_fonts_static() {
139
- return;
140
- }
141
  }
142
 
143
- if ( ! function_exists( 'hemingway_get_google_fonts_url' ) ) {
144
- /**
145
- * Dequeue Google Fonts loaded by the Hemingway theme.
146
- */
147
- function hemingway_get_google_fonts_url() {
148
- return false;
149
- }
150
  }
151
 
152
- /**
153
- * Dequeue Google Fonts loaded by the Avia framework (Enfold theme).
154
- */
155
- add_action( 'init', 'drgf_enfold_customization_switch_fonts' );
156
- function drgf_enfold_customization_switch_fonts() {
157
- if ( class_exists( 'avia_style_generator' ) ) {
158
- global $avia;
159
- $avia->style->print_extra_output = false;
160
- }
161
  }
162
 
163
- /**
164
- * Remove the preconnect hint to fonts.gstatic.com.
165
- */
166
- add_action( 'init', 'drgf_remove_divi_preconnect' );
167
- function drgf_remove_divi_preconnect() {
168
- remove_action( 'wp_enqueue_scripts', 'et_builder_preconnect_google_fonts', 9 );
169
  }
170
 
171
- /**
172
- * Dequeue Google Fonts loaded by Avada theme.
173
- */
174
- $fusion_options = get_option( 'fusion_options', false );
175
- if (
176
- $fusion_options
177
- && isset( $fusion_options['gfonts_load_method'] )
178
- && $fusion_options['gfonts_load_method'] === 'cdn'
179
- ) {
180
- add_filter(
181
- 'fusion_google_fonts',
182
- function( $fonts ) {
183
- return array();
184
- },
185
- 99999
186
- );
187
- }
188
 
189
- /**
190
- * Avada caches the CSS output so we need to clear the
191
- * cache once the fonts have been removed.
192
- */
193
- function dgrf_flush_avada_cache() {
194
- if ( function_exists( 'fusion_reset_all_caches' ) ) {
195
- fusion_reset_all_caches();
196
- }
197
  }
198
- register_activation_hook( __FILE__, 'dgrf_flush_avada_cache' );
199
-
200
- /**
201
- * WPBakery enqueues fonts correctly using wp_enqueue_style
202
- * but does it late so this is required.
203
- */
204
- function dgrf_dequeue_wpbakery_fonts() {
205
- global $wp_styles;
206
-
207
- if ( ! ( $wp_styles instanceof WP_Styles ) ) {
208
- return;
209
- }
210
-
211
- $allowed = apply_filters(
212
- 'drgf_exceptions',
213
- [ 'olympus-google-fonts' ]
214
- );
215
-
216
- foreach ( $wp_styles->registered as $style ) {
217
- $handle = $style->handle;
218
- $src = $style->src;
219
-
220
- if ( strpos( $src, 'fonts.googleapis' ) !== false ) {
221
- if ( ! array_key_exists( $handle, array_flip( $allowed ) ) ) {
222
- wp_dequeue_style( $handle );
223
- }
224
- }
225
- }
226
- }
227
- add_action( 'wp_footer', 'dgrf_dequeue_wpbakery_fonts' );
228
-
229
- /**
230
- * Dequeue Google Fonts loaded by Kadence theme.
231
- */
232
- add_filter( 'kadence_theme_google_fonts_array', '__return_empty_array' );
5
  * Description: Optimize frontend performance by disabling Google Fonts. GDPR-friendly.
6
  * Author: Fonts Plugin
7
  * Author URI: https://fontsplugin.com
8
+ * Version: 1.4.8
9
  * License: GPLv2 or later
10
  * License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
11
  *
17
  exit;
18
  }
19
 
20
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  /**
23
+ * Exit early if Fonts Plugin Pro is active.
24
  */
25
+ if ( is_plugin_active( 'fonts-plugin-pro/fonts-plugin-pro.php' ) ) {
26
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  }
28
 
29
+ if ( ! defined( 'DRGF_PLUGIN_FILE' ) ) {
30
+ define( 'DRGF_PLUGIN_FILE', __FILE__ );
 
 
 
 
 
31
  }
32
 
33
+ if ( ! defined( 'DRGF_VERSION' ) ) {
34
+ define( 'DRGF_VERSION', '1.4.8' );
 
 
 
 
 
35
  }
36
 
37
+ if ( ! defined( 'DRGF_DIR_PATH' ) ) {
38
+ define( 'DRGF_DIR_PATH', plugin_dir_path( __FILE__ ) );
 
 
 
 
 
 
 
39
  }
40
 
41
+ if ( ! defined( 'DRGF_DIR_URL' ) ) {
42
+ define( 'DRGF_DIR_URL', plugin_dir_url( __FILE__ ) );
 
 
 
 
43
  }
44
 
45
+ require DRGF_DIR_PATH . 'inc/remove-google-fonts.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
+ if ( is_admin() ) {
48
+ require DRGF_DIR_PATH . 'admin/class-drgf-admin.php';
49
+ require DRGF_DIR_PATH . 'admin/class-drgf-notice.php';
 
 
 
 
 
50
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/remove-google-fonts.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Remove DNS prefetch, preconnect and preload headers.
4
+ */
5
+ function drgf_remove_prefetch( $urls, $relation_type ) {
6
+ if ( 'dns-prefetch' === $relation_type ) {
7
+ $urls = array_diff( $urls, array( 'fonts.googleapis.com' ) );
8
+ } elseif ( 'preconnect' === $relation_type || 'preload' === $relation_type ) {
9
+ foreach ( $urls as $key => $url ) {
10
+ if ( ! isset( $url['href'] ) ) {
11
+ continue;
12
+ }
13
+ if ( preg_match( '/\/\/fonts\.(gstatic|googleapis)\.com/', $url['href'] ) ) {
14
+ unset( $urls[ $key ] );
15
+ }
16
+ }
17
+ }
18
+
19
+ return $urls;
20
+ }
21
+ add_filter( 'wp_resource_hints', 'drgf_remove_prefetch', PHP_INT_MAX, 2 );
22
+
23
+ // Remove the aThemes resource hints.
24
+ remove_action( 'wp_head', 'sydney_preconnect_google_fonts' );
25
+ remove_action( 'wp_head', 'botiga_preconnect_google_fonts' );
26
+
27
+ /**
28
+ * Dequeue Google Fonts based on URL.
29
+ */
30
+ function drgf_dequeueu_fonts() {
31
+
32
+ // Remove fonts added by the Divi Extra theme
33
+ remove_action( 'wp_footer', 'et_builder_print_font' );
34
+
35
+ // Dequeue Google Fonts loaded by Revolution Slider.
36
+ remove_action( 'wp_footer', array( 'RevSliderFront', 'load_google_fonts' ) );
37
+
38
+ // Dequeue the Jupiter theme font loader.
39
+ wp_dequeue_script( 'mk-webfontloader' );
40
+
41
+
42
+ global $wp_styles;
43
+
44
+ if ( ! ( $wp_styles instanceof WP_Styles ) ) {
45
+ return;
46
+ }
47
+
48
+ $allowed = apply_filters(
49
+ 'drgf_exceptions',
50
+ [ 'olympus-google-fonts' ]
51
+ );
52
+
53
+ foreach ( $wp_styles->registered as $style ) {
54
+ $handle = $style->handle;
55
+ $src = $style->src;
56
+
57
+ if ( strpos( $src, 'fonts.googleapis' ) !== false ) {
58
+ if ( ! array_key_exists( $handle, array_flip( $allowed ) ) ) {
59
+ wp_dequeue_style( $handle );
60
+ }
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Some themes set the Google Fonts URL as a dependency, so we need to replace
66
+ * it with a blank value rather than removing it entirely. As that would
67
+ * remove the stylesheet too.
68
+ */
69
+ foreach ( $wp_styles->registered as $style ) {
70
+ foreach( $style->deps as $dep ) {
71
+ if ( ( strpos( $dep, 'google-fonts' ) !== false ) || ( strpos( $dep, 'google_fonts' ) !== false ) || ( strpos( $dep, 'googlefonts' ) !== false ) ) {
72
+ $wp_styles->remove( $dep );
73
+ $wp_styles->add( $dep, '' );
74
+ }
75
+ }
76
+ }
77
+ remove_action( 'wp_head', 'hu_print_gfont_head_link', 2 );
78
+
79
+ remove_action('wp_head', 'appointment_load_google_font');
80
+
81
+
82
+ }
83
+
84
+ add_action( 'wp_enqueue_scripts', 'drgf_dequeueu_fonts', PHP_INT_MAX );
85
+ add_action( 'wp_print_styles', 'drgf_dequeueu_fonts', PHP_INT_MAX );
86
+
87
+ /**
88
+ * Dequeue Google Fonts loaded by Elementor.
89
+ */
90
+ add_filter( 'elementor/frontend/print_google_fonts', '__return_false' );
91
+
92
+ /**
93
+ * Dequeue Google Fonts loaded by Beaver Builder.
94
+ */
95
+ add_filter(
96
+ 'fl_builder_google_fonts_pre_enqueue',
97
+ function( $fonts ) {
98
+ return array();
99
+ }
100
+ );
101
+
102
+ /**
103
+ * Dequeue Google Fonts loaded by JupiterX theme.
104
+ */
105
+ add_filter(
106
+ 'jupiterx_register_fonts',
107
+ function( $fonts ) {
108
+ return array();
109
+ },
110
+ 99999
111
+ );
112
+
113
+ /**
114
+ * Dequeue Google Fonts loaded by the Hustle plugin.
115
+ */
116
+ add_filter( 'hustle_load_google_fonts', '__return_false' );
117
+
118
+ /**
119
+ * Dequeue Google Fonts loaded by the Vantage theme.
120
+ */
121
+ add_filter( 'vantage_import_google_fonts', '__return_false' );
122
+
123
+
124
+ /**
125
+ * Dequeue Google Fonts loaded by the Hustle plugin.
126
+ */
127
+ add_filter( 'mailpoet_display_custom_fonts', '__return_false' );
128
+
129
+ if ( ! function_exists( 'apollo13framework_get_web_fonts_dynamic' ) ) {
130
+ /**
131
+ * Dequeue Google Fonts loaded by the Apollo13 Themes Framework.
132
+ */
133
+ function apollo13framework_get_web_fonts_dynamic() {
134
+ return;
135
+ }
136
+ }
137
+
138
+ if ( ! function_exists( 'apollo13framework_get_web_fonts_static' ) ) {
139
+ /**
140
+ * Dequeue Google Fonts loaded by the Apollo13 Themes Framework.
141
+ */
142
+ function apollo13framework_get_web_fonts_static() {
143
+ return;
144
+ }
145
+ }
146
+
147
+ if ( ! function_exists( 'hemingway_get_google_fonts_url' ) ) {
148
+ /**
149
+ * Dequeue Google Fonts loaded by the Hemingway theme.
150
+ */
151
+ function hemingway_get_google_fonts_url() {
152
+ return false;
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Dequeue Google Fonts loaded by the Avia framework (Enfold theme).
158
+ */
159
+ add_action( 'init', 'drgf_enfold_customization_switch_fonts' );
160
+ function drgf_enfold_customization_switch_fonts() {
161
+ if ( class_exists( 'avia_style_generator' ) ) {
162
+ global $avia;
163
+ $avia->style->print_extra_output = false;
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Remove the preconnect hint to fonts.gstatic.com.
169
+ */
170
+ add_action( 'init', 'drgf_remove_divi_preconnect' );
171
+ function drgf_remove_divi_preconnect() {
172
+ remove_action( 'wp_enqueue_scripts', 'et_builder_preconnect_google_fonts', 9 );
173
+ }
174
+
175
+ /**
176
+ * Dequeue Google Fonts loaded by Avada theme.
177
+ */
178
+ $fusion_options = get_option( 'fusion_options', false );
179
+ if (
180
+ $fusion_options
181
+ && isset( $fusion_options['gfonts_load_method'] )
182
+ && $fusion_options['gfonts_load_method'] === 'cdn'
183
+ ) {
184
+ add_filter(
185
+ 'fusion_google_fonts',
186
+ function( $fonts ) {
187
+ return array();
188
+ },
189
+ 99999
190
+ );
191
+ }
192
+
193
+ /**
194
+ * Avada caches the CSS output so we need to clear the
195
+ * cache once the fonts have been removed.
196
+ */
197
+ function drgf_flush_avada_cache() {
198
+ if ( function_exists( 'fusion_reset_all_caches' ) ) {
199
+ fusion_reset_all_caches();
200
+ }
201
+ }
202
+ register_activation_hook( __FILE__, 'drgf_flush_avada_cache' );
203
+
204
+ /**
205
+ * WPBakery enqueues fonts correctly using wp_enqueue_style
206
+ * but does it late so this is required.
207
+ */
208
+ function drgf_dequeue_wpbakery_fonts() {
209
+ global $wp_styles;
210
+
211
+ if ( ! ( $wp_styles instanceof WP_Styles ) ) {
212
+ return;
213
+ }
214
+
215
+ $allowed = apply_filters(
216
+ 'drgf_exceptions',
217
+ [ 'olympus-google-fonts' ]
218
+ );
219
+
220
+ foreach ( $wp_styles->registered as $style ) {
221
+ $handle = $style->handle;
222
+ $src = $style->src;
223
+
224
+ if ( strpos( $src, 'fonts.googleapis' ) !== false ) {
225
+ if ( ! array_key_exists( $handle, array_flip( $allowed ) ) ) {
226
+ wp_dequeue_style( $handle );
227
+ }
228
+ }
229
+ }
230
+ }
231
+ add_action( 'wp_footer', 'drgf_dequeue_wpbakery_fonts' );
232
+
233
+ /**
234
+ * Dequeue Google Fonts loaded by Kadence theme.
235
+ */
236
+ add_filter( 'kadence_theme_google_fonts_array', '__return_empty_array' );
237
+ add_filter( 'kadence_print_google_fonts', '__return_false' );
readme.txt CHANGED
@@ -13,6 +13,8 @@ Improve frontend performance by disabling [Google Fonts](https://wordpress.org/p
13
 
14
  While this plugin removes Google Fonts from as many themes and plugins as possible, some require additional steps, we have detailed those here: [Remove Google Fonts from WordPress](https://fontsplugin.com/remove-disable-google-fonts/)
15
 
 
 
16
  = Plugin Compatibility =
17
 
18
  This plugin will work with all WordPress themes and has been specifically tested with the following:
13
 
14
  While this plugin removes Google Fonts from as many themes and plugins as possible, some require additional steps, we have detailed those here: [Remove Google Fonts from WordPress](https://fontsplugin.com/remove-disable-google-fonts/)
15
 
16
+ After installing this plugin, clear your website cache and test your site using the free [Google Fonts Checker](https://fontsplugin.com/google-fonts-checker).
17
+
18
  = Plugin Compatibility =
19
 
20
  This plugin will work with all WordPress themes and has been specifically tested with the following: