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

Version Description

  • Use WordPress' tabs system for navigation to comply with Plugin Conventions.
  • Fixed bug which caused preload font styles to be saved incorrectly.
  • Replaced separate apply buttons with one apply button, which handles the entire queue for removal as well as preload at once.
  • Known bug: 'Apply' button isn't clickable when sticky. Available workaround: scroll to the bottom of the list and click 'Apply'.
Download this release

Release Info

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

Code changes from version 3.3.0 to 3.3.1

css/omgf-admin.css CHANGED
@@ -16,187 +16,145 @@
16
  * Navigation
17
  */
18
  .omgf-nav {
19
- padding: 1em 0 1.5em;
20
- }
21
-
22
- .omgf-nav span {
23
- color: #23282d;
24
- font-size: 1.3em;
25
- margin-right: 1.5em;
26
- font-weight: 600;
27
- }
28
-
29
- .omgf-nav span:hover {
30
- cursor: pointer;
31
- }
32
-
33
- .omgf-nav span:not(.selected) {
34
- opacity: 0.85;
35
- }
36
-
37
- .omgf-nav .selected,
38
- .omgf-nav span:hover {
39
- border-bottom: 1px dashed #23282d;
40
- padding: 3px 0;
41
- }
42
-
43
  .omgf-nav .dashicons-before:before {
44
- margin-right: 0.25em;
 
45
  }
46
-
47
  /**
48
  * Sections
49
  */
50
- .settings-column {
51
- display: inline-block;
52
- }
53
-
54
  .settings-column.left {
55
- float: left;
56
- width: 66%;
57
  }
58
-
59
  .settings-column.right {
60
- float: right;
61
- width: 21.75%;
62
  }
63
-
64
  /**
65
  * Welcome block
66
  */
67
  #omgf-welcome-panel {
68
- padding: 20px 10px 5px;
69
  }
70
-
71
  #omgf-welcome-panel h3 > .dashicons {
72
- line-height: 1.4;
73
  }
74
-
75
  /**
76
  * Generate Stylesheet-form
77
  */
78
  .omgf-generate-stylesheet table {
79
- margin-top: 0.66em;
80
  }
81
-
82
  .omgf-generate-stylesheet .omgf-search-section {
83
- max-width: 640px;
84
- margin-top: 1em;
 
 
 
85
  }
86
-
87
  .omgf-generate-stylesheet .omgf-search-section a.omgf-apply span:before {
88
- line-height: 1.4;
89
- width: 16px;
90
  }
91
-
92
  .omgf-generate-stylesheet .omgf-search-section caption {
93
- text-align: left;
94
- font-size: 1.2em;
95
- font-weight: 600;
96
- margin: 0.66em 0 0.33em;
97
  }
98
-
99
  .omgf-generate-stylesheet .omgf-search-section span.omgf-apply.font-styles-search {
100
- width: 75%;
101
  }
102
-
103
  .omgf-generate-stylesheet .omgf-search-section #omgf-search {
104
- line-height: 38px;
105
- width: 360px;
106
- padding: 3px 10px;
107
- }
108
-
109
- .omgf-generate-stylesheet .omgf-search-section #omgf-font-styles .omgf-font-remove {
110
- cursor: pointer;
111
- padding: 0 0 0 20px;
112
- position: relative;
113
- display: inline-block;
114
- }
115
-
116
- .omgf-generate-stylesheet .omgf-search-section #omgf-font-styles .omgf-font-remove:before {
117
- position: absolute;
118
- left: 0;
119
- }
120
-
121
  .omgf-generate-stylesheet .omgf-search-section #omgf-font-styles #font-styles-nav.sticky {
122
- background: #f1f1f1;
123
- box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
124
- width: 565px;
125
  }
126
-
127
  .omgf-generate-stylesheet #omgf-control-panel {
128
- margin-top: 1em;
129
  }
130
-
131
  .omgf-generate-stylesheet #omgf-control-panel .button-cancel {
132
- color: #a00;
133
- text-decoration: none;
134
- border-color: transparent;
135
- box-shadow: none;
136
- background: 0 0;
137
- border-radius: 3px;
138
- white-space: nowrap;
139
- padding: 1px 10px !important;
140
- }
141
-
142
  .omgf-generate-stylesheet #omgf-control-panel .button-cancel:hover {
143
- cursor: pointer;
144
- background: #d54e21;
145
- color: #fff;
146
- border-color: #d54e21;
147
  }
148
-
149
  /**
150
  * Loader
151
  */
152
  .omgf-loading {
153
- position: absolute;
154
- width: 100%;
155
- height: 100%;
156
- left: 0;
157
- right: 0;
158
- top: 0;
159
- text-align: center;
160
  }
161
-
162
  .omgf-loading .spinner {
163
- top: 50%;
164
- left: 50%;
165
- position: absolute;
166
- -ms-transform: translate(0, -70%);
167
- transform: translate(0, -70%);
168
  }
169
-
170
  /**
171
  * Sticky elements.
172
  */
173
  .sticky {
174
- position: -webkit-sticky;
175
- position: sticky;
176
- overflow: visible;
177
  }
178
-
179
  .sticky.top {
180
- top: 25px;
181
  }
182
-
183
  .sticky.bottom {
184
- bottom: 0;
185
  }
186
-
187
  /**
188
  * Responsiveness
189
  */
190
  @media only screen and (max-width: 1024px) {
191
- .settings-column {
192
- display: block;
193
- float: none;
194
- }
195
-
196
- .settings-column.left,
197
- .settings-column.right {
198
- width: 100%;
199
- }
200
- }
201
-
202
  /*# sourceMappingURL=omgf-admin.css.map */
16
  * Navigation
17
  */
18
  .omgf-nav {
19
+ padding: 1em 0 1.5em;
20
+ }
21
+ .omgf-nav a {
22
+ cursor: pointer;
23
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  .omgf-nav .dashicons-before:before {
25
+ margin-right: 0.25em;
26
+ line-height: 1.15em;
27
  }
 
28
  /**
29
  * Sections
30
  */
 
 
 
 
31
  .settings-column.left {
32
+ float: left;
33
+ width: 66%;
34
  }
 
35
  .settings-column.right {
36
+ float: right;
37
+ width: 21.75%;
38
  }
 
39
  /**
40
  * Welcome block
41
  */
42
  #omgf-welcome-panel {
43
+ padding: 20px 10px 5px;
44
  }
 
45
  #omgf-welcome-panel h3 > .dashicons {
46
+ line-height: 1.4;
47
  }
 
48
  /**
49
  * Generate Stylesheet-form
50
  */
51
  .omgf-generate-stylesheet table {
52
+ margin-top: 0.66em;
53
  }
 
54
  .omgf-generate-stylesheet .omgf-search-section {
55
+ max-width: 640px;
56
+ margin-top: 1em;
57
+ }
58
+ .omgf-generate-stylesheet .omgf-search-section a.omgf-apply.button {
59
+ width: 85px;
60
  }
 
61
  .omgf-generate-stylesheet .omgf-search-section a.omgf-apply span:before {
62
+ line-height: 1.4;
63
+ width: 16px;
64
  }
 
65
  .omgf-generate-stylesheet .omgf-search-section caption {
66
+ text-align: left;
67
+ font-size: 1.2em;
68
+ font-weight: 600;
69
+ margin: 0.66em 0 0.33em;
70
  }
 
71
  .omgf-generate-stylesheet .omgf-search-section span.omgf-apply.font-styles-search {
72
+ width: 75%;
73
  }
 
74
  .omgf-generate-stylesheet .omgf-search-section #omgf-search {
75
+ line-height: 38px;
76
+ width: 360px;
77
+ padding: 3px 10px;
78
+ }
79
+ .omgf-generate-stylesheet .omgf-search-section #omgf-font-styles .omgf-font-remove,
80
+ .omgf-generate-stylesheet .omgf-search-section #omgf-font-styles .omgf-font-no-remove {
81
+ cursor: pointer;
82
+ padding: 0 0 0 20px;
83
+ position: relative;
84
+ display: inline-block;
85
+ }
86
+ .omgf-generate-stylesheet .omgf-search-section #omgf-font-styles .omgf-font-remove:before,
87
+ .omgf-generate-stylesheet .omgf-search-section #omgf-font-styles .omgf-font-no-remove:before {
88
+ position: absolute;
89
+ left: 0;
90
+ }
 
91
  .omgf-generate-stylesheet .omgf-search-section #omgf-font-styles #font-styles-nav.sticky {
92
+ background: #f1f1f1;
93
+ box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
94
+ width: 565px;
95
  }
 
96
  .omgf-generate-stylesheet #omgf-control-panel {
97
+ margin-top: 1em;
98
  }
 
99
  .omgf-generate-stylesheet #omgf-control-panel .button-cancel {
100
+ color: #a00;
101
+ text-decoration: none;
102
+ border-color: transparent;
103
+ box-shadow: none;
104
+ background: 0 0;
105
+ border-radius: 3px;
106
+ white-space: nowrap;
107
+ padding: 1px 10px !important;
108
+ }
 
109
  .omgf-generate-stylesheet #omgf-control-panel .button-cancel:hover {
110
+ cursor: pointer;
111
+ background: #d54e21;
112
+ color: #fff;
113
+ border-color: #d54e21;
114
  }
 
115
  /**
116
  * Loader
117
  */
118
  .omgf-loading {
119
+ position: absolute;
120
+ width: 100%;
121
+ height: 100%;
122
+ left: 0;
123
+ right: 0;
124
+ top: 0;
125
+ text-align: center;
126
  }
 
127
  .omgf-loading .spinner {
128
+ top: 50%;
129
+ left: 50%;
130
+ position: absolute;
131
+ -ms-transform: translate(0, -70%);
132
+ transform: translate(0, -70%);
133
  }
 
134
  /**
135
  * Sticky elements.
136
  */
137
  .sticky {
138
+ position: -webkit-sticky;
139
+ position: sticky;
 
140
  }
 
141
  .sticky.top {
142
+ top: 25px;
143
  }
 
144
  .sticky.bottom {
145
+ bottom: 0;
146
  }
 
147
  /**
148
  * Responsiveness
149
  */
150
  @media only screen and (max-width: 1024px) {
151
+ .settings-column {
152
+ display: block;
153
+ float: none;
154
+ }
155
+ .settings-column.left,
156
+ .settings-column.right {
157
+ width: 100%;
158
+ }
159
+ }
 
 
160
  /*# sourceMappingURL=omgf-admin.css.map */
css/omgf-admin.css.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["omgf-admin.less"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAkBA;EACE,oBAAA;;AADF,SAGE;EACE,cAAA;EACA,gBAAA;EACA,mBAAA;EACA,gBAAA;;AAEA,SANF,KAMG;EACC,eAAA;;AAGF,SAVF,KAUG,IAAI;EACH,aAAA;;AAdN,SAkBE;AAlBF,SAmBE,KAAI;EACF,iCAAA;EACA,cAAA;;AArBJ,SAwBE,kBAAiB;EACf,oBAAA;;;;;AAOJ;EACE,qBAAA;;AAEA,gBAAC;EACC,WAAA;EACA,UAAA;;AAGF,gBAAC;EACC,YAAA;EACA,aAAA;;;;;AAOJ;EACE,sBAAA;;AADF,mBAGE,GAAG;EACD,gBAAA;;;;;AAOJ,yBACE;EACE,kBAAA;;AAFJ,yBAKE;EACE,gBAAA;EACA,eAAA;;AAGE,yBALJ,qBAIE,EACG,WACC,KAAI;EACF,gBAAA;EACA,WAAA;;AAbV,yBAKE,qBAaE;EACE,gBAAA;EACA,gBAAA;EACA,gBAAA;EACA,uBAAA;;AAKE,yBAtBN,qBAoBE,KACG,WACE;EACC,UAAA;;AA5BV,yBAKE,qBA4BE;EACE,iBAAA;EACA,YAAA;EACA,iBAAA;;AApCN,yBAKE,qBAkCE,kBACE;EACE,eAAA;EACA,mBAAA;EACA,kBAAA;EACA,qBAAA;;AAEA,yBAzCN,qBAkCE,kBACE,kBAMG;EACC,kBAAA;EACA,OAAA;;AAKF,yBAhDN,qBAkCE,kBAaE,iBACG;EACC,mBAAA;EACA,yCAAA;EACA,YAAA;;AAxDV,yBA8DE;EACE,eAAA;;AA/DJ,yBA8DE,oBAGE;EACE,WAAA;EACA,qBAAA;EACA,yBAAA;EACA,gBAAA;EACA,eAAA;EACA,kBAAA;EACA,mBAAA;EACA,4BAAA;;AAEA,yBAbJ,oBAGE,eAUG;EACC,eAAA;EACA,mBAAA;EACA,WAAA;EACA,qBAAA;;;;;AASR;EACE,kBAAA;EACA,WAAA;EACA,YAAA;EACA,OAAA;EACA,QAAA;EACA,MAAA;EACA,kBAAA;;AAPF,aASE;EACE,QAAA;EACA,SAAA;EACA,kBAAA;EACA,eAAe,kBAAf;EACA,WAAW,kBAAX;;;;;AAOJ;EACE,wBAAA;EACA,gBAAA;EACA,iBAAA;;AAEA,OAAC;EACC,SAAA;;AAGF,OAAC;EACC,SAAA;;;;;AAOJ,wBAA2C;EACzC;IACE,cAAA;IACA,WAAA;;EAEA,gBAAC;EACD,gBAAC;IACC,WAAA","file":"omgf-admin.css"}
1
+ {"version":3,"sources":["omgf-admin.less"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAkBA;EACE,oBAAA;;AADF,SAGE;EACE,eAAA;;AAJJ,SAOE,kBAAiB;EACf,oBAAA;EACA,mBAAA;;;;;AAQF,gBAAC;EACC,WAAA;EACA,UAAA;;AAGF,gBAAC;EACC,YAAA;EACA,aAAA;;;;;AAOJ;EACE,sBAAA;;AADF,mBAGE,GAAG;EACD,gBAAA;;;;;AAOJ,yBACE;EACE,kBAAA;;AAFJ,yBAKE;EACE,gBAAA;EACA,eAAA;;AAII,yBANN,qBAIE,EACG,WACE;EACC,WAAA;;AAFJ,yBALJ,qBAIE,EACG,WAKC,KAAI;EACF,gBAAA;EACA,WAAA;;AAjBV,yBAKE,qBAiBE;EACE,gBAAA;EACA,gBAAA;EACA,gBAAA;EACA,uBAAA;;AAKE,yBA1BN,qBAwBE,KACG,WACE;EACC,UAAA;;AAhCV,yBAKE,qBAgCE;EACE,iBAAA;EACA,YAAA;EACA,iBAAA;;AAxCN,yBAKE,qBAsCE,kBACE;AA5CN,yBAKE,qBAsCE,kBAEE;EACE,eAAA;EACA,mBAAA;EACA,kBAAA;EACA,qBAAA;;AAEA,yBA9CN,qBAsCE,kBACE,kBAOG;AAAD,yBA9CN,qBAsCE,kBAEE,qBAMG;EACC,kBAAA;EACA,OAAA;;AAKF,yBArDN,qBAsCE,kBAcE,iBACG;EACC,mBAAA;EACA,yCAAA;EACA,YAAA;;AA7DV,yBAmEE;EACE,eAAA;;AApEJ,yBAmEE,oBAGE;EACE,WAAA;EACA,qBAAA;EACA,yBAAA;EACA,gBAAA;EACA,eAAA;EACA,kBAAA;EACA,mBAAA;EACA,4BAAA;;AAEA,yBAbJ,oBAGE,eAUG;EACC,eAAA;EACA,mBAAA;EACA,WAAA;EACA,qBAAA;;;;;AASR;EACE,kBAAA;EACA,WAAA;EACA,YAAA;EACA,OAAA;EACA,QAAA;EACA,MAAA;EACA,kBAAA;;AAPF,aASE;EACE,QAAA;EACA,SAAA;EACA,kBAAA;EACA,eAAe,kBAAf;EACA,WAAW,kBAAX;;;;;AAOJ;EACE,wBAAA;EACA,gBAAA;;AAEA,OAAC;EACC,SAAA;;AAGF,OAAC;EACC,SAAA;;;;;AAOJ,wBAA2C;EACzC;IACE,cAAA;IACA,WAAA;;EAEA,gBAAC;EACD,gBAAC;IACC,WAAA","file":"omgf-admin.css"}
css/omgf-admin.less CHANGED
@@ -19,29 +19,13 @@
19
  .omgf-nav {
20
  padding: 1em 0 1.5em;
21
 
22
- span {
23
- color: #23282d;
24
- font-size: 1.3em;
25
- margin-right: 1.5em;
26
- font-weight: 600;
27
-
28
- &:hover {
29
- cursor: pointer;
30
- }
31
-
32
- &:not(.selected) {
33
- opacity: 0.85;
34
- }
35
- }
36
-
37
- .selected,
38
- span:hover {
39
- border-bottom: 1px dashed #23282d;
40
- padding: 3px 0;
41
  }
42
 
43
  .dashicons-before:before {
44
  margin-right: .25em;
 
45
  }
46
  }
47
 
@@ -49,8 +33,6 @@
49
  * Sections
50
  */
51
  .settings-column {
52
- display: inline-block;
53
-
54
  &.left {
55
  float: left;
56
  width: 66%;
@@ -87,6 +69,10 @@
87
 
88
  a {
89
  &.omgf-apply {
 
 
 
 
90
  span:before {
91
  line-height: 1.4;
92
  width: 16px;
@@ -116,7 +102,8 @@
116
  }
117
 
118
  #omgf-font-styles {
119
- .omgf-font-remove {
 
120
  cursor: pointer;
121
  padding: 0 0 0 20px;
122
  position: relative;
@@ -188,7 +175,6 @@
188
  .sticky {
189
  position: -webkit-sticky;
190
  position: sticky;
191
- overflow: visible;
192
 
193
  &.top {
194
  top: 25px;
19
  .omgf-nav {
20
  padding: 1em 0 1.5em;
21
 
22
+ a {
23
+ cursor: pointer;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  }
25
 
26
  .dashicons-before:before {
27
  margin-right: .25em;
28
+ line-height: 1.15em;
29
  }
30
  }
31
 
33
  * Sections
34
  */
35
  .settings-column {
 
 
36
  &.left {
37
  float: left;
38
  width: 66%;
69
 
70
  a {
71
  &.omgf-apply {
72
+ &.button {
73
+ width: 85px;
74
+ }
75
+
76
  span:before {
77
  line-height: 1.4;
78
  width: 16px;
102
  }
103
 
104
  #omgf-font-styles {
105
+ .omgf-font-remove,
106
+ .omgf-font-no-remove {
107
  cursor: pointer;
108
  padding: 0 0 0 20px;
109
  position: relative;
175
  .sticky {
176
  position: -webkit-sticky;
177
  position: sticky;
 
178
 
179
  &.top {
180
  top: 25px;
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: 3.3.0
8
  * Author: Daan van den Bergh
9
  * Author URI: https://daan.dev
10
  * License: GPL2v2 or later
@@ -20,7 +20,7 @@ defined('ABSPATH') || exit;
20
  define('OMGF_PLUGIN_DIR', plugin_dir_path(__FILE__));
21
  define('OMGF_PLUGIN_FILE', __FILE__);
22
  define('OMGF_DB_VERSION', '3.0.0');
23
- define('OMGF_STATIC_VERSION', '3.3.0');
24
  define('OMGF_WEB_FONT_LOADER_VERSION', '1.6.26');
25
 
26
  /**
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: 3.3.1
8
  * Author: Daan van den Bergh
9
  * Author URI: https://daan.dev
10
  * License: GPL2v2 or later
20
  define('OMGF_PLUGIN_DIR', plugin_dir_path(__FILE__));
21
  define('OMGF_PLUGIN_FILE', __FILE__);
22
  define('OMGF_DB_VERSION', '3.0.0');
23
+ define('OMGF_STATIC_VERSION', '3.3.1');
24
  define('OMGF_WEB_FONT_LOADER_VERSION', '1.6.26');
25
 
26
  /**
includes/admin/class-settings.php CHANGED
@@ -18,7 +18,14 @@ defined('ABSPATH') || exit;
18
 
19
  class OMGF_Admin_Settings extends OMGF_Admin
20
  {
 
 
 
21
  const OMGF_SETTINGS_FIELD_ADVANCED = 'omgf-advanced-settings';
 
 
 
 
22
  const OMGF_FONT_DISPLAY_OPTIONS = array(
23
  'Auto (default)' => 'auto',
24
  'Block' => 'block',
@@ -26,35 +33,48 @@ class OMGF_Admin_Settings extends OMGF_Admin
26
  'Fallback' => 'fallback',
27
  'Optional' => 'optional'
28
  );
29
- const OMGF_SETTING_AUTO_DETECTION_ENABLED = 'omgf_auto_detection_enabled';
30
- const OMGF_SETTING_SUBSETS = 'omgf_subsets';
31
- const OMGF_SETTING_FONTS = 'omgf_fonts';
32
- const OMGF_SETTING_DETECTED_FONTS = 'omgf_detected_fonts';
33
- const OMGF_SETTING_CACHE_PATH = 'omgf_cache_dir';
34
- const OMGF_SETTING_CACHE_URI = 'omgf_cache_uri';
35
- const OMGF_SETTING_CDN_URL = 'omgf_cdn_url';
36
- const OMGF_SETTING_WEB_FONT_LOADER = 'omgf_web_font_loader';
37
- const OMGF_SETTING_REMOVE_VERSION = 'omgf_remove_version';
38
- const OMGF_SETTING_DISPLAY_OPTION = 'omgf_display_option';
39
- const OMGF_SETTING_REMOVE_GOOGLE_FONTS = 'omgf_remove_gfonts';
40
- const OMGF_SETTING_ENABLE_PRELOAD = 'omgf_preload';
41
- const OMGF_SETTING_DB_VERSION = 'omgf_db_version';
42
- const OMGF_SETTING_UNINSTALL = 'omgf_uninstall';
43
- const OMGF_SETTING_ENQUEUE_ORDER = 'omgf_enqueue_order';
44
- const OMGF_SETTING_RELATIVE_URL = 'omgf_relative_url';
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  /**
47
  * OMGF_Admin_Settings constructor.
48
  */
49
  public function __construct()
50
  {
51
- // @formatter:off
52
- add_action('admin_menu', array($this, 'create_menu'));
53
-
54
- $caosLink = plugin_basename(OMGF_PLUGIN_FILE);
55
 
56
- add_filter("plugin_action_links_$caosLink", array($this, 'create_settings_link'));
57
- add_filter('whitelist_options', [$this, 'remove_settings_from_whitelist'], 100);
 
 
 
 
 
58
  // @formatter:on
59
 
60
  parent::__construct();
@@ -86,7 +106,7 @@ class OMGF_Admin_Settings extends OMGF_Admin
86
  public function create_settings_page()
87
  {
88
  if (!current_user_can('manage_options')) {
89
- wp_die(__("You're not cool enough to access this page."));
90
  }
91
  ?>
92
  <div class="wrap">
@@ -97,29 +117,11 @@ class OMGF_Admin_Settings extends OMGF_Admin
97
  </p>
98
 
99
  <div class="settings-column left">
100
- <div class="omgf-nav">
101
- <span class="generate-stylesheet dashicons-before dashicons-admin-appearance selected"><?php _e('Generate Stylesheet', 'host-webfonts-local'); ?></span>
102
- <span class="advanced-settings dashicons-before dashicons-admin-settings"><?php _e('Advanced Settings', 'host-webfonts-local'); ?></span>
103
- </div>
104
-
105
- <form id="omgf-generate-stylesheet-form" name="omgf-generate-stylesheet-form" style="display: block;">
106
- <?php
107
- $this->get_template('generate-stylesheet');
108
- ?>
109
- </form>
110
-
111
- <form id="omgf-advanced-settings-form" name="omgf-settings-form" method="post" action="options.php" style="display: none;">
112
- <?php
113
- settings_fields(OMGF_Admin_Settings::OMGF_SETTINGS_FIELD_ADVANCED);
114
- do_settings_sections(OMGF_Admin_Settings::OMGF_SETTINGS_FIELD_ADVANCED);
115
 
116
- $this->get_template('advanced-settings');
117
-
118
- do_action('omgf_after_settings_form_settings');
119
-
120
- submit_button();
121
- ?>
122
- </form>
123
  </div>
124
 
125
  <div class="settings-column right">
@@ -148,58 +150,117 @@ class OMGF_Admin_Settings extends OMGF_Admin
148
  }
149
 
150
  /**
151
- * Adds the 'settings' link to the Plugin overview.
152
  *
153
- * @return mixed
 
154
  */
155
- public function create_settings_link($links)
156
  {
157
- $adminUrl = admin_url() . 'options-general.php?page=optimize-webfonts';
158
- $settingsLink = "<a href='$adminUrl'>" . __('Settings') . "</a>";
159
- array_push($links, $settingsLink);
160
 
161
- return $links;
 
 
 
 
 
 
162
  }
163
 
164
  /**
165
- * Preserve fonts and subsets when saving changes.
166
- *
167
- * @param $options
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  *
169
- * @return array
170
  */
171
- public function remove_settings_from_whitelist($options)
172
  {
173
- if (!isset($options[self::OMGF_SETTINGS_FIELD_ADVANCED])) {
174
- return $options;
 
 
 
 
 
 
 
 
175
  }
 
 
 
 
 
 
 
 
176
 
177
- foreach ($options[self::OMGF_SETTINGS_FIELD_ADVANCED] as $key => &$setting) {
178
- if ($setting == self::OMGF_SETTING_FONTS || $setting == self::OMGF_SETTING_SUBSETS) {
179
- unset($options[self::OMGF_SETTINGS_FIELD_ADVANCED][$key]);
180
- }
 
 
 
181
  }
 
 
 
 
 
 
 
 
 
182
 
183
- return $options;
 
 
 
184
  }
185
 
186
  /**
187
- * Get all settings using the constants in this class.
188
  *
189
- * @return array
190
- * @throws ReflectionException
191
  */
192
- public function get_settings()
193
  {
194
- $reflection = new ReflectionClass($this);
195
- $constants = $reflection->getConstants();
 
196
 
197
- return array_filter(
198
- $constants,
199
- function ($key) {
200
- return strpos($key, 'OMGF_SETTING') !== false;
201
- },
202
- ARRAY_FILTER_USE_KEY
203
- );
204
  }
205
  }
18
 
19
  class OMGF_Admin_Settings extends OMGF_Admin
20
  {
21
+ /**
22
+ * Settings Fields
23
+ */
24
  const OMGF_SETTINGS_FIELD_ADVANCED = 'omgf-advanced-settings';
25
+
26
+ /**
27
+ * Option Values
28
+ */
29
  const OMGF_FONT_DISPLAY_OPTIONS = array(
30
  'Auto (default)' => 'auto',
31
  'Block' => 'block',
33
  'Fallback' => 'fallback',
34
  'Optional' => 'optional'
35
  );
36
+
37
+ /**
38
+ * Generate Stylesheet
39
+ */
40
+ const OMGF_SETTING_DB_VERSION = 'omgf_db_version';
41
+ const OMGF_SETTING_AUTO_DETECTION_ENABLED = 'omgf_auto_detection_enabled';
42
+ const OMGF_SETTING_DETECTED_FONTS = 'omgf_detected_fonts';
43
+ const OMGF_SETTING_SUBSETS = 'omgf_subsets';
44
+ const OMGF_SETTING_FONTS = 'omgf_fonts';
45
+
46
+ /**
47
+ * Advanced Settings
48
+ */
49
+ const OMGF_ADV_SETTING_CACHE_PATH = 'omgf_cache_dir';
50
+ const OMGF_ADV_SETTING_CACHE_URI = 'omgf_cache_uri';
51
+ const OMGF_ADV_SETTING_CDN_URL = 'omgf_cdn_url';
52
+ const OMGF_ADV_SETTING_WEB_FONT_LOADER = 'omgf_web_font_loader';
53
+ const OMGF_ADV_SETTING_REMOVE_VERSION = 'omgf_remove_version';
54
+ const OMGF_ADV_SETTING_DISPLAY_OPTION = 'omgf_display_option';
55
+ const OMGF_ADV_SETTING_REMOVE_GOOGLE_FONTS = 'omgf_remove_gfonts';
56
+ const OMGF_ADV_SETTING_ENABLE_PRELOAD = 'omgf_preload';
57
+ const OMGF_ADV_SETTING_UNINSTALL = 'omgf_uninstall';
58
+ const OMGF_ADV_SETTING_ENQUEUE_ORDER = 'omgf_enqueue_order';
59
+ const OMGF_ADV_SETTING_RELATIVE_URL = 'omgf_relative_url';
60
+
61
+ /** @var string $active_tab */
62
+ private $active_tab;
63
 
64
  /**
65
  * OMGF_Admin_Settings constructor.
66
  */
67
  public function __construct()
68
  {
69
+ $this->active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'generate-stylesheet';
 
 
 
70
 
71
+ // @formatter:off
72
+ add_action('admin_menu', [$this, 'create_menu']);
73
+ add_action('omgf_settings_tab', [$this, 'generate_stylesheet_tab'], 1);
74
+ add_action('omgf_settings_tab', [$this, 'advanced_settings_tab'], 2);
75
+ add_action('omgf_settings_content', [$this, 'generate_stylesheet_content'], 1);
76
+ add_action('omgf_settings_content', [$this, 'advanced_settings_content'], 2);
77
+ add_filter('plugin_action_links_' . plugin_basename(OMGF_PLUGIN_FILE), [$this, 'create_settings_link']);
78
  // @formatter:on
79
 
80
  parent::__construct();
106
  public function create_settings_page()
107
  {
108
  if (!current_user_can('manage_options')) {
109
+ wp_die(__("You're not cool enough to access this page.", 'host-webfonts-local'));
110
  }
111
  ?>
112
  <div class="wrap">
117
  </p>
118
 
119
  <div class="settings-column left">
120
+ <h2 class="omgf-nav nav-tab-wrapper">
121
+ <?php do_action('omgf_settings_tab'); ?>
122
+ </h2>
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
+ <?php do_action('omgf_settings_content'); ?>
 
 
 
 
 
 
125
  </div>
126
 
127
  <div class="settings-column right">
150
  }
151
 
152
  /**
153
+ * Get all settings using the constants in this class.
154
  *
155
+ * @return array
156
+ * @throws ReflectionException
157
  */
158
+ public function get_settings()
159
  {
160
+ $reflection = new ReflectionClass($this);
161
+ $constants = $reflection->getConstants();
 
162
 
163
+ return array_filter(
164
+ $constants,
165
+ function ($key) {
166
+ return strpos($key, 'OMGF_ADV_SETTING') !== false;
167
+ },
168
+ ARRAY_FILTER_USE_KEY
169
+ );
170
  }
171
 
172
  /**
173
+ * Add Generate Stylesheet Tab to Settings Screen.
174
+ */
175
+ public function generate_stylesheet_tab()
176
+ {
177
+ $this->generate_tab('generate-stylesheet', 'dashicons-admin-appearance', __('Generate Stylesheet', 'host-webfonts-local'));
178
+ }
179
+
180
+ /**
181
+ * Add Advanced Settings Tab to Settings Screen.
182
+ */
183
+ public function advanced_settings_tab()
184
+ {
185
+ $this->generate_tab('advanced-settings', 'dashicons-admin-settings', __('Advanced Settings', 'host-webfonts-local'));
186
+ }
187
+
188
+ /**
189
+ * @param $id
190
+ * @param null $icon
191
+ * @param null $label
192
+ */
193
+ private function generate_tab($id, $icon = null, $label = null)
194
+ {
195
+ ?>
196
+ <a class="nav-tab dashicons-before <?= $icon; ?> <?= $this->active_tab == $id ? 'nav-tab-active' : ''; ?>" href="<?= $this->generate_tab_link($id);?>">
197
+ <?= $label; ?>
198
+ </a>
199
+ <?php
200
+ }
201
+
202
+ /**
203
+ * @param $tab
204
  *
205
+ * @return string
206
  */
207
+ private function generate_tab_link($tab)
208
  {
209
+ return admin_url("options-general.php?page=optimize-webfonts&tab=$tab");
210
+ }
211
+
212
+ /**
213
+ * Render Generate Stylesheet
214
+ */
215
+ public function generate_stylesheet_content()
216
+ {
217
+ if ($this->active_tab != 'generate-stylesheet') {
218
+ return;
219
  }
220
+ ?>
221
+ <form id="omgf-generate-stylesheet-form" name="omgf-generate-stylesheet-form">
222
+ <?php
223
+ $this->get_template('generate-stylesheet');
224
+ ?>
225
+ </form>
226
+ <?php
227
+ }
228
 
229
+ /**
230
+ * Render Advanced Settings
231
+ */
232
+ public function advanced_settings_content()
233
+ {
234
+ if ($this->active_tab != 'advanced-settings') {
235
+ return;
236
  }
237
+ ?>
238
+ <form id="omgf-advanced-settings-form" name="omgf-settings-form" method="post" action="options.php">
239
+ <?php
240
+ settings_fields(OMGF_Admin_Settings::OMGF_SETTINGS_FIELD_ADVANCED);
241
+ do_settings_sections(OMGF_Admin_Settings::OMGF_SETTINGS_FIELD_ADVANCED);
242
+
243
+ $this->get_template('advanced-settings');
244
+
245
+ do_action('omgf_after_settings_form_settings');
246
 
247
+ submit_button();
248
+ ?>
249
+ </form>
250
+ <?php
251
  }
252
 
253
  /**
254
+ * Adds the 'settings' link to the Plugin overview.
255
  *
256
+ * @return mixed
 
257
  */
258
+ public function create_settings_link($links)
259
  {
260
+ $adminUrl = admin_url() . 'options-general.php?page=optimize-webfonts';
261
+ $settingsLink = "<a href='$adminUrl'>" . __('Settings') . "</a>";
262
+ array_push($links, $settingsLink);
263
 
264
+ return $links;
 
 
 
 
 
 
265
  }
266
  }
includes/class-ajax.php CHANGED
@@ -31,10 +31,9 @@ class OMGF_AJAX
31
  add_action('wp_ajax_omgf_ajax_search_font_subsets', array($this, 'search_font_subsets'));
32
  add_action('wp_ajax_omgf_ajax_enable_auto_detect', [$this, 'enable_auto_detect']);
33
  add_action('wp_ajax_omgf_ajax_search_google_fonts', array($this, 'search_fonts'));
 
34
  add_action('wp_ajax_omgf_ajax_download_fonts', array($this, 'download_fonts'));
35
  add_action('wp_ajax_omgf_ajax_generate_styles', array($this, 'generate_styles'));
36
- add_action('wp_ajax_omgf_ajax_preload_font_style', array($this, 'preload_font_style'));
37
- add_action('wp_ajax_omgf_ajax_refresh_font_style_list', array($this, 'refresh_font_style_list'));
38
  add_action('wp_ajax_omgf_ajax_empty_dir', array($this, 'empty_directory'));
39
  // @formatter:on
40
  }
@@ -138,57 +137,46 @@ class OMGF_AJAX
138
  OMGF_Admin_Notice::set_notice(count($fonts) . ' ' . __('font styles found. Trim the list to your needs and click <strong>Download Fonts</strong>.', 'host-webfonts-local'));
139
  }
140
 
141
- /**
142
- * @return OMGF_AJAX_Download
143
- */
144
- public function download_fonts()
145
- {
146
- return new OMGF_AJAX_Download();
147
- }
148
-
149
- /**
150
- * @return OMGF_AJAX_Generate
151
- */
152
- public function generate_styles()
153
- {
154
- return new OMGF_AJAX_Generate();
155
- }
156
-
157
  /**
158
  * Update options with font styles selected for preloading.
159
  */
160
- public function preload_font_style()
161
  {
162
- $fonts = get_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS);
163
- $preload_styles = $_POST['preload_font_styles'];
 
164
 
165
- foreach ($fonts as &$font) {
166
- if (in_array($font['font_id'], $preload_styles)) {
 
 
 
 
167
  $font['preload'] = 1;
 
 
168
  }
169
  }
170
 
171
- update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $fonts);
172
 
173
- OMGF_Admin_Notice::set_notice(count($preload_styles) . ' ' . __('fonts set to preload. If you haven\'t already, you can now <strong>download</strong> the <strong>fonts</strong>. Otherwise, just (re-)<strong>generate</strong> the <strong>stylesheet</strong>.', 'host-webfonts-local'));
174
  }
175
 
176
  /**
177
- * Refresh font style list after rows have been removed.
178
  */
179
- public function refresh_font_style_list()
180
  {
181
- $fonts = get_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS);
182
-
183
- $current = $_POST['font_styles'];
184
-
185
- $refreshed_list = array_filter($fonts, function ($font_style) use ($current) {
186
- return in_array($font_style['font_id'], $current);
187
- });
188
-
189
- update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $refreshed_list);
190
 
191
- OMGF_Admin_Notice::set_notice(count($fonts) - count($refreshed_list) . ' ' . __('fonts removed from list. If you haven\'t already, you can now <strong>download</strong> the <strong>fonts</strong>. Otherwise, just (re-)<strong>generate</strong> the <strong>stylesheet</strong>.', 'host-webfonts-local'));
 
 
 
 
 
192
  }
193
 
194
  /**
31
  add_action('wp_ajax_omgf_ajax_search_font_subsets', array($this, 'search_font_subsets'));
32
  add_action('wp_ajax_omgf_ajax_enable_auto_detect', [$this, 'enable_auto_detect']);
33
  add_action('wp_ajax_omgf_ajax_search_google_fonts', array($this, 'search_fonts'));
34
+ add_action('wp_ajax_omgf_ajax_process_font_styles_queue', [$this, 'process_font_styles_queue']);
35
  add_action('wp_ajax_omgf_ajax_download_fonts', array($this, 'download_fonts'));
36
  add_action('wp_ajax_omgf_ajax_generate_styles', array($this, 'generate_styles'));
 
 
37
  add_action('wp_ajax_omgf_ajax_empty_dir', array($this, 'empty_directory'));
38
  // @formatter:on
39
  }
137
  OMGF_Admin_Notice::set_notice(count($fonts) . ' ' . __('font styles found. Trim the list to your needs and click <strong>Download Fonts</strong>.', 'host-webfonts-local'));
138
  }
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  /**
141
  * Update options with font styles selected for preloading.
142
  */
143
+ public function process_font_styles_queue()
144
  {
145
+ $current_fonts = get_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS);
146
+ $selected_fonts = $_POST['font_styles'];
147
+ $to_be_preloaded = $_POST['preload_font_styles'];
148
 
149
+ $selected_fonts = array_filter($current_fonts, function ($font_style) use ($selected_fonts) {
150
+ return in_array($font_style['font_id'], $selected_fonts);
151
+ });
152
+
153
+ foreach ($selected_fonts as &$font) {
154
+ if (in_array($font['font_id'], $to_be_preloaded)) {
155
  $font['preload'] = 1;
156
+ } else {
157
+ $font['preload'] = 0;
158
  }
159
  }
160
 
161
+ update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $selected_fonts);
162
 
163
+ OMGF_Admin_Notice::set_notice(count($current_fonts) - count($selected_fonts) . ' ' . __('fonts removed from list and', 'host-webfonts-local') . ' ' . count($to_be_preloaded) . ' ' . __('fonts set to preload. If you haven\'t already, you can now <strong>download</strong> the <strong>fonts</strong>. Otherwise, just (re-)<strong>generate</strong> the <strong>stylesheet</strong>.', 'host-webfonts-local'), false);
164
  }
165
 
166
  /**
167
+ * @return OMGF_AJAX_Download
168
  */
169
+ public function download_fonts()
170
  {
171
+ return new OMGF_AJAX_Download();
172
+ }
 
 
 
 
 
 
 
173
 
174
+ /**
175
+ * @return OMGF_AJAX_Generate
176
+ */
177
+ public function generate_styles()
178
+ {
179
+ return new OMGF_AJAX_Generate();
180
  }
181
 
182
  /**
includes/class-omgf.php CHANGED
@@ -55,20 +55,20 @@ class OMGF
55
  define('OMGF_HELPER_URL', 'https://google-webfonts-helper.herokuapp.com/api/fonts/');
56
  define('OMGF_FILENAME', 'fonts.css');
57
  define('OMGF_AUTO_DETECT_ENABLED', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_AUTO_DETECTION_ENABLED, false)));
58
- define('OMGF_CACHE_PATH', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_CACHE_PATH)) ?: '/cache/omgf-webfonts');
59
- define('OMGF_CACHE_URI', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_CACHE_URI)) ?: '');
60
- define('OMGF_RELATIVE_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_RELATIVE_URL)));
61
- define('OMGF_CDN_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_CDN_URL)));
62
- define('OMGF_WEB_FONT_LOADER', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_WEB_FONT_LOADER)));
63
- define('OMGF_REMOVE_VERSION', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_REMOVE_VERSION)));
64
  define('OMGF_CURRENT_BLOG_ID', get_current_blog_id());
65
  define('OMGF_FONTS_DIR', WP_CONTENT_DIR . OMGF_CACHE_PATH);
66
  define('OMGF_FONTS_URL', $this->get_fonts_url());
67
- define('OMGF_DISPLAY_OPTION', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_DISPLAY_OPTION)) ?: 'auto');
68
- define('OMGF_REMOVE_GFONTS', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_REMOVE_GOOGLE_FONTS)));
69
- define('OMGF_PRELOAD', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_ENABLE_PRELOAD)));
70
- define('OMGF_ENQUEUE_ORDER', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_ENQUEUE_ORDER, 100)));
71
- define('OMGF_UNINSTALL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_UNINSTALL)));
72
  }
73
 
74
  /**
55
  define('OMGF_HELPER_URL', 'https://google-webfonts-helper.herokuapp.com/api/fonts/');
56
  define('OMGF_FILENAME', 'fonts.css');
57
  define('OMGF_AUTO_DETECT_ENABLED', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_AUTO_DETECTION_ENABLED, false)));
58
+ define('OMGF_CACHE_PATH', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH)) ?: '/cache/omgf-webfonts');
59
+ define('OMGF_CACHE_URI', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI)) ?: '');
60
+ define('OMGF_RELATIVE_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL)));
61
+ define('OMGF_CDN_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL)));
62
+ define('OMGF_WEB_FONT_LOADER', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_WEB_FONT_LOADER)));
63
+ define('OMGF_REMOVE_VERSION', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_VERSION)));
64
  define('OMGF_CURRENT_BLOG_ID', get_current_blog_id());
65
  define('OMGF_FONTS_DIR', WP_CONTENT_DIR . OMGF_CACHE_PATH);
66
  define('OMGF_FONTS_URL', $this->get_fonts_url());
67
+ define('OMGF_DISPLAY_OPTION', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_DISPLAY_OPTION)) ?: 'auto');
68
+ define('OMGF_REMOVE_GFONTS', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_GOOGLE_FONTS)));
69
+ define('OMGF_PRELOAD', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_ENABLE_PRELOAD)));
70
+ define('OMGF_ENQUEUE_ORDER', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_ENQUEUE_ORDER, 100)));
71
+ define('OMGF_UNINSTALL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL)));
72
  }
73
 
74
  /**
js/omgf-admin.js CHANGED
@@ -17,118 +17,92 @@ jQuery(document).ready(function ($) {
17
  var omgf_admin = {
18
  // XHR
19
  search_fonts_xhr: false,
20
- preload_font_style_xhr: false,
21
- refresh_font_style_list_xhr: false,
22
  download_fonts_xhr: false,
23
  generate_stylesheet_xhr: false,
24
  empty_cache_directory_xhr: false,
25
 
 
 
 
 
 
26
  // Data
27
  font_families: [],
28
  preload_font_styles: [],
29
  font_style_list: [],
30
 
31
- // Settings screen elements
32
- $nav: $('.omgf-nav span'),
33
- $nav_generate_stylesheet: $('.generate-stylesheet'),
34
- $nav_advanced_settings: $('.advanced-settings'),
35
- $generate_stylesheet_form: $('#omgf-generate-stylesheet-form'),
36
- $advanced_settings_form: $('#omgf-advanced-settings-form'),
37
-
38
  // Selectors
39
  $loader: $('.omgf-loading'),
40
  $font_families: $('.omgf-subset-font-family'),
41
  $subsets: $('.omgf-subset'),
42
- $preload_font_styles: $('.omgf-font-preload'),
43
- $removed_font_style: $('.omgf-font-remove'),
44
 
45
  /**
46
  * Initialize all on click events.
47
  */
48
  init: function () {
49
- // Nav
50
- this.$nav.on('click', this.toggle_section);
 
 
51
 
52
  // Manage queues
53
  this.$subsets.on('click', this.manage_subset_queue);
54
- this.$preload_font_styles.on('click', this.manage_preload_queue);
55
- this.$removed_font_style.on('click', this.manage_removal_queue);
56
 
57
  // Buttons
58
  $('#omgf-search-subsets').on('click', this.click_search);
59
  $('#omgf-auto-detect, .help.auto-detect').on('click', this.enable_auto_detect);
60
  $('.omgf-apply.font-styles-search').on('click', this.search_google_fonts);
61
- $('.omgf-apply.remove').on('click', this.process_removal_queue);
62
- $('.omgf-apply.preload').on('click', this.preload_font_style);
63
  $('#omgf-download, .help.download-fonts').on('click', this.download_fonts);
64
  $('#omgf-generate, .help.generate-stylesheet').on('click', this.generate_stylesheet);
65
  $('#omgf-empty').on('click', this.empty_cache_directory);
66
  },
67
 
68
  /**
69
- * Toggle settings sections.
70
- */
71
- toggle_section: function () {
72
- omgf_admin.$nav.removeClass('selected');
73
- $(this).addClass('selected');
74
-
75
- if (this.classList.contains('generate-stylesheet')) {
76
- omgf_admin.$generate_stylesheet_form.fadeIn();
77
- omgf_admin.$advanced_settings_form.fadeOut(100);
78
- } else {
79
- omgf_admin.$advanced_settings_form.fadeIn();
80
- omgf_admin.$generate_stylesheet_form.fadeOut(100);
81
- }
82
- },
83
-
84
- /**
85
- * If any subsets are checked for search.
86
  */
87
  manage_subset_queue: function () {
88
  section = $('#omgf-subsets');
89
  colspan = section.find("tr:first td").length - 1;
90
  $('.omgf-subsets-search').attr('colspan', colspan);
 
91
 
92
- omgf_admin.toggle_button($('.omgf-subset:checked'), $('.omgf-apply.font-styles-search'), section);
 
 
 
 
93
  },
94
 
95
  /**
96
- * If any fonts are checked for preload, display Preload apply button.
97
  */
98
- manage_preload_queue: function () {
99
- omgf_admin.toggle_button($('.omgf-font-preload:checked'), $('.omgf-apply.preload'), $('#omgf-font-styles-list'));
 
 
 
 
100
  },
101
 
102
  /**
103
- * Enqueue for removal or undo removal of current item.
104
  */
105
- manage_removal_queue: function () {
106
- if (this.classList.contains('notice-dismiss')) {
107
- omgf_admin.enqueue_for_removal(this);
108
- } else {
109
- omgf_admin.undo_removal(this);
110
- }
111
  },
112
 
113
  /**
114
- * @param conditional
115
- * @param button
116
- * @param section
117
  */
118
- toggle_button: function(conditional, button, section) {
119
- help_text = section.find('.omgf-apply.help');
120
- buttons = section.find('.omgf-apply.button');
121
-
122
- if (conditional.length > 0) {
123
- button.show();
124
- } else {
125
- button.hide();
126
- }
127
-
128
- if (buttons.is(':visible')) {
129
- help_text.show();
130
  } else {
131
- help_text.hide();
132
  }
133
  },
134
 
@@ -144,11 +118,11 @@ jQuery(document).ready(function ($) {
144
  'opacity': '0.5'
145
  });
146
 
147
- $(item).addClass('dashicons-before dashicons-undo');
148
- $(item).removeClass('notice-dismiss');
149
  $(row).removeClass('omgf-font-style');
150
 
151
- omgf_admin.toggle_button($('.dashicons-undo'), $('.omgf-apply.remove'), $('#omgf-font-styles-list'));
152
  },
153
 
154
  /**
@@ -163,11 +137,47 @@ jQuery(document).ready(function ($) {
163
  'opacity': '1'
164
  });
165
 
166
- $(item).removeClass('dashicons-before dashicons-undo');
167
- $(item).addClass('notice-dismiss');
168
  $(row).addClass('omgf-font-style');
169
 
170
- omgf_admin.toggle_button($('.dashicons-undo'), $('.omgf-apply.remove'), $('#omgf-font-styles-list'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  },
172
 
173
  /**
@@ -223,6 +233,7 @@ jQuery(document).ready(function ($) {
223
 
224
  /**
225
  * Triggered on Search
 
226
  */
227
  search_google_fonts: function () {
228
  if (omgf_admin.search_fonts_xhr) {
@@ -261,70 +272,34 @@ jQuery(document).ready(function ($) {
261
  },
262
 
263
  /**
264
- * Processes the removal queue.
265
- */
266
- process_removal_queue: function() {
267
- row = '#' + $(this).data('row');
268
-
269
- omgf_admin.show_loader(row);
270
- $(row).removeClass('omgf-font-style');
271
-
272
- setTimeout(omgf_admin.refresh_font_style_list, this.timeout);
273
- },
274
-
275
- /**
276
- * Triggered after remove to sync data to backend.
277
  */
278
- refresh_font_style_list: function () {
279
- if (omgf_admin.refresh_font_style_list_xhr) {
280
- omgf_admin.refresh_font_style_list_xhr.abort();
281
  }
282
 
283
  omgf_admin.font_style_list = $('.omgf-font-style').map(function () {
284
  return $(this).data('font-id');
285
  }).get();
286
 
287
- omgf_admin.refresh_font_style_list_xhr = $.ajax({
288
- type: 'POST',
289
- url: ajaxurl,
290
- data: {
291
- action: 'omgf_ajax_refresh_font_style_list',
292
- font_styles: omgf_admin.font_style_list
293
- },
294
- dataType: 'json',
295
- beforeSend: function() {
296
- omgf_admin.show_loader('#omgf-font-styles-list');
297
- },
298
- success: function() {
299
- location.reload();
300
- }
301
- });
302
- },
303
-
304
- /**
305
- * Triggered when preload is checked. If multiple are checked, all are processed at once.
306
- */
307
- preload_font_style: function() {
308
- if (omgf_admin.preload_font_style_xhr) {
309
- omgf_admin.preload_font_style_xhr.abort();
310
- }
311
-
312
  omgf_admin.preload_font_styles = $('.omgf-font-preload:checked').map(function () {
313
- return $(this).data('preload');
314
  }).get();
315
 
316
- omgf_admin.preload_font_style_xhr = $.ajax({
317
  type: 'POST',
318
  url: ajaxurl,
319
  data: {
320
- action: 'omgf_ajax_preload_font_style',
 
321
  preload_font_styles: omgf_admin.preload_font_styles
322
  },
323
  dataType: 'json',
324
  beforeSend: function() {
325
  omgf_admin.show_loader('#omgf-font-styles-list');
326
  },
327
- success: function () {
328
  location.reload();
329
  }
330
  });
@@ -358,7 +333,11 @@ jQuery(document).ready(function ($) {
358
  * Generate stylesheet and refresh window.
359
  */
360
  generate_stylesheet: function () {
361
- $.ajax({
 
 
 
 
362
  type: 'POST',
363
  url: ajaxurl,
364
  data: {
17
  var omgf_admin = {
18
  // XHR
19
  search_fonts_xhr: false,
20
+ process_font_styles_xhr: false,
 
21
  download_fonts_xhr: false,
22
  generate_stylesheet_xhr: false,
23
  empty_cache_directory_xhr: false,
24
 
25
+ // Saved State
26
+ subsets_state: 0,
27
+ preload_state: 0,
28
+ font_style_state: 0,
29
+
30
  // Data
31
  font_families: [],
32
  preload_font_styles: [],
33
  font_style_list: [],
34
 
 
 
 
 
 
 
 
35
  // Selectors
36
  $loader: $('.omgf-loading'),
37
  $font_families: $('.omgf-subset-font-family'),
38
  $subsets: $('.omgf-subset'),
39
+ $manage_font_styles: $('.omgf-font-preload, .omgf-font-remove'),
 
40
 
41
  /**
42
  * Initialize all on click events.
43
  */
44
  init: function () {
45
+ // Current queue states
46
+ this.subsets_state = $('.omgf-subset:checked').length;
47
+ this.preload_state = $('.omgf-font-preload:checked').length;
48
+ this.font_style_state = $('.omgf-font-style').length;
49
 
50
  // Manage queues
51
  this.$subsets.on('click', this.manage_subset_queue);
52
+ this.$manage_font_styles.on('click', this.manage_font_styles_queues);
 
53
 
54
  // Buttons
55
  $('#omgf-search-subsets').on('click', this.click_search);
56
  $('#omgf-auto-detect, .help.auto-detect').on('click', this.enable_auto_detect);
57
  $('.omgf-apply.font-styles-search').on('click', this.search_google_fonts);
58
+ $('.omgf-apply.font-styles').on('click', this.process_font_styles_queue);
 
59
  $('#omgf-download, .help.download-fonts').on('click', this.download_fonts);
60
  $('#omgf-generate, .help.generate-stylesheet').on('click', this.generate_stylesheet);
61
  $('#omgf-empty').on('click', this.empty_cache_directory);
62
  },
63
 
64
  /**
65
+ * Show apply button, if any changes are made to the list of subsets.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  */
67
  manage_subset_queue: function () {
68
  section = $('#omgf-subsets');
69
  colspan = section.find("tr:first td").length - 1;
70
  $('.omgf-subsets-search').attr('colspan', colspan);
71
+ subset_length = $('.omgf-subset:checked').length;
72
 
73
+ if (subset_length !== omgf_admin.subsets_state) {
74
+ omgf_admin.show_button($('.omgf-apply.font-styles-search'), section);
75
+ } else {
76
+ omgf_admin.hide_button($('.omgf-apply.font-styles-search'), section);
77
+ }
78
  },
79
 
80
  /**
81
+ * Trigger the appropriate queue manager.
82
  */
83
+ manage_font_styles_queues: function () {
84
+ if (this.classList.contains('omgf-font-preload')) {
85
+ omgf_admin.manage_preload_queue();
86
+ } else {
87
+ omgf_admin.manage_removal_queue(this);
88
+ }
89
  },
90
 
91
  /**
92
+ * If any changes are made to the preload queue, display apply button.
93
  */
94
+ manage_preload_queue: function () {
95
+ omgf_admin.toggle_font_styles_apply_button();
 
 
 
 
96
  },
97
 
98
  /**
99
+ * Enqueue for removal or undo removal of current item.
 
 
100
  */
101
+ manage_removal_queue: function (element) {
102
+ if (element.classList.contains('omgf-font-remove')) {
103
+ omgf_admin.enqueue_for_removal(element);
 
 
 
 
 
 
 
 
 
104
  } else {
105
+ omgf_admin.undo_removal(element);
106
  }
107
  },
108
 
118
  'opacity': '0.5'
119
  });
120
 
121
+ $(item).addClass('omgf-font-no-remove dashicons-before dashicons-undo');
122
+ $(item).removeClass('omgf-font-remove notice-dismiss');
123
  $(row).removeClass('omgf-font-style');
124
 
125
+ omgf_admin.toggle_font_styles_apply_button();
126
  },
127
 
128
  /**
137
  'opacity': '1'
138
  });
139
 
140
+ $(item).removeClass('omgf-font-no-remove dashicons-before dashicons-undo');
141
+ $(item).addClass('omgf-font-remove notice-dismiss');
142
  $(row).addClass('omgf-font-style');
143
 
144
+ omgf_admin.toggle_font_styles_apply_button();
145
+ },
146
+
147
+ /**
148
+ *
149
+ */
150
+ toggle_font_styles_apply_button: function () {
151
+ font_style_length = $('.omgf-font-style').length;
152
+ preload_length = $('.omgf-font-preload:checked').length;
153
+
154
+ if (font_style_length !== omgf_admin.font_style_state || preload_length !== omgf_admin.preload_state) {
155
+ omgf_admin.show_button($('.omgf-apply.button.font-styles'), $('#omgf-font-styles-list'));
156
+ } else {
157
+ omgf_admin.hide_button($('.omgf-apply.button.font-styles'), $('#omgf-font-styles-list'));
158
+ }
159
+ },
160
+
161
+ /**
162
+ * @param button
163
+ * @param section
164
+ */
165
+ show_button: function(button, section) {
166
+ help_text = section.find('.omgf-apply.help');
167
+
168
+ button.show();
169
+ help_text.show();
170
+ },
171
+
172
+ /**
173
+ * @param button
174
+ * @param section
175
+ */
176
+ hide_button: function(button, section) {
177
+ help_text = section.find('.omgf-apply.help');
178
+
179
+ button.hide();
180
+ help_text.hide();
181
  },
182
 
183
  /**
233
 
234
  /**
235
  * Triggered on Search
236
+ * TODO: Refactor to more sensible names.
237
  */
238
  search_google_fonts: function () {
239
  if (omgf_admin.search_fonts_xhr) {
272
  },
273
 
274
  /**
275
+ *
 
 
 
 
 
 
 
 
 
 
 
 
276
  */
277
+ process_font_styles_queue: function () {
278
+ if (omgf_admin.process_font_styles_xhr) {
279
+ omgf_admin.process_font_styles_xhr.abort();
280
  }
281
 
282
  omgf_admin.font_style_list = $('.omgf-font-style').map(function () {
283
  return $(this).data('font-id');
284
  }).get();
285
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  omgf_admin.preload_font_styles = $('.omgf-font-preload:checked').map(function () {
287
+ return this.value;
288
  }).get();
289
 
290
+ omgf_admin.process_font_styles_xhr = $.ajax({
291
  type: 'POST',
292
  url: ajaxurl,
293
  data: {
294
+ action: 'omgf_ajax_process_font_styles_queue',
295
+ font_styles: omgf_admin.font_style_list,
296
  preload_font_styles: omgf_admin.preload_font_styles
297
  },
298
  dataType: 'json',
299
  beforeSend: function() {
300
  omgf_admin.show_loader('#omgf-font-styles-list');
301
  },
302
+ success: function() {
303
  location.reload();
304
  }
305
  });
333
  * Generate stylesheet and refresh window.
334
  */
335
  generate_stylesheet: function () {
336
+ if (omgf_admin.generate_stylesheet_xhr) {
337
+ omgf_admin.generate_stylesheet_xhr.abort();
338
+ }
339
+
340
+ omgf_admin.generate_stylesheet_xhr = $.ajax({
341
  type: 'POST',
342
  url: ajaxurl,
343
  data: {
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: DaanvandenBergh
3
  Tags: google, fonts, preload, font-display, webfonts, subsets, remove, minimize, external, requests, leverage, browser, cache
4
  Requires at least: 4.6
5
  Tested up to: 5.4
6
- Stable tag: 3.3.0
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -105,6 +105,12 @@ N/A
105
 
106
  == Changelog ==
107
 
 
 
 
 
 
 
108
  = 3.3.0 =
109
  * Introduced a queueing system for font-styles search, preload and remove for easier management. The 'Apply' buttons now process all your changes at once.
110
  * The 'Apply' buttons are sticky, so they're visible for long lists.
3
  Tags: google, fonts, preload, font-display, webfonts, subsets, remove, minimize, external, requests, leverage, browser, cache
4
  Requires at least: 4.6
5
  Tested up to: 5.4
6
+ Stable tag: 3.3.1
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
105
 
106
  == Changelog ==
107
 
108
+ = 3.3.1 =
109
+ * Use WordPress' tabs system for navigation to comply with Plugin Conventions.
110
+ * Fixed bug which caused preload font styles to be saved incorrectly.
111
+ * Replaced separate apply buttons with one apply button, which handles the entire queue for removal as well as preload at once.
112
+ * Known bug: 'Apply' button isn't clickable when sticky. Available workaround: scroll to the bottom of the list and click 'Apply'.
113
+
114
  = 3.3.0 =
115
  * Introduced a queueing system for font-styles search, preload and remove for easier management. The 'Apply' buttons now process all your changes at once.
116
  * The 'Apply' buttons are sticky, so they're visible for long lists.
templates/admin/block-advanced-settings.phtml CHANGED
@@ -18,25 +18,21 @@ defined('ABSPATH') || exit;
18
 
19
  $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
20
  ?>
21
- <div class="">
22
- <p class="description">
23
- <strong><?= __('Make sure you\'ve saved your settings, before generating the stylesheet!', 'host-webfonts-local'); ?></strong>
24
- </p>
25
- <p class="description">
26
- <?php _e('* <strong>Generate stylesheet</strong> after changing this setting.', 'host-webfonts-local'); ?>
27
- </p>
28
- <p class="description">
29
  <?php _e('** <strong>Download Fonts</strong> and <strong>Generate Stylesheet</strong> after changing this setting.', 'host-webfonts-local'); ?>
30
  </p>
31
  <table class="form-table">
32
  <tr valign="top">
33
  <th scope="row">
34
- <label for="<?= OMGF_Admin_Settings::OMGF_SETTING_REMOVE_GOOGLE_FONTS; ?>">
35
  <?php _e('Remove Google Fonts (experimental)', 'host-webfonts-local'); ?>
36
  </label>
37
  </th>
38
  <td>
39
- <input class="<?= OMGF_Admin_Settings::OMGF_SETTING_REMOVE_GOOGLE_FONTS; ?>" id="<?= OMGF_Admin_Settings::OMGF_SETTING_REMOVE_GOOGLE_FONTS; ?>" type="checkbox" name="<?= OMGF_Admin_Settings::OMGF_SETTING_REMOVE_GOOGLE_FONTS; ?>" <?= OMGF_REMOVE_GFONTS == 'on' ? 'checked = "checked"' : ''; ?> />
40
  <p class="description">
41
  <?= sprintf(__('Enabling this option will attempt to remove any externally hosted Google Fonts-stylesheets from your WordPress-blog. If it doesn\'t work for you, your theme and/or plugin(s) are using unconventional methods (or Web Font Loader) to load Google Fonts. <a href="%s" target="_blank">Hire me</a> for a custom integration or <a href="%s" target="_blank">contact me</a> when in doubt.', 'host-webfonts-local'), 'https://woosh.dev/wordpress-services/omgf-expert-configuration/' . $utmTags, OMGF_SITE_URL . '/contact/' . $utmTags); ?>
42
  </p>
@@ -44,12 +40,12 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
44
  </tr>
45
  <tr valign="top">
46
  <th scope="row">
47
- <label for="<?= OMGF_Admin_Settings::OMGF_SETTING_DISPLAY_OPTION; ?>">
48
  <?php _e('Font-display option', 'host-webfonts-local'); ?> *
49
  </label>
50
  </th>
51
  <td>
52
- <select id="<?= OMGF_Admin_Settings::OMGF_SETTING_DISPLAY_OPTION; ?>" name="<?= OMGF_Admin_Settings::OMGF_SETTING_DISPLAY_OPTION; ?>">
53
  <?php foreach (OMGF_Admin_Settings::OMGF_FONT_DISPLAY_OPTIONS as $label => $value): ?>
54
  <option value="<?= $value; ?>" <?= $value == OMGF_DISPLAY_OPTION ? 'selected' : ''; ?>><?php _e($label, 'host-webfonts-local'); ?></option>
55
  <?php endforeach; ?>
@@ -63,25 +59,25 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
63
  </tr>
64
  <tr valign="top">
65
  <th scope="row">
66
- <label for="<?= OMGF_Admin_Settings::OMGF_SETTING_CACHE_PATH; ?>">
67
  <?php _e('Save font files to...', 'host-webfonts-local'); ?> *
68
  </label>
69
  </th>
70
  <td>
71
- <input id="<?= OMGF_Admin_Settings::OMGF_SETTING_CACHE_PATH; ?>" class="<?= OMGF_Admin_Settings::OMGF_SETTING_CACHE_PATH; ?>" type="text" name="<?= OMGF_Admin_Settings::OMGF_SETTING_CACHE_PATH; ?>" placeholder="<?= __('e.g. /cache/omgf-webfonts', 'host-webfonts-local'); ?>" value="<?= OMGF_CACHE_PATH; ?>"/>
72
  <p class="description">
73
- <?php _e("The folder (inside <code>wp-content</code>) where font files should be stored. Give each site a unique value if you're using Multisite. Defaults to <code>/cache/omgf-webfonts</code>. Folder will be created if it doesn't exist and existing files will be moved automatically.", 'host-webfonts-local'); ?>
74
  </p>
75
  </td>
76
  </tr>
77
  <tr valign="top">
78
  <th scope="row">
79
- <label for="<?= OMGF_Admin_Settings::OMGF_SETTING_CACHE_URI; ?>">
80
  <?php _e('Serve font files from...', 'host-webfonts-local'); ?> *
81
  </label>
82
  </th>
83
  <td>
84
- <input id="<?= OMGF_Admin_Settings::OMGF_SETTING_CACHE_URI; ?>" class="<?= OMGF_Admin_Settings::OMGF_SETTING_CACHE_URI; ?>" type="text" name="<?= OMGF_Admin_Settings::OMGF_SETTING_CACHE_URI; ?>" placeholder="<?= __('e.g. /app/cache/omgf-webfonts', 'host-webfonts-local'); ?>" value="<?= OMGF_CACHE_URI; ?>" />
85
  <p class="description">
86
  <?php _e('The relative path to serve font files from. Useful for when you\'re using security through obscurity plugins, such as WP Hide. If left empty, the cache directory specified above will be used.', 'host-webfonts-local'); ?>
87
  </p>
@@ -89,12 +85,12 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
89
  </tr>
90
  <tr valign="top">
91
  <th scope="row">
92
- <label for="<?= OMGF_Admin_Settings::OMGF_SETTING_RELATIVE_URL; ?>">
93
  <?php _e('Use Relative URLs?', 'host-webfonts-local'); ?> **
94
  </label>
95
  </th>
96
  <td>
97
- <input id="<?= OMGF_Admin_Settings::OMGF_SETTING_RELATIVE_URL; ?>" class="<?= OMGF_Admin_Settings::OMGF_SETTING_RELATIVE_URL; ?>" type="checkbox" name="<?= OMGF_Admin_Settings::OMGF_SETTING_RELATIVE_URL; ?>" <?= OMGF_RELATIVE_URL ? "checked ='checked'" : ''; ?> />
98
  <p class="description">
99
  <?php _e('Use relative instead of absolute (full) URLs to generate the stylesheet. <strong>Warning!</strong> This disables the CDN URL!', 'host-webfonts-local'); ?>
100
  </p>
@@ -102,12 +98,12 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
102
  </tr>
103
  <tr valign="top">
104
  <th scope="row">
105
- <label for="<?= OMGF_Admin_Settings::OMGF_SETTING_CDN_URL; ?>">
106
  <?php _e('Serve fonts from CDN', 'host-webfonts-local'); ?> **
107
  </label>
108
  </th>
109
  <td>
110
- <input id="<?= OMGF_Admin_Settings::OMGF_SETTING_CDN_URL; ?>" class="<?= OMGF_Admin_Settings::OMGF_SETTING_CDN_URL; ?>" type="text" name="<?= OMGF_Admin_Settings::OMGF_SETTING_CDN_URL; ?>" placeholder="<?= __('e.g. cdn.mydomain.com', 'host-webfonts-local'); ?>" value="<?= OMGF_CDN_URL; ?>" <?= OMGF_RELATIVE_URL ? 'disabled' : ''; ?> />
111
  <p class="description">
112
  <?php _e("Are you using a CDN? Then enter the URL here.", 'host-webfonts-local'); ?>
113
  </p>
@@ -115,12 +111,12 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
115
  </tr>
116
  <tr valign="top">
117
  <th scope="row">
118
- <label for="<?= OMGF_Admin_Settings::OMGF_SETTING_WEB_FONT_LOADER; ?>">
119
  <?php _e('Use Web Font Loader?', 'host-webfonts-local'); ?>
120
  </label>
121
  </th>
122
  <td>
123
- <input id="<?= OMGF_Admin_Settings::OMGF_SETTING_WEB_FONT_LOADER; ?>" class="<?= OMGF_Admin_Settings::OMGF_SETTING_WEB_FONT_LOADER; ?>" type="checkbox" name="<?= OMGF_Admin_Settings::OMGF_SETTING_WEB_FONT_LOADER; ?>" <?= OMGF_WEB_FONT_LOADER ? "checked = 'checked'" : ""; ?> />
124
  <p class="description">
125
  <?php _e('Use Typekit\'s Web Font Loader to load fonts asynchronously. <strong>Caution:</strong> while this might raise your Pagespeed Score, it could temporarily cause fonts to be displayed unstyled.', 'host-webfonts-local'); ?>
126
  </p>
@@ -128,12 +124,12 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
128
  </tr>
129
  <tr valign="top">
130
  <th scope="row">
131
- <label for="<?= OMGF_Admin_Settings::OMGF_SETTING_REMOVE_VERSION; ?>">
132
  <?php _e('Remove version parameter?', 'host-webfonts-local'); ?>
133
  </label>
134
  </th>
135
  <td>
136
- <input id="<?= OMGF_Admin_Settings::OMGF_SETTING_REMOVE_VERSION; ?>" class="<?= OMGF_Admin_Settings::OMGF_SETTING_REMOVE_VERSION; ?>" type="checkbox" name="<?= OMGF_Admin_Settings::OMGF_SETTING_REMOVE_VERSION; ?>" <?= OMGF_REMOVE_VERSION ? "checked = 'checked'" : ""; ?> />
137
  <p class="description">
138
  <?php _e('This removes the <code>?ver=x.x.x</code> parameter from the Stylesheet\'s (<code>fonts.css</code>) request. ', 'host-webfonts-local'); ?>
139
  </p>
@@ -141,12 +137,12 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
141
  </tr>
142
  <tr valign="top">
143
  <th scope="row">
144
- <label for="<?= OMGF_Admin_Settings::OMGF_SETTING_ENABLE_PRELOAD; ?>">
145
  <?php _e('Enable preload for stylesheet (experimental)', 'host-webfonts-local'); ?>
146
  </label>
147
  </th>
148
  <td>
149
- <input class="<?= OMGF_Admin_Settings::OMGF_SETTING_ENABLE_PRELOAD; ?>" id="<?= OMGF_Admin_Settings::OMGF_SETTING_ENABLE_PRELOAD; ?>" type="checkbox" name="<?= OMGF_Admin_Settings::OMGF_SETTING_ENABLE_PRELOAD; ?>" <?= OMGF_PRELOAD == 'on' ? 'checked = "checked"' : ''; ?> />
150
  <p class="description">
151
  <?php _e('Leave this disabled if you\'re using a CSS minification plugin, such as Autoptimize or W3 Total Cache, or when using Web Font Loader.', 'host-webfonts-local'); ?>
152
  <a target="_blank" href="https://developers.google.com/web/fundamentals/performance/resource-prioritization#preload"><?php _e('Read more', 'host-webfonts-local'); ?></a>
@@ -155,12 +151,12 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
155
  </tr>
156
  <tr valign="top">
157
  <th scope="row">
158
- <label for="<?= OMGF_Admin_Settings::OMGF_SETTING_ENQUEUE_ORDER; ?>">
159
  <?php _e('Change enqueue order of stylesheet? (experimental)', 'host-webfonts-local'); ?>
160
  </label>
161
  </th>
162
  <td>
163
- <input type="number" name="<?= OMGF_Admin_Settings::OMGF_SETTING_ENQUEUE_ORDER; ?>" id="<?= OMGF_Admin_Settings::OMGF_SETTING_ENQUEUE_ORDER ?>" min="0" value="<?= OMGF_ENQUEUE_ORDER; ?>" />
164
  <p class="description">
165
  <?php _e('Lower this value if the generated stylesheet (<code>fonts.css</code>) is not captured by your CSS minification/combining plugin. Doesn\'t work with Web Font Loader enabled.', 'host-webfonts-local'); ?>
166
  </p>
@@ -168,12 +164,12 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
168
  </tr>
169
  <tr valign="top">
170
  <th scope="row">
171
- <label for="<?= OMGF_Admin_Settings::OMGF_SETTING_UNINSTALL ?>">
172
  <?php _e('Remove settings and files at uninstall?', 'host-webfonts-local'); ?>
173
  </label>
174
  </th>
175
  <td>
176
- <input class="<?= OMGF_Admin_Settings::OMGF_SETTING_UNINSTALL ?>" id="<?= OMGF_Admin_Settings::OMGF_SETTING_UNINSTALL ?>" type="checkbox" name="<?= OMGF_Admin_Settings::OMGF_SETTING_UNINSTALL ?>" <?= OMGF_UNINSTALL == 'on' ? 'checked = "checked"' : '' ?> />
177
  <p class="description">
178
  <?php _e('Warning! This will remove all settings and cached fonts upon plugin deletion.', 'host-webfonts-local'); ?>
179
  </p>
18
 
19
  $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
20
  ?>
21
+ <div>
22
+ <h3><?= __('Advanced Settings', 'host-webfonts-local'); ?></h3>
23
+ <p>
24
+ <?php _e('* <strong>Generate stylesheet</strong> after changing this setting.', 'host-webfonts-local'); ?><br />
 
 
 
 
25
  <?php _e('** <strong>Download Fonts</strong> and <strong>Generate Stylesheet</strong> after changing this setting.', 'host-webfonts-local'); ?>
26
  </p>
27
  <table class="form-table">
28
  <tr valign="top">
29
  <th scope="row">
30
+ <label for="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_GOOGLE_FONTS; ?>">
31
  <?php _e('Remove Google Fonts (experimental)', 'host-webfonts-local'); ?>
32
  </label>
33
  </th>
34
  <td>
35
+ <input class="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_GOOGLE_FONTS; ?>" id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_GOOGLE_FONTS; ?>" type="checkbox" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_GOOGLE_FONTS; ?>" <?= OMGF_REMOVE_GFONTS == 'on' ? 'checked = "checked"' : ''; ?> />
36
  <p class="description">
37
  <?= sprintf(__('Enabling this option will attempt to remove any externally hosted Google Fonts-stylesheets from your WordPress-blog. If it doesn\'t work for you, your theme and/or plugin(s) are using unconventional methods (or Web Font Loader) to load Google Fonts. <a href="%s" target="_blank">Hire me</a> for a custom integration or <a href="%s" target="_blank">contact me</a> when in doubt.', 'host-webfonts-local'), 'https://woosh.dev/wordpress-services/omgf-expert-configuration/' . $utmTags, OMGF_SITE_URL . '/contact/' . $utmTags); ?>
38
  </p>
40
  </tr>
41
  <tr valign="top">
42
  <th scope="row">
43
+ <label for="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_DISPLAY_OPTION; ?>">
44
  <?php _e('Font-display option', 'host-webfonts-local'); ?> *
45
  </label>
46
  </th>
47
  <td>
48
+ <select id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_DISPLAY_OPTION; ?>" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_DISPLAY_OPTION; ?>">
49
  <?php foreach (OMGF_Admin_Settings::OMGF_FONT_DISPLAY_OPTIONS as $label => $value): ?>
50
  <option value="<?= $value; ?>" <?= $value == OMGF_DISPLAY_OPTION ? 'selected' : ''; ?>><?php _e($label, 'host-webfonts-local'); ?></option>
51
  <?php endforeach; ?>
59
  </tr>
60
  <tr valign="top">
61
  <th scope="row">
62
+ <label for="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH; ?>">
63
  <?php _e('Save font files to...', 'host-webfonts-local'); ?> *
64
  </label>
65
  </th>
66
  <td>
67
+ <input id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH; ?>" class="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH; ?>" type="text" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH; ?>" placeholder="<?= __('e.g. /cache/omgf-webfonts', 'host-webfonts-local'); ?>" value="<?= OMGF_CACHE_PATH; ?>"/>
68
  <p class="description">
69
+ <?php _e("The folder (inside <code>wp-content</code>) where font files should be stored. Give each site a unique value if you're using Multisite. Defaults to <code>/cache/omgf-webfonts</code>. After changing this setting, the folder will be created if it doesn't exist and existing files will be moved automatically.", 'host-webfonts-local'); ?>
70
  </p>
71
  </td>
72
  </tr>
73
  <tr valign="top">
74
  <th scope="row">
75
+ <label for="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI; ?>">
76
  <?php _e('Serve font files from...', 'host-webfonts-local'); ?> *
77
  </label>
78
  </th>
79
  <td>
80
+ <input id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI; ?>" class="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI; ?>" type="text" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI; ?>" placeholder="<?= __('e.g. /app/cache/omgf-webfonts', 'host-webfonts-local'); ?>" value="<?= OMGF_CACHE_URI; ?>" />
81
  <p class="description">
82
  <?php _e('The relative path to serve font files from. Useful for when you\'re using security through obscurity plugins, such as WP Hide. If left empty, the cache directory specified above will be used.', 'host-webfonts-local'); ?>
83
  </p>
85
  </tr>
86
  <tr valign="top">
87
  <th scope="row">
88
+ <label for="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL; ?>">
89
  <?php _e('Use Relative URLs?', 'host-webfonts-local'); ?> **
90
  </label>
91
  </th>
92
  <td>
93
+ <input id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL; ?>" class="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL; ?>" type="checkbox" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL; ?>" <?= OMGF_RELATIVE_URL ? "checked ='checked'" : ''; ?> />
94
  <p class="description">
95
  <?php _e('Use relative instead of absolute (full) URLs to generate the stylesheet. <strong>Warning!</strong> This disables the CDN URL!', 'host-webfonts-local'); ?>
96
  </p>
98
  </tr>
99
  <tr valign="top">
100
  <th scope="row">
101
+ <label for="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL; ?>">
102
  <?php _e('Serve fonts from CDN', 'host-webfonts-local'); ?> **
103
  </label>
104
  </th>
105
  <td>
106
+ <input id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL; ?>" class="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL; ?>" type="text" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL; ?>" placeholder="<?= __('e.g. cdn.mydomain.com', 'host-webfonts-local'); ?>" value="<?= OMGF_CDN_URL; ?>" <?= OMGF_RELATIVE_URL ? 'disabled' : ''; ?> />
107
  <p class="description">
108
  <?php _e("Are you using a CDN? Then enter the URL here.", 'host-webfonts-local'); ?>
109
  </p>
111
  </tr>
112
  <tr valign="top">
113
  <th scope="row">
114
+ <label for="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_WEB_FONT_LOADER; ?>">
115
  <?php _e('Use Web Font Loader?', 'host-webfonts-local'); ?>
116
  </label>
117
  </th>
118
  <td>
119
+ <input id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_WEB_FONT_LOADER; ?>" class="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_WEB_FONT_LOADER; ?>" type="checkbox" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_WEB_FONT_LOADER; ?>" <?= OMGF_WEB_FONT_LOADER ? "checked = 'checked'" : ""; ?> />
120
  <p class="description">
121
  <?php _e('Use Typekit\'s Web Font Loader to load fonts asynchronously. <strong>Caution:</strong> while this might raise your Pagespeed Score, it could temporarily cause fonts to be displayed unstyled.', 'host-webfonts-local'); ?>
122
  </p>
124
  </tr>
125
  <tr valign="top">
126
  <th scope="row">
127
+ <label for="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_VERSION; ?>">
128
  <?php _e('Remove version parameter?', 'host-webfonts-local'); ?>
129
  </label>
130
  </th>
131
  <td>
132
+ <input id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_VERSION; ?>" class="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_VERSION; ?>" type="checkbox" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_VERSION; ?>" <?= OMGF_REMOVE_VERSION ? "checked = 'checked'" : ""; ?> />
133
  <p class="description">
134
  <?php _e('This removes the <code>?ver=x.x.x</code> parameter from the Stylesheet\'s (<code>fonts.css</code>) request. ', 'host-webfonts-local'); ?>
135
  </p>
137
  </tr>
138
  <tr valign="top">
139
  <th scope="row">
140
+ <label for="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_ENABLE_PRELOAD; ?>">
141
  <?php _e('Enable preload for stylesheet (experimental)', 'host-webfonts-local'); ?>
142
  </label>
143
  </th>
144
  <td>
145
+ <input class="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_ENABLE_PRELOAD; ?>" id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_ENABLE_PRELOAD; ?>" type="checkbox" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_ENABLE_PRELOAD; ?>" <?= OMGF_PRELOAD == 'on' ? 'checked = "checked"' : ''; ?> />
146
  <p class="description">
147
  <?php _e('Leave this disabled if you\'re using a CSS minification plugin, such as Autoptimize or W3 Total Cache, or when using Web Font Loader.', 'host-webfonts-local'); ?>
148
  <a target="_blank" href="https://developers.google.com/web/fundamentals/performance/resource-prioritization#preload"><?php _e('Read more', 'host-webfonts-local'); ?></a>
151
  </tr>
152
  <tr valign="top">
153
  <th scope="row">
154
+ <label for="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_ENQUEUE_ORDER; ?>">
155
  <?php _e('Change enqueue order of stylesheet? (experimental)', 'host-webfonts-local'); ?>
156
  </label>
157
  </th>
158
  <td>
159
+ <input type="number" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_ENQUEUE_ORDER; ?>" id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_ENQUEUE_ORDER ?>" min="0" value="<?= OMGF_ENQUEUE_ORDER; ?>" />
160
  <p class="description">
161
  <?php _e('Lower this value if the generated stylesheet (<code>fonts.css</code>) is not captured by your CSS minification/combining plugin. Doesn\'t work with Web Font Loader enabled.', 'host-webfonts-local'); ?>
162
  </p>
164
  </tr>
165
  <tr valign="top">
166
  <th scope="row">
167
+ <label for="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL ?>">
168
  <?php _e('Remove settings and files at uninstall?', 'host-webfonts-local'); ?>
169
  </label>
170
  </th>
171
  <td>
172
+ <input class="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL ?>" id="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL ?>" type="checkbox" name="<?= OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL ?>" <?= OMGF_UNINSTALL == 'on' ? 'checked = "checked"' : '' ?> />
173
  <p class="description">
174
  <?php _e('Warning! This will remove all settings and cached fonts upon plugin deletion.', 'host-webfonts-local'); ?>
175
  </p>
templates/admin/block-generate-stylesheet.phtml CHANGED
@@ -20,10 +20,11 @@ $db = new OMGF_DB();
20
  $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
21
  ?>
22
  <div class="omgf-generate-stylesheet">
23
- <p class="description">
 
24
  <?= __('<strong>Search</strong> returns all available subsets and font styles for each font family. <strong>Auto Detect</strong> only returns subsets and font styles that\'re used by your installed theme and plugins.', 'host-webfonts-local'); ?>
25
  </p>
26
- <p class="description">
27
  <?= __('You can <strong>Search</strong> by either using a comma separated list (e.g. Open Sans, Poppins, Roboto) or by searching for each font family one by one.', 'host-webfonts-local'); ?>
28
  </p>
29
  <div class="omgf-search-section">
@@ -49,8 +50,8 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
49
  <?php foreach ($subsetFont['available_subsets'] as $availableSubset): ?>
50
  <td>
51
  <label>
52
- <?php $checked = in_array($availableSubset, $subsetFont['selected_subsets']) ? 'checked="checked"' : ''; ?>
53
- <input class="omgf-subset" data-subset-font-family="<?= $subsetFont['subset_font']; ?>" value="<?= $availableSubset; ?>" type="checkbox" <?= $checked; ?> />
54
  <?= $availableSubset; ?>
55
  </label>
56
  </td>
@@ -106,7 +107,7 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
106
  <input style="width: 100px;" readonly type="text" value="<?= $font['font_weight']; ?>" />
107
  </td>
108
  <td align="center" style="width: 45px;">
109
- <input type="checkbox" class="omgf-font-preload" data-preload="<?= $fontId; ?>" value="1" <?= $font['preload'] == 1 ? 'checked' : ''; ?> />
110
  </td>
111
  <td style="width: 45px;">
112
  <input type="hidden" value="<?= $fontId; ?>" />
@@ -120,10 +121,13 @@ $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
120
  </tr>
121
  <?php endforeach; ?>
122
  <!-- The navbar at the bottom of the table. -->
123
- <tr id="font-styles-nav" class="sticky bottom" align="right">
124
- <td align="right" colspan="3"><span class="omgf-apply help font-styles" style="display: none;"><strong><?= __('Apply Changes', 'host-webfonts-local'); ?></strong></span></td>
125
- <td align="center" style="width: 45px"><a class="button-primary omgf-apply button preload" href="#" style="display: none;"><span class="dashicons-before dashicons-yes">&nbsp;</span></a></td>
126
- <td align="left" style="width: 45px;"><a class="button-primary omgf-apply button remove" href="#" style="display: none;'"><span class="dashicons-before dashicons-yes">&nbsp;</span></a></td>
 
 
 
127
  </tr>
128
  <tr>
129
  <td colspan="5">
20
  $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
21
  ?>
22
  <div class="omgf-generate-stylesheet">
23
+ <h3><?= __('Generate Stylesheet', 'host-webfonts-local'); ?></h3>
24
+ <p>
25
  <?= __('<strong>Search</strong> returns all available subsets and font styles for each font family. <strong>Auto Detect</strong> only returns subsets and font styles that\'re used by your installed theme and plugins.', 'host-webfonts-local'); ?>
26
  </p>
27
+ <p>
28
  <?= __('You can <strong>Search</strong> by either using a comma separated list (e.g. Open Sans, Poppins, Roboto) or by searching for each font family one by one.', 'host-webfonts-local'); ?>
29
  </p>
30
  <div class="omgf-search-section">
50
  <?php foreach ($subsetFont['available_subsets'] as $availableSubset): ?>
51
  <td>
52
  <label>
53
+ <?php $checked = in_array($availableSubset, $subsetFont['selected_subsets']) ? 'checked' : ''; ?>
54
+ <input class="omgf-subset" data-subset-font-family="<?= $subsetFont['subset_font']; ?>" autocomplete="off" value="<?= $availableSubset; ?>" type="checkbox" <?= $checked; ?> />
55
  <?= $availableSubset; ?>
56
  </label>
57
  </td>
107
  <input style="width: 100px;" readonly type="text" value="<?= $font['font_weight']; ?>" />
108
  </td>
109
  <td align="center" style="width: 45px;">
110
+ <input type="checkbox" class="omgf-font-preload" autocomplete="off" value="<?= $fontId; ?>" <?= $font['preload'] == 1 ? 'checked' : ''; ?> />
111
  </td>
112
  <td style="width: 45px;">
113
  <input type="hidden" value="<?= $fontId; ?>" />
121
  </tr>
122
  <?php endforeach; ?>
123
  <!-- The navbar at the bottom of the table. -->
124
+ <tr id="font-styles-nav" class="sticky bottom">
125
+ <td colspan="3" align="right">
126
+ <span class="omgf-apply help font-styles" style="display: none;"><strong><?= __('Apply Changes', 'host-webfonts-local'); ?></strong></span>
127
+ </td>
128
+ <td colspan="2" style="width: 100px">
129
+ <a class="button-primary omgf-apply button font-styles" href="#" style="display: none;"><span class="dashicons-before dashicons-yes"></span> <?= __('Apply', 'host-webfonts-local'); ?></a>
130
+ </td>
131
  </tr>
132
  <tr>
133
  <td colspan="5">