OMGF | GDPR/DSVGO Compliant, Faster Google Fonts. Easy. - Version 2.2.2

Version Description

Added long overdue migration script for options and tables. Code optimizations.

Download this release

Release Info

Developer DaanvandenBergh
Plugin Icon 128x128 OMGF | GDPR/DSVGO Compliant, Faster Google Fonts. Easy.
Version 2.2.2
Comparing to
See all releases

Code changes from version 2.2.1 to 2.2.2

host-webfonts-local.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: OMGF
5
  * Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
6
  * Description: Minimize DNS requests and leverage browser cache by easily saving Google Fonts to your server and removing the external Google Fonts.
7
- * Version: 2.2.1
8
  * Author: Daan van den Bergh
9
  * Author URI: https://daan.dev
10
  * License: GPL2v2 or later
@@ -19,7 +19,7 @@ defined('ABSPATH') || exit;
19
  */
20
  define('OMGF_PLUGIN_DIR', plugin_dir_path(__FILE__));
21
  define('OMGF_PLUGIN_FILE', __FILE__);
22
- define('OMGF_DB_VERSION', '1.8.3');
23
  define('OMGF_STATIC_VERSION', '2.1.4');
24
  define('OMGF_WEB_FONT_LOADER_VERSION', '1.6.26');
25
 
4
  * Plugin Name: OMGF
5
  * Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
6
  * Description: Minimize DNS requests and leverage browser cache by easily saving Google Fonts to your server and removing the external Google Fonts.
7
+ * Version: 2.2.2
8
  * Author: Daan van den Bergh
9
  * Author URI: https://daan.dev
10
  * License: GPL2v2 or later
19
  */
20
  define('OMGF_PLUGIN_DIR', plugin_dir_path(__FILE__));
21
  define('OMGF_PLUGIN_FILE', __FILE__);
22
+ define('OMGF_DB_VERSION', '2.2.2');
23
  define('OMGF_STATIC_VERSION', '2.1.4');
24
  define('OMGF_WEB_FONT_LOADER_VERSION', '1.6.26');
25
 
includes/admin/class-settings.php CHANGED
@@ -27,14 +27,14 @@ class OMGF_Admin_Settings extends OMGF_Admin
27
  );
28
  const OMGF_SETTING_AUTO_DETECTION_ENABLED = 'omgf_auto_detection_enabled';
29
  const OMGF_SETTING_DETECTED_FONTS = 'omgf_detected_fonts';
30
- const OMGF_SETTING_CACHE_DIR = 'caos_webfonts_cache_dir';
31
- const OMGF_SETTING_CDN_URL = 'caos_webfonts_cdn_url';
32
  const OMGF_SETTING_WEB_FONT_LOADER = 'omgf_web_font_loader';
33
- const OMGF_SETTING_REMOVE_VERSION = 'caos_webfonts_remove_version';
34
- const OMGF_SETTING_DISPLAY_OPTION = 'caos_webfonts_display_option';
35
- const OMGF_SETTING_REMOVE_GOOGLE_FONTS = 'caos_webfonts_remove_gfonts';
36
- const OMGF_SETTING_ENABLE_PRELOAD = 'caos_webfonts_preload';
37
- const OMGF_SETTING_DB_VERSION = 'caos_webfonts_db_version';
38
  const OMGF_SETTING_UNINSTALL = 'omgf_uninstall';
39
 
40
  /**
@@ -97,12 +97,12 @@ class OMGF_Admin_Settings extends OMGF_Admin
97
 
98
  <form id="hwl-settings-form" class="settings-column right" name="hwl-settings-form" method="post" action="options.php">
99
  <?php
100
- settings_fields('caos-webfonts-basic-settings');
101
- do_settings_sections('caos-webfonts-basic-settings');
102
 
103
  $this->get_template('basic-settings');
104
 
105
- do_action('hwl_after_settings_form_settings');
106
 
107
  submit_button();
108
  ?>
@@ -112,50 +112,19 @@ class OMGF_Admin_Settings extends OMGF_Admin
112
  }
113
 
114
  /**
115
- * Register our settings.
 
 
116
  */
117
  public function register_settings()
118
  {
119
- register_setting(
120
- 'caos-webfonts-basic-settings',
121
- self::OMGF_SETTING_AUTO_DETECTION_ENABLED
122
- );
123
- register_setting(
124
- 'caos-webfonts-basic-settings',
125
- self::OMGF_SETTING_DETECTED_FONTS
126
- );
127
- register_setting(
128
- 'caos-webfonts-basic-settings',
129
- self::OMGF_SETTING_CACHE_DIR
130
- );
131
- register_setting(
132
- 'caos-webfonts-basic-settings',
133
- self::OMGF_SETTING_CDN_URL
134
- );
135
- register_setting(
136
- 'caos-webfonts-basic-settings',
137
- self::OMGF_SETTING_WEB_FONT_LOADER
138
- );
139
- register_setting(
140
- 'caos-webfonts-basic-settings',
141
- self::OMGF_SETTING_REMOVE_VERSION
142
- );
143
- register_setting(
144
- 'caos-webfonts-basic-settings',
145
- self::OMGF_SETTING_DISPLAY_OPTION
146
- );
147
- register_setting(
148
- 'caos-webfonts-basic-settings',
149
- self::OMGF_SETTING_REMOVE_GOOGLE_FONTS
150
- );
151
- register_setting(
152
- 'caos-webfonts-basic-settings',
153
- self::OMGF_SETTING_ENABLE_PRELOAD
154
- );
155
- register_setting(
156
- 'caos-webfonts-basic-settings',
157
- self::OMGF_SETTING_UNINSTALL
158
- );
159
  }
160
 
161
  /**
@@ -171,4 +140,24 @@ class OMGF_Admin_Settings extends OMGF_Admin
171
 
172
  return $links;
173
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  }
27
  );
28
  const OMGF_SETTING_AUTO_DETECTION_ENABLED = 'omgf_auto_detection_enabled';
29
  const OMGF_SETTING_DETECTED_FONTS = 'omgf_detected_fonts';
30
+ const OMGF_SETTING_CACHE_DIR = 'omgf_cache_dir';
31
+ const OMGF_SETTING_CDN_URL = 'omgf_cdn_url';
32
  const OMGF_SETTING_WEB_FONT_LOADER = 'omgf_web_font_loader';
33
+ const OMGF_SETTING_REMOVE_VERSION = 'omgf_remove_version';
34
+ const OMGF_SETTING_DISPLAY_OPTION = 'omgf_display_option';
35
+ const OMGF_SETTING_REMOVE_GOOGLE_FONTS = 'omgf_remove_gfonts';
36
+ const OMGF_SETTING_ENABLE_PRELOAD = 'omgf_preload';
37
+ const OMGF_SETTING_DB_VERSION = 'omgf_db_version';
38
  const OMGF_SETTING_UNINSTALL = 'omgf_uninstall';
39
 
40
  /**
97
 
98
  <form id="hwl-settings-form" class="settings-column right" name="hwl-settings-form" method="post" action="options.php">
99
  <?php
100
+ settings_fields('omgf-basic-settings');
101
+ do_settings_sections('omgf-basic-settings');
102
 
103
  $this->get_template('basic-settings');
104
 
105
+ do_action('omgf_after_settings_form_settings');
106
 
107
  submit_button();
108
  ?>
112
  }
113
 
114
  /**
115
+ * Register all settings.
116
+ *
117
+ * @throws ReflectionException
118
  */
119
  public function register_settings()
120
  {
121
+ foreach ($this->get_settings() as $constant => $value)
122
+ {
123
+ register_setting(
124
+ 'omgf-basic-settings',
125
+ $value
126
+ );
127
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  }
129
 
130
  /**
140
 
141
  return $links;
142
  }
143
+
144
+ /**
145
+ * Get all settings using the constants in this class.
146
+ *
147
+ * @return array
148
+ * @throws ReflectionException
149
+ */
150
+ public function get_settings()
151
+ {
152
+ $reflection = new ReflectionClass($this);
153
+ $constants = $reflection->getConstants();
154
+
155
+ return array_filter(
156
+ $constants,
157
+ function ($key) {
158
+ return strpos($key, 'OMGF_SETTING') !== false;
159
+ },
160
+ ARRAY_FILTER_USE_KEY
161
+ );
162
+ }
163
  }
includes/class-admin.php CHANGED
@@ -24,7 +24,7 @@ class OMGF_Admin
24
  public function __construct()
25
  {
26
  // @formatter:off
27
- add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_js'));
28
  // @formatter:on
29
  }
30
 
@@ -33,7 +33,7 @@ class OMGF_Admin
33
  *
34
  * @param $hook
35
  */
36
- public function enqueue_admin_js($hook)
37
  {
38
  if ($hook == 'settings_page_optimize-webfonts') {
39
  wp_enqueue_script(self::OMGF_ADMIN_JS_HANDLE, plugin_dir_url(OMGF_PLUGIN_FILE) . 'js/hwl-admin.js', array('jquery'), OMGF_STATIC_VERSION, true);
24
  public function __construct()
25
  {
26
  // @formatter:off
27
+ add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
28
  // @formatter:on
29
  }
30
 
33
  *
34
  * @param $hook
35
  */
36
+ public function enqueue_admin_scripts($hook)
37
  {
38
  if ($hook == 'settings_page_optimize-webfonts') {
39
  wp_enqueue_script(self::OMGF_ADMIN_JS_HANDLE, plugin_dir_url(OMGF_PLUGIN_FILE) . 'js/hwl-admin.js', array('jquery'), OMGF_STATIC_VERSION, true);
includes/class-omgf.php CHANGED
@@ -49,7 +49,7 @@ class OMGF
49
  global $wpdb;
50
 
51
  define('OMGF_SITE_URL', 'https://daan.dev');
52
- define('OMGF_DB_TABLENAME', $wpdb->prefix . 'caos_webfonts');
53
  define('OMGF_DB_CHARSET', $wpdb->get_charset_collate());
54
  define('OMGF_HELPER_URL', 'https://google-webfonts-helper.herokuapp.com/api/fonts/');
55
  define('OMGF_FILENAME', 'fonts.css');
49
  global $wpdb;
50
 
51
  define('OMGF_SITE_URL', 'https://daan.dev');
52
+ define('OMGF_DB_TABLENAME', $wpdb->prefix . 'omgf_fonts');
53
  define('OMGF_DB_CHARSET', $wpdb->get_charset_collate());
54
  define('OMGF_HELPER_URL', 'https://google-webfonts-helper.herokuapp.com/api/fonts/');
55
  define('OMGF_FILENAME', 'fonts.css');
includes/class-setup.php CHANGED
@@ -38,16 +38,20 @@ class OMGF_Setup
38
  */
39
  public function run_db_updates()
40
  {
41
- $currentVersion = get_option('caos_webfonts_db_version') ?: '1.0.0';
42
  if (version_compare($currentVersion, '1.6.1') < 0) {
43
  $this->create_webfonts_table();
44
  }
45
  if (version_compare($currentVersion, '1.7.0') < 0) {
46
  $this->create_subsets_table();
47
  }
48
- if (version_compare($currentVersion, OMGF_DB_VERSION) < 0) {
49
  $this->add_local_column();
50
  }
 
 
 
 
51
  }
52
 
53
  /**
@@ -69,7 +73,7 @@ class OMGF_Setup
69
  ) " . OMGF_DB_CHARSET . ";";
70
  $this->wpdb->query($sql);
71
 
72
- add_option('caos_webfonts_db_version', '1.6.1');
73
  }
74
 
75
  /**
@@ -86,7 +90,7 @@ class OMGF_Setup
86
  ) " . OMGF_DB_CHARSET . ";";
87
  $this->wpdb->query($sql);
88
 
89
- update_option('caos_webfonts_db_version', '1.7.0');
90
  }
91
 
92
  /**
@@ -98,6 +102,49 @@ class OMGF_Setup
98
  "ADD COLUMN local varchar(128) AFTER font_style;";
99
  $this->wpdb->query($sql);
100
 
101
- update_option('caos_webfonts_db_version', '1.8.3');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  }
103
  }
38
  */
39
  public function run_db_updates()
40
  {
41
+ $currentVersion = get_option(OMGF_Admin_Settings::OMGF_SETTING_DB_VERSION) ?: get_option('caos_webfonts_db_version') ?: '1.0.0';
42
  if (version_compare($currentVersion, '1.6.1') < 0) {
43
  $this->create_webfonts_table();
44
  }
45
  if (version_compare($currentVersion, '1.7.0') < 0) {
46
  $this->create_subsets_table();
47
  }
48
+ if (version_compare($currentVersion, '1.8.3') < 0) {
49
  $this->add_local_column();
50
  }
51
+ if (version_compare($currentVersion, OMGF_DB_VERSION) < 0) {
52
+ $this->rename_tables();
53
+ $this->migrate_options();
54
+ }
55
  }
56
 
57
  /**
73
  ) " . OMGF_DB_CHARSET . ";";
74
  $this->wpdb->query($sql);
75
 
76
+ $this->set_db_version('1.6.1');
77
  }
78
 
79
  /**
90
  ) " . OMGF_DB_CHARSET . ";";
91
  $this->wpdb->query($sql);
92
 
93
+ $this->set_db_version('1.7.0');
94
  }
95
 
96
  /**
102
  "ADD COLUMN local varchar(128) AFTER font_style;";
103
  $this->wpdb->query($sql);
104
 
105
+ $this->set_db_version('1.8.3');
106
+ }
107
+
108
+ /**
109
+ * Delete options with old plugin names and migrate them to new names.
110
+ */
111
+ private function migrate_options()
112
+ {
113
+ $table = $this->wpdb->prefix . 'options';
114
+ $sql = "SELECT * FROM $table WHERE option_name LIKE '%caos_webfonts%'";
115
+ $legacy_options = $this->wpdb->get_results($sql);
116
+
117
+ foreach ($legacy_options as &$option) {
118
+ $legacy_name = $option->option_name;
119
+ $option->option_name = str_replace('caos_webfonts', 'omgf', $legacy_name);
120
+ add_option($option->option_name, $option->option_value);
121
+ delete_option($legacy_name);
122
+ }
123
+
124
+ $this->set_db_version('2.2.2');
125
+ }
126
+
127
+ /**
128
+ * Rename tables using OMGF_DB_TABLENAME.
129
+ */
130
+ private function rename_tables()
131
+ {
132
+ $table = $this->wpdb->prefix . 'caos_webfonts';
133
+ $subsets = $table . '_subsets';
134
+ $sql = "ALTER TABLE $table RENAME TO " . OMGF_DB_TABLENAME;
135
+ $sql_subsets = "ALTER TABLE $subsets RENAME TO " . OMGF_DB_TABLENAME . '_subsets';
136
+
137
+ $this->wpdb->query($sql);
138
+ $this->wpdb->query($sql_subsets);
139
+
140
+ $this->set_db_version('2.2.2');
141
+ }
142
+
143
+ /**
144
+ * @param $value
145
+ */
146
+ private function set_db_version($value)
147
+ {
148
+ update_option(OMGF_Admin_Settings::OMGF_SETTING_DB_VERSION, $value);
149
  }
150
  }
includes/class-uninstall.php CHANGED
@@ -41,9 +41,10 @@ class OMGF_Uninstall
41
  }
42
 
43
  global $wpdb;
 
44
 
45
  $this->wpdb = $wpdb;
46
- $this->options = $this->get_options();
47
  $this->table = OMGF_DB_TABLENAME;
48
  $this->cacheDir = OMGF_UPLOAD_DIR;
49
 
@@ -53,25 +54,6 @@ class OMGF_Uninstall
53
  $this->delete_dir();
54
  }
55
 
56
- /**
57
- * @return array
58
- * @throws ReflectionException
59
- */
60
- private function get_options()
61
- {
62
- $settings = new OMGF_Admin_Settings();
63
- $reflection = new ReflectionClass($settings);
64
- $constants = $reflection->getConstants();
65
-
66
- return array_filter(
67
- $constants,
68
- function ($key) {
69
- return strpos($key, 'OMGF_SETTING') !== false;
70
- },
71
- ARRAY_FILTER_USE_KEY
72
- );
73
- }
74
-
75
  /**
76
  * Remove all settings stored in the wp_options table.
77
  */
41
  }
42
 
43
  global $wpdb;
44
+ $settings = new OMGF_Admin_Settings();
45
 
46
  $this->wpdb = $wpdb;
47
+ $this->options = $settings->get_settings();
48
  $this->table = OMGF_DB_TABLENAME;
49
  $this->cacheDir = OMGF_UPLOAD_DIR;
50
 
54
  $this->delete_dir();
55
  }
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  /**
58
  * Remove all settings stored in the wp_options table.
59
  */
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://daan.dev/donate/
4
  Tags: google, fonts, host, save, local, locally, webfonts, update, minimize, external, requests, leverage, browser, cache
5
  Requires at least: 4.6
6
  Tested up to: 5.3
7
- Stable tag: 2.2.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -115,6 +115,9 @@ N/A
115
 
116
  == Changelog ==
117
 
 
 
 
118
  = 2.2.1 =
119
  wp-block-editor style is now ignored when detecting stylesheets that depend on Google Fonts, when the remove function is enabled.
120
 
4
  Tags: google, fonts, host, save, local, locally, webfonts, update, minimize, external, requests, leverage, browser, cache
5
  Requires at least: 4.6
6
  Tested up to: 5.3
7
+ Stable tag: 2.2.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
115
 
116
  == Changelog ==
117
 
118
+ = 2.2.2 =
119
+ Added long overdue migration script for options and tables. Code optimizations.
120
+
121
  = 2.2.1 =
122
  wp-block-editor style is now ignored when detecting stylesheets that depend on Google Fonts, when the remove function is enabled.
123