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

Version Description

| September 30th, 2020 = * OMGF now runs fully automatic to replace/remove Google Fonts from your pages using OMGF's new Download API. No initial configuration required! * This means that if you use different fonts on different pages, all of them will be cached and served locally. * HUGE performance increase in OMGF's automatic replacing/removing methods. * Major overhaul of Settings Page: * Removed Extensions Tab * Some settings were moved to a new tab: Basic Settings. * Improved Welcome and Documentation tab. * Clarified option descriptions. * Removed 'Generate Stylesheet' tab, which'll be released in a separate (free) add-on plugin soon. * Removed 'Use Web Font Loader?' option, because it causes Cumulative Layout Shift and will not work with OMGF's new Auto Replace feature. * Removed 'Remove Version Parameter' option, because it has become obsolete. The new detection method uses the initial script's version, if set. * Font Preloading is temporarily removed and will be re-introduced (in a different form, along with new features) in a later release.

Download this release

Release Info

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

Code changes from version 3.8.2 to 4.0.0

assets/css/omgf-admin.css CHANGED
@@ -12,6 +12,25 @@
12
  * @copyright: (c) 2020 Daan van den Bergh
13
  * @url : https://daan.dev
14
  * * * * * * * * * * * * * * * * * * * */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  /**
16
  * Navigation
17
  */
@@ -42,107 +61,24 @@
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: 666px;
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
12
  * @copyright: (c) 2020 Daan van den Bergh
13
  * @url : https://daan.dev
14
  * * * * * * * * * * * * * * * * * * * */
15
+ /**
16
+ * General
17
+ */
18
+ .omgf .button-cancel {
19
+ color: #a00;
20
+ text-decoration: none;
21
+ border-color: transparent;
22
+ box-shadow: none;
23
+ background: 0 0;
24
+ border-radius: 3px;
25
+ white-space: nowrap;
26
+ padding: 1px 10px !important;
27
+ }
28
+ .omgf .button-cancel:hover {
29
+ cursor: pointer;
30
+ background: #d54e21;
31
+ color: #fff;
32
+ border-color: #d54e21;
33
+ }
34
  /**
35
  * Navigation
36
  */
61
  #omgf-welcome-panel {
62
  padding: 20px 10px 5px;
63
  }
64
+ #omgf-welcome-panel .welcome-panel-content {
65
+ margin-left: 0;
66
+ padding: 0 15px;
67
  }
68
+ #omgf-welcome-panel h3 > .dashicons {
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  line-height: 1.4;
 
 
 
 
 
 
 
70
  }
71
+ #omgf-welcome-panel .dashicons.ffwp-heart:before {
72
+ color: #FF4136;
73
  }
74
+ #omgf-welcome-panel .welcome-icon:before {
75
+ padding: 0;
 
 
76
  }
77
+ #omgf-welcome-panel .signature {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  text-align: center;
79
  }
80
+ #omgf-welcome-panel .signature-image {
81
+ max-width: 90%;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  }
83
  /**
84
  * Responsiveness
assets/css/omgf-admin.css.map CHANGED
@@ -1 +1 @@
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"}
1
+ {"version":3,"sources":["omgf-admin.less"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAkBA,KACE;EACE,WAAA;EACA,qBAAA;EACA,yBAAA;EACA,gBAAA;EACA,eAAA;EACA,kBAAA;EACA,mBAAA;EACA,4BAAA;;AAEA,KAVF,eAUG;EACC,eAAA;EACA,mBAAA;EACA,WAAA;EACA,qBAAA;;;;;AAQN;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;EACE,cAAA;EACA,eAAA;;AALJ,mBAQE,GAAG;EACD,gBAAA;;AAIA,mBADF,WACG,WAAW;EACV,cAAA;;AAdN,mBAkBE,cAAa;EACX,UAAA;;AAnBJ,mBAsBE;EACE,kBAAA;;AAvBJ,mBA0BE;EACE,cAAA;;;;;AAOJ,wBAA2C;EACzC;IACE,cAAA;IACA,WAAA;;EAEA,gBAAC;EACD,gBAAC;IACC,WAAA","file":"omgf-admin.css"}
assets/css/omgf-admin.less CHANGED
@@ -13,6 +13,29 @@
13
  * @url : https://daan.dev
14
  * * * * * * * * * * * * * * * * * * * */
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  /**
17
  * Navigation
18
  */
@@ -50,138 +73,31 @@
50
  #omgf-welcome-panel {
51
  padding: 20px 10px 5px;
52
 
53
- h3 > .dashicons {
54
- line-height: 1.4;
55
- }
56
- }
57
-
58
- /**
59
- * Generate Stylesheet-form
60
- */
61
- .omgf-generate-stylesheet {
62
- table {
63
- margin-top: .66em;
64
  }
65
 
66
- .omgf-search-section {
67
- max-width: 666px;
68
- margin-top: 1em;
69
-
70
- a {
71
- &.omgf-apply {
72
- &.button {
73
- width: 85px;
74
- }
75
-
76
- span:before {
77
- line-height: 1.4;
78
- width: 16px;
79
- }
80
- }
81
- }
82
-
83
- caption {
84
- text-align: left;
85
- font-size: 1.2em;
86
- font-weight: 600;
87
- margin: 0.66em 0 0.33em;
88
- }
89
-
90
- span {
91
- &.omgf-apply {
92
- &.font-styles-search {
93
- width: 75%;
94
- }
95
- }
96
- }
97
-
98
- #omgf-search {
99
- line-height: 38px;
100
- width: 360px;
101
- padding: 3px 10px;
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;
110
- display: inline-block;
111
-
112
- &:before {
113
- position: absolute;
114
- left: 0;
115
- }
116
- }
117
-
118
- #font-styles-nav {
119
- &.sticky {
120
- background: #f1f1f1;
121
- box-shadow: 0 1px 1px rgba(0,0,0,0.04);
122
- width: 565px;
123
- }
124
- }
125
- }
126
  }
127
 
128
- #omgf-control-panel {
129
- margin-top: 1em;
130
-
131
- .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
- &:hover {
142
- cursor: pointer;
143
- background: #d54e21;
144
- color: #fff;
145
- border-color: #d54e21;
146
- }
147
  }
148
  }
149
- }
150
 
151
- /**
152
- * Loader
153
- */
154
- .omgf-loading {
155
- position: absolute;
156
- width: 100%;
157
- height: 100%;
158
- left: 0;
159
- right: 0;
160
- top: 0;
161
- text-align: center;
162
-
163
- .spinner {
164
- top: 50%;
165
- left: 50%;
166
- position: absolute;
167
- -ms-transform: translate(0, -70%);
168
- transform: translate(0, -70%);
169
  }
170
- }
171
-
172
- /**
173
- * Sticky elements.
174
- */
175
- .sticky {
176
- position: -webkit-sticky;
177
- position: sticky;
178
 
179
- &.top {
180
- top: 25px;
181
  }
182
 
183
- &.bottom {
184
- bottom: 0;
185
  }
186
  }
187
 
13
  * @url : https://daan.dev
14
  * * * * * * * * * * * * * * * * * * * */
15
 
16
+ /**
17
+ * General
18
+ */
19
+ .omgf {
20
+ .button-cancel {
21
+ color: #a00;
22
+ text-decoration: none;
23
+ border-color: transparent;
24
+ box-shadow: none;
25
+ background: 0 0;
26
+ border-radius: 3px;
27
+ white-space: nowrap;
28
+ padding: 1px 10px !important;
29
+
30
+ &:hover {
31
+ cursor: pointer;
32
+ background: #d54e21;
33
+ color: #fff;
34
+ border-color: #d54e21;
35
+ }
36
+ }
37
+ }
38
+
39
  /**
40
  * Navigation
41
  */
73
  #omgf-welcome-panel {
74
  padding: 20px 10px 5px;
75
 
76
+ .welcome-panel-content {
77
+ margin-left: 0;
78
+ padding: 0 15px;
 
 
 
 
 
 
 
 
79
  }
80
 
81
+ h3 > .dashicons {
82
+ line-height: 1.4;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  }
84
 
85
+ .dashicons {
86
+ &.ffwp-heart:before {
87
+ color: #FF4136;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  }
89
  }
 
90
 
91
+ .welcome-icon:before {
92
+ padding: 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  }
 
 
 
 
 
 
 
 
94
 
95
+ .signature {
96
+ text-align: center;
97
  }
98
 
99
+ .signature-image {
100
+ max-width: 90%;
101
  }
102
  }
103
 
assets/css/omgf-admin.min.css CHANGED
@@ -1 +1 @@
1
- .omgf-nav{padding:1em 0 1.5em}.omgf-nav a{cursor:pointer}.omgf-nav .dashicons-before:before{margin-right:.25em;line-height:1.15em}.settings-column.left{float:left;width:66%}.settings-column.right{float:right;width:21.75%}#omgf-welcome-panel{padding:20px 10px 5px}#omgf-welcome-panel h3>.dashicons{line-height:1.4}.omgf-generate-stylesheet table{margin-top:.66em}.omgf-generate-stylesheet .omgf-search-section{max-width:666px;margin-top:1em}.omgf-generate-stylesheet .omgf-search-section a.omgf-apply.button{width:85px}.omgf-generate-stylesheet .omgf-search-section a.omgf-apply span:before{line-height:1.4;width:16px}.omgf-generate-stylesheet .omgf-search-section caption{text-align:left;font-size:1.2em;font-weight:600;margin:.66em 0 .33em}.omgf-generate-stylesheet .omgf-search-section span.omgf-apply.font-styles-search{width:75%}.omgf-generate-stylesheet .omgf-search-section #omgf-search{line-height:38px;width:360px;padding:3px 10px}.omgf-generate-stylesheet .omgf-search-section #omgf-font-styles .omgf-font-remove,.omgf-generate-stylesheet .omgf-search-section #omgf-font-styles .omgf-font-no-remove{cursor:pointer;padding:0 0 0 20px;position:relative;display:inline-block}.omgf-generate-stylesheet .omgf-search-section #omgf-font-styles .omgf-font-remove:before,.omgf-generate-stylesheet .omgf-search-section #omgf-font-styles .omgf-font-no-remove:before{position:absolute;left:0}.omgf-generate-stylesheet .omgf-search-section #omgf-font-styles #font-styles-nav.sticky{background:#f1f1f1;box-shadow:0 1px 1px rgba(0,0,0,0.04);width:565px}.omgf-generate-stylesheet #omgf-control-panel{margin-top:1em}.omgf-generate-stylesheet #omgf-control-panel .button-cancel{color:#a00;text-decoration:none;border-color:transparent;box-shadow:none;background:0;border-radius:3px;white-space:nowrap;padding:1px 10px !important}.omgf-generate-stylesheet #omgf-control-panel .button-cancel:hover{cursor:pointer;background:#d54e21;color:#fff;border-color:#d54e21}.omgf-loading{position:absolute;width:100%;height:100%;left:0;right:0;top:0;text-align:center}.omgf-loading .spinner{top:50%;left:50%;position:absolute;-ms-transform:translate(0,-70%);transform:translate(0,-70%)}.sticky{position:-webkit-sticky;position:sticky}.sticky.top{top:25px}.sticky.bottom{bottom:0}@media only screen and (max-width:1024px){.settings-column{display:block;float:none}.settings-column.left,.settings-column.right{width:100%}}
1
+ .omgf .button-cancel{color:#a00;text-decoration:none;border-color:transparent;box-shadow:none;background:0 0;border-radius:3px;white-space:nowrap;padding:1px 10px!important}.omgf .button-cancel:hover{cursor:pointer;background:#d54e21;color:#fff;border-color:#d54e21}.omgf-nav{padding:1em 0 1.5em}.omgf-nav a{cursor:pointer}.omgf-nav .dashicons-before:before{margin-right:.25em;line-height:1.15em}.settings-column.left{float:left;width:66%}.settings-column.right{float:right;width:21.75%}#omgf-welcome-panel{padding:20px 10px 5px}#omgf-welcome-panel .welcome-panel-content{margin-left:0;padding:0 15px}#omgf-welcome-panel h3>.dashicons{line-height:1.4}#omgf-welcome-panel .dashicons.ffwp-heart:before{color:#ff4136}#omgf-welcome-panel .welcome-icon:before{padding:0}#omgf-welcome-panel .signature{text-align:center}#omgf-welcome-panel .signature-image{max-width:90%}@media only screen and (max-width:1024px){.settings-column{display:block;float:none}.settings-column.left,.settings-column.right{width:100%}}
assets/js/libraries/webfont.js DELETED
@@ -1,33 +0,0 @@
1
- /*
2
- * Copyright 2016 Small Batch, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
- * use this file except in compliance with the License. You may obtain a copy of
6
- * the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
- * License for the specific language governing permissions and limitations under
14
- * the License.
15
- */
16
- /* Web Font Loader v1.6.26 - (c) Adobe Systems, Google. License: Apache 2.0 */(function(){function aa(a,b,c){return a.call.apply(a.bind,arguments)}function ba(a,b,c){if(!a)throw Error();if(2<arguments.length){var d=Array.prototype.slice.call(arguments,2);return function(){var c=Array.prototype.slice.call(arguments);Array.prototype.unshift.apply(c,d);return a.apply(b,c)}}return function(){return a.apply(b,arguments)}}function p(a,b,c){p=Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf("native code")?aa:ba;return p.apply(null,arguments)}var q=Date.now||function(){return+new Date};function ca(a,b){this.a=a;this.m=b||a;this.c=this.m.document}var da=!!window.FontFace;function t(a,b,c,d){b=a.c.createElement(b);if(c)for(var e in c)c.hasOwnProperty(e)&&("style"==e?b.style.cssText=c[e]:b.setAttribute(e,c[e]));d&&b.appendChild(a.c.createTextNode(d));return b}function u(a,b,c){a=a.c.getElementsByTagName(b)[0];a||(a=document.documentElement);a.insertBefore(c,a.lastChild)}function v(a){a.parentNode&&a.parentNode.removeChild(a)}
17
- function w(a,b,c){b=b||[];c=c||[];for(var d=a.className.split(/\s+/),e=0;e<b.length;e+=1){for(var f=!1,g=0;g<d.length;g+=1)if(b[e]===d[g]){f=!0;break}f||d.push(b[e])}b=[];for(e=0;e<d.length;e+=1){f=!1;for(g=0;g<c.length;g+=1)if(d[e]===c[g]){f=!0;break}f||b.push(d[e])}a.className=b.join(" ").replace(/\s+/g," ").replace(/^\s+|\s+$/,"")}function y(a,b){for(var c=a.className.split(/\s+/),d=0,e=c.length;d<e;d++)if(c[d]==b)return!0;return!1}
18
- function z(a){if("string"===typeof a.f)return a.f;var b=a.m.location.protocol;"about:"==b&&(b=a.a.location.protocol);return"https:"==b?"https:":"http:"}function ea(a){return a.m.location.hostname||a.a.location.hostname}
19
- function A(a,b,c){function d(){k&&e&&f&&(k(g),k=null)}b=t(a,"link",{rel:"stylesheet",href:b,media:"all"});var e=!1,f=!0,g=null,k=c||null;da?(b.onload=function(){e=!0;d()},b.onerror=function(){e=!0;g=Error("Stylesheet failed to load");d()}):setTimeout(function(){e=!0;d()},0);u(a,"head",b)}
20
- function B(a,b,c,d){var e=a.c.getElementsByTagName("head")[0];if(e){var f=t(a,"script",{src:b}),g=!1;f.onload=f.onreadystatechange=function(){g||this.readyState&&"loaded"!=this.readyState&&"complete"!=this.readyState||(g=!0,c&&c(null),f.onload=f.onreadystatechange=null,"HEAD"==f.parentNode.tagName&&e.removeChild(f))};e.appendChild(f);setTimeout(function(){g||(g=!0,c&&c(Error("Script load timeout")))},d||5E3);return f}return null};function C(){this.a=0;this.c=null}function D(a){a.a++;return function(){a.a--;E(a)}}function F(a,b){a.c=b;E(a)}function E(a){0==a.a&&a.c&&(a.c(),a.c=null)};function G(a){this.a=a||"-"}G.prototype.c=function(a){for(var b=[],c=0;c<arguments.length;c++)b.push(arguments[c].replace(/[\W_]+/g,"").toLowerCase());return b.join(this.a)};function H(a,b){this.c=a;this.f=4;this.a="n";var c=(b||"n4").match(/^([nio])([1-9])$/i);c&&(this.a=c[1],this.f=parseInt(c[2],10))}function fa(a){return I(a)+" "+(a.f+"00")+" 300px "+J(a.c)}function J(a){var b=[];a=a.split(/,\s*/);for(var c=0;c<a.length;c++){var d=a[c].replace(/['"]/g,"");-1!=d.indexOf(" ")||/^\d/.test(d)?b.push("'"+d+"'"):b.push(d)}return b.join(",")}function K(a){return a.a+a.f}function I(a){var b="normal";"o"===a.a?b="oblique":"i"===a.a&&(b="italic");return b}
21
- function ga(a){var b=4,c="n",d=null;a&&((d=a.match(/(normal|oblique|italic)/i))&&d[1]&&(c=d[1].substr(0,1).toLowerCase()),(d=a.match(/([1-9]00|normal|bold)/i))&&d[1]&&(/bold/i.test(d[1])?b=7:/[1-9]00/.test(d[1])&&(b=parseInt(d[1].substr(0,1),10))));return c+b};function ha(a,b){this.c=a;this.f=a.m.document.documentElement;this.h=b;this.a=new G("-");this.j=!1!==b.events;this.g=!1!==b.classes}function ia(a){a.g&&w(a.f,[a.a.c("wf","loading")]);L(a,"loading")}function M(a){if(a.g){var b=y(a.f,a.a.c("wf","active")),c=[],d=[a.a.c("wf","loading")];b||c.push(a.a.c("wf","inactive"));w(a.f,c,d)}L(a,"inactive")}function L(a,b,c){if(a.j&&a.h[b])if(c)a.h[b](c.c,K(c));else a.h[b]()};function ja(){this.c={}}function ka(a,b,c){var d=[],e;for(e in b)if(b.hasOwnProperty(e)){var f=a.c[e];f&&d.push(f(b[e],c))}return d};function N(a,b){this.c=a;this.f=b;this.a=t(this.c,"span",{"aria-hidden":"true"},this.f)}function O(a){u(a.c,"body",a.a)}function P(a){return"display:block;position:absolute;top:-9999px;left:-9999px;font-size:300px;width:auto;height:auto;line-height:normal;margin:0;padding:0;font-variant:normal;white-space:nowrap;font-family:"+J(a.c)+";"+("font-style:"+I(a)+";font-weight:"+(a.f+"00")+";")};function Q(a,b,c,d,e,f){this.g=a;this.j=b;this.a=d;this.c=c;this.f=e||3E3;this.h=f||void 0}Q.prototype.start=function(){var a=this.c.m.document,b=this,c=q(),d=new Promise(function(d,e){function k(){q()-c>=b.f?e():a.fonts.load(fa(b.a),b.h).then(function(a){1<=a.length?d():setTimeout(k,25)},function(){e()})}k()}),e=new Promise(function(a,d){setTimeout(d,b.f)});Promise.race([e,d]).then(function(){b.g(b.a)},function(){b.j(b.a)})};function R(a,b,c,d,e,f,g){this.v=a;this.B=b;this.c=c;this.a=d;this.s=g||"BESbswy";this.f={};this.w=e||3E3;this.u=f||null;this.o=this.j=this.h=this.g=null;this.g=new N(this.c,this.s);this.h=new N(this.c,this.s);this.j=new N(this.c,this.s);this.o=new N(this.c,this.s);a=new H(this.a.c+",serif",K(this.a));a=P(a);this.g.a.style.cssText=a;a=new H(this.a.c+",sans-serif",K(this.a));a=P(a);this.h.a.style.cssText=a;a=new H("serif",K(this.a));a=P(a);this.j.a.style.cssText=a;a=new H("sans-serif",K(this.a));a=
22
- P(a);this.o.a.style.cssText=a;O(this.g);O(this.h);O(this.j);O(this.o)}var S={D:"serif",C:"sans-serif"},T=null;function U(){if(null===T){var a=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(window.navigator.userAgent);T=!!a&&(536>parseInt(a[1],10)||536===parseInt(a[1],10)&&11>=parseInt(a[2],10))}return T}R.prototype.start=function(){this.f.serif=this.j.a.offsetWidth;this.f["sans-serif"]=this.o.a.offsetWidth;this.A=q();la(this)};
23
- function ma(a,b,c){for(var d in S)if(S.hasOwnProperty(d)&&b===a.f[S[d]]&&c===a.f[S[d]])return!0;return!1}function la(a){var b=a.g.a.offsetWidth,c=a.h.a.offsetWidth,d;(d=b===a.f.serif&&c===a.f["sans-serif"])||(d=U()&&ma(a,b,c));d?q()-a.A>=a.w?U()&&ma(a,b,c)&&(null===a.u||a.u.hasOwnProperty(a.a.c))?V(a,a.v):V(a,a.B):na(a):V(a,a.v)}function na(a){setTimeout(p(function(){la(this)},a),50)}function V(a,b){setTimeout(p(function(){v(this.g.a);v(this.h.a);v(this.j.a);v(this.o.a);b(this.a)},a),0)};function W(a,b,c){this.c=a;this.a=b;this.f=0;this.o=this.j=!1;this.s=c}var X=null;W.prototype.g=function(a){var b=this.a;b.g&&w(b.f,[b.a.c("wf",a.c,K(a).toString(),"active")],[b.a.c("wf",a.c,K(a).toString(),"loading"),b.a.c("wf",a.c,K(a).toString(),"inactive")]);L(b,"fontactive",a);this.o=!0;oa(this)};
24
- W.prototype.h=function(a){var b=this.a;if(b.g){var c=y(b.f,b.a.c("wf",a.c,K(a).toString(),"active")),d=[],e=[b.a.c("wf",a.c,K(a).toString(),"loading")];c||d.push(b.a.c("wf",a.c,K(a).toString(),"inactive"));w(b.f,d,e)}L(b,"fontinactive",a);oa(this)};function oa(a){0==--a.f&&a.j&&(a.o?(a=a.a,a.g&&w(a.f,[a.a.c("wf","active")],[a.a.c("wf","loading"),a.a.c("wf","inactive")]),L(a,"active")):M(a.a))};function pa(a){this.j=a;this.a=new ja;this.h=0;this.f=this.g=!0}pa.prototype.load=function(a){this.c=new ca(this.j,a.context||this.j);this.g=!1!==a.events;this.f=!1!==a.classes;qa(this,new ha(this.c,a),a)};
25
- function ra(a,b,c,d,e){var f=0==--a.h;(a.f||a.g)&&setTimeout(function(){var a=e||null,k=d||null||{};if(0===c.length&&f)M(b.a);else{b.f+=c.length;f&&(b.j=f);var h,m=[];for(h=0;h<c.length;h++){var l=c[h],n=k[l.c],r=b.a,x=l;r.g&&w(r.f,[r.a.c("wf",x.c,K(x).toString(),"loading")]);L(r,"fontloading",x);r=null;null===X&&(X=window.FontFace?(x=/Gecko.*Firefox\/(\d+)/.exec(window.navigator.userAgent))?42<parseInt(x[1],10):!0:!1);X?r=new Q(p(b.g,b),p(b.h,b),b.c,l,b.s,n):r=new R(p(b.g,b),p(b.h,b),b.c,l,b.s,a,
26
- n);m.push(r)}for(h=0;h<m.length;h++)m[h].start()}},0)}function qa(a,b,c){var d=[],e=c.timeout;ia(b);var d=ka(a.a,c,a.c),f=new W(a.c,b,e);a.h=d.length;b=0;for(c=d.length;b<c;b++)d[b].load(function(b,d,c){ra(a,f,b,d,c)})};function sa(a,b){this.c=a;this.a=b}function ta(a,b,c){var d=z(a.c);a=(a.a.api||"fast.fonts.net/jsapi").replace(/^.*http(s?):(\/\/)?/,"");return d+"//"+a+"/"+b+".js"+(c?"?v="+c:"")}
27
- sa.prototype.load=function(a){function b(){if(f["__mti_fntLst"+d]){var c=f["__mti_fntLst"+d](),e=[],h;if(c)for(var m=0;m<c.length;m++){var l=c[m].fontfamily;void 0!=c[m].fontStyle&&void 0!=c[m].fontWeight?(h=c[m].fontStyle+c[m].fontWeight,e.push(new H(l,h))):e.push(new H(l))}a(e)}else setTimeout(function(){b()},50)}var c=this,d=c.a.projectId,e=c.a.version;if(d){var f=c.c.m;B(this.c,ta(c,d,e),function(e){e?a([]):(f["__MonotypeConfiguration__"+d]=function(){return c.a},b())}).id="__MonotypeAPIScript__"+
28
- d}else a([])};function ua(a,b){this.c=a;this.a=b}ua.prototype.load=function(a){var b,c,d=this.a.urls||[],e=this.a.families||[],f=this.a.testStrings||{},g=new C;b=0;for(c=d.length;b<c;b++)A(this.c,d[b],D(g));var k=[];b=0;for(c=e.length;b<c;b++)if(d=e[b].split(":"),d[1])for(var h=d[1].split(","),m=0;m<h.length;m+=1)k.push(new H(d[0],h[m]));else k.push(new H(d[0]));F(g,function(){a(k,f)})};function va(a,b,c){a?this.c=a:this.c=b+wa;this.a=[];this.f=[];this.g=c||""}var wa="//fonts.googleapis.com/css";function xa(a,b){for(var c=b.length,d=0;d<c;d++){var e=b[d].split(":");3==e.length&&a.f.push(e.pop());var f="";2==e.length&&""!=e[1]&&(f=":");a.a.push(e.join(f))}}
29
- function ya(a){if(0==a.a.length)throw Error("No fonts to load!");if(-1!=a.c.indexOf("kit="))return a.c;for(var b=a.a.length,c=[],d=0;d<b;d++)c.push(a.a[d].replace(/ /g,"+"));b=a.c+"?family="+c.join("%7C");0<a.f.length&&(b+="&subset="+a.f.join(","));0<a.g.length&&(b+="&text="+encodeURIComponent(a.g));return b};function za(a){this.f=a;this.a=[];this.c={}}
30
- var Aa={latin:"BESbswy","latin-ext":"\u00e7\u00f6\u00fc\u011f\u015f",cyrillic:"\u0439\u044f\u0416",greek:"\u03b1\u03b2\u03a3",khmer:"\u1780\u1781\u1782",Hanuman:"\u1780\u1781\u1782"},Ba={thin:"1",extralight:"2","extra-light":"2",ultralight:"2","ultra-light":"2",light:"3",regular:"4",book:"4",medium:"5","semi-bold":"6",semibold:"6","demi-bold":"6",demibold:"6",bold:"7","extra-bold":"8",extrabold:"8","ultra-bold":"8",ultrabold:"8",black:"9",heavy:"9",l:"3",r:"4",b:"7"},Ca={i:"i",italic:"i",n:"n",normal:"n"},
31
- Da=/^(thin|(?:(?:extra|ultra)-?)?light|regular|book|medium|(?:(?:semi|demi|extra|ultra)-?)?bold|black|heavy|l|r|b|[1-9]00)?(n|i|normal|italic)?$/;
32
- function Ea(a){for(var b=a.f.length,c=0;c<b;c++){var d=a.f[c].split(":"),e=d[0].replace(/\+/g," "),f=["n4"];if(2<=d.length){var g;var k=d[1];g=[];if(k)for(var k=k.split(","),h=k.length,m=0;m<h;m++){var l;l=k[m];if(l.match(/^[\w-]+$/)){var n=Da.exec(l.toLowerCase());if(null==n)l="";else{l=n[2];l=null==l||""==l?"n":Ca[l];n=n[1];if(null==n||""==n)n="4";else var r=Ba[n],n=r?r:isNaN(n)?"4":n.substr(0,1);l=[l,n].join("")}}else l="";l&&g.push(l)}0<g.length&&(f=g);3==d.length&&(d=d[2],g=[],d=d?d.split(","):
33
- g,0<d.length&&(d=Aa[d[0]])&&(a.c[e]=d))}a.c[e]||(d=Aa[e])&&(a.c[e]=d);for(d=0;d<f.length;d+=1)a.a.push(new H(e,f[d]))}};function Fa(a,b){this.c=a;this.a=b}var Ga={Arimo:!0,Cousine:!0,Tinos:!0};Fa.prototype.load=function(a){var b=new C,c=this.c,d=new va(this.a.api,z(c),this.a.text),e=this.a.families;xa(d,e);var f=new za(e);Ea(f);A(c,ya(d),D(b));F(b,function(){a(f.a,f.c,Ga)})};function Ha(a,b){this.c=a;this.a=b}Ha.prototype.load=function(a){var b=this.a.id,c=this.c.m;b?B(this.c,(this.a.api||"https://use.typekit.net")+"/"+b+".js",function(b){if(b)a([]);else if(c.Typekit&&c.Typekit.config&&c.Typekit.config.fn){b=c.Typekit.config.fn;for(var e=[],f=0;f<b.length;f+=2)for(var g=b[f],k=b[f+1],h=0;h<k.length;h++)e.push(new H(g,k[h]));try{c.Typekit.load({events:!1,classes:!1,async:!0})}catch(m){}a(e)}},2E3):a([])};function Ia(a,b){this.c=a;this.f=b;this.a=[]}Ia.prototype.load=function(a){var b=this.f.id,c=this.c.m,d=this;b?(c.__webfontfontdeckmodule__||(c.__webfontfontdeckmodule__={}),c.__webfontfontdeckmodule__[b]=function(b,c){for(var g=0,k=c.fonts.length;g<k;++g){var h=c.fonts[g];d.a.push(new H(h.name,ga("font-weight:"+h.weight+";font-style:"+h.style)))}a(d.a)},B(this.c,z(this.c)+(this.f.api||"//f.fontdeck.com/s/css/js/")+ea(this.c)+"/"+b+".js",function(b){b&&a([])})):a([])};var Y=new pa(window);Y.a.c.custom=function(a,b){return new ua(b,a)};Y.a.c.fontdeck=function(a,b){return new Ia(b,a)};Y.a.c.monotype=function(a,b){return new sa(b,a)};Y.a.c.typekit=function(a,b){return new Ha(b,a)};Y.a.c.google=function(a,b){return new Fa(b,a)};var Z={load:p(Y.load,Y)};"function"===typeof define&&define.amd?define(function(){return Z}):"undefined"!==typeof module&&module.exports?module.exports=Z:(window.WebFont=Z,window.WebFontConfig&&Y.load(window.WebFontConfig));}());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/js/omgf-admin.js CHANGED
@@ -15,352 +15,14 @@
15
 
16
  jQuery(document).ready(function ($) {
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
- $search_box: $('#omgf-search'),
37
- $search_button: $('#omgf-search-subsets'),
38
- $loader: $('.omgf-loading'),
39
- $font_families: $('.omgf-subset-font-family'),
40
- $subsets: $('.omgf-subset'),
41
- $manage_font_styles: $('.omgf-font-preload, .omgf-font-remove'),
42
-
43
  /**
44
  * Initialize all on click events.
45
  */
46
  init: function () {
47
- // Current queue states
48
- this.subsets_state = $('.omgf-subset:checked').length;
49
- this.preload_state = $('.omgf-font-preload:checked').length;
50
- this.font_style_state = $('.omgf-font-style').length;
51
-
52
- // Manage queues
53
- this.$subsets.on('click', this.manage_subset_queue);
54
- this.$manage_font_styles.on('click', this.manage_font_styles_queues);
55
-
56
- // Pressing enter in the search box redirects to WordPress' General Options? Let's NOT.
57
- this.$search_box.on('keyup, keydown', function(event) {
58
- if (event.keyCode === 13) {
59
- event.preventDefault();
60
- omgf_admin.$search_button.click();
61
- }
62
- });
63
-
64
  // Buttons
65
- $('#omgf-search-subsets').on('click', this.click_search);
66
- $('#omgf-auto-detect, .help.auto-detect').on('click', this.enable_auto_detect);
67
- $('.omgf-apply.font-styles-search').on('click', this.search_google_fonts);
68
- $('.omgf-apply.font-styles').on('click', this.process_font_styles_queue);
69
- $('#omgf-download, .help.download-fonts').on('click', this.download_fonts);
70
- $('#omgf-generate, .help.generate-stylesheet').on('click', this.generate_stylesheet);
71
- $('#omgf-empty').on('click', this.empty_cache_directory);
72
- },
73
-
74
- /**
75
- * Show apply button, if any changes are made to the list of subsets.
76
- */
77
- manage_subset_queue: function () {
78
- section = $('#omgf-subsets');
79
- colspan = section.find("tr:first td").length - 1;
80
- $('.omgf-subsets-search').attr('colspan', colspan);
81
- subset_length = $('.omgf-subset:checked').length;
82
-
83
- if (subset_length !== omgf_admin.subsets_state) {
84
- omgf_admin.show_button($('.omgf-apply.font-styles-search'), section);
85
- } else {
86
- omgf_admin.hide_button($('.omgf-apply.font-styles-search'), section);
87
- }
88
- },
89
-
90
- /**
91
- * Trigger the appropriate queue manager.
92
- */
93
- manage_font_styles_queues: function () {
94
- if (this.classList.contains('omgf-font-preload')) {
95
- omgf_admin.manage_preload_queue();
96
- } else {
97
- omgf_admin.manage_removal_queue(this);
98
- }
99
- },
100
-
101
- /**
102
- * If any changes are made to the preload queue, display apply button.
103
- */
104
- manage_preload_queue: function () {
105
- omgf_admin.toggle_font_styles_apply_button();
106
- },
107
-
108
- /**
109
- * Enqueue for removal or undo removal of current item.
110
- */
111
- manage_removal_queue: function (element) {
112
- if (element.classList.contains('omgf-font-remove')) {
113
- omgf_admin.enqueue_for_removal(element);
114
- } else {
115
- omgf_admin.undo_removal(element);
116
- }
117
- },
118
-
119
- /**
120
- * Add current item to removal queue.
121
- *
122
- * @param item
123
- */
124
- enqueue_for_removal: function (item) {
125
- row = '#' + $(item).data('row');
126
-
127
- $(row).css({
128
- 'opacity': '0.5'
129
- });
130
-
131
- $(item).addClass('omgf-font-no-remove dashicons-before dashicons-undo');
132
- $(item).removeClass('omgf-font-remove notice-dismiss');
133
- $(row).removeClass('omgf-font-style');
134
-
135
- omgf_admin.toggle_font_styles_apply_button();
136
- },
137
-
138
- /**
139
- * Remove current item from removal queue.
140
- *
141
- * @param item
142
- */
143
- undo_removal: function (item) {
144
- row = '#' + $(item).data('row');
145
-
146
- $(row).css({
147
- 'opacity': '1'
148
- });
149
-
150
- $(item).removeClass('omgf-font-no-remove dashicons-before dashicons-undo');
151
- $(item).addClass('omgf-font-remove notice-dismiss');
152
- $(row).addClass('omgf-font-style');
153
-
154
- omgf_admin.toggle_font_styles_apply_button();
155
- },
156
-
157
- /**
158
- *
159
- */
160
- toggle_font_styles_apply_button: function () {
161
- font_style_length = $('.omgf-font-style').length;
162
- preload_length = $('.omgf-font-preload:checked').length;
163
-
164
- if (font_style_length !== omgf_admin.font_style_state || preload_length !== omgf_admin.preload_state) {
165
- omgf_admin.show_button($('.omgf-apply.button.font-styles'), $('#omgf-font-styles-list'));
166
- } else {
167
- omgf_admin.hide_button($('.omgf-apply.button.font-styles'), $('#omgf-font-styles-list'));
168
- }
169
- },
170
-
171
- /**
172
- * @param button
173
- * @param section
174
- */
175
- show_button: function(button, section) {
176
- help_text = section.find('.omgf-apply.help');
177
-
178
- button.show();
179
- help_text.show();
180
- },
181
-
182
- /**
183
- * @param button
184
- * @param section
185
- */
186
- hide_button: function(button, section) {
187
- help_text = section.find('.omgf-apply.help');
188
-
189
- button.hide();
190
- help_text.hide();
191
- },
192
-
193
- /**
194
- * Triggered when Search is clicked.
195
- */
196
- click_search: function () {
197
- searchQuery = $('#omgf-search').val();
198
- omgf_admin.search_subsets(searchQuery);
199
- },
200
-
201
- /**
202
- * Triggered by Click Search
203
- *
204
- * @param query
205
- */
206
- search_subsets: function (query) {
207
- jQuery.ajax({
208
- type: 'POST',
209
- url: ajaxurl,
210
- data: {
211
- action: 'omgf_ajax_search_font_subsets',
212
- search_query: query
213
- },
214
- dataType: 'json',
215
- beforeSend: function () {
216
- omgf_admin.show_loader('.omgf-search-box');
217
- },
218
- complete: function() {
219
- location.reload();
220
- }
221
- });
222
- },
223
-
224
- /**
225
- * Enable Auto Detect.
226
- */
227
- enable_auto_detect: function () {
228
- $.ajax({
229
- type: 'POST',
230
- url: ajaxurl,
231
- data: {
232
- action: 'omgf_ajax_enable_auto_detect'
233
- },
234
- dataType: 'json',
235
- beforeSend: function () {
236
- omgf_admin.show_loader('.omgf-search-box');
237
- },
238
- complete: function () {
239
- location.reload();
240
- }
241
- });
242
- },
243
-
244
- /**
245
- * Triggered on Search
246
- * TODO: Refactor to more sensible names.
247
- */
248
- search_google_fonts: function () {
249
- if (omgf_admin.search_fonts_xhr) {
250
- omgf_admin.search_fonts_xhr.abort();
251
- }
252
-
253
- omgf_admin.font_families = omgf_admin.$font_families.map(function () {
254
- return $(this).data('font-family');
255
- }).get();
256
-
257
- omgf_admin.font_families.forEach(function(font, index) {
258
- omgf_admin.font_families[index] = {};
259
- omgf_admin.font_families[index].selected_subsets = [];
260
-
261
- $('input[data-subset-font-family="' + font + '"]:checked').each(function(i) {
262
- omgf_admin.font_families[index].subset_font = font;
263
- omgf_admin.font_families[index].selected_subsets[i] = this.value;
264
- });
265
- });
266
-
267
- omgf_admin.search_fonts_xhr = $.ajax({
268
- type: 'POST',
269
- url: ajaxurl,
270
- data: {
271
- action: 'omgf_ajax_search_google_fonts',
272
- search_google_fonts: omgf_admin.font_families,
273
- },
274
- dataType: 'json',
275
- beforeSend: function() {
276
- omgf_admin.show_loader('#omgf-font-styles-list');
277
- },
278
- complete: function () {
279
- location.reload();
280
- }
281
- });
282
- },
283
-
284
- /**
285
- *
286
- */
287
- process_font_styles_queue: function () {
288
- if (omgf_admin.process_font_styles_xhr) {
289
- omgf_admin.process_font_styles_xhr.abort();
290
- }
291
-
292
- omgf_admin.font_style_list = $('.omgf-font-style').map(function () {
293
- return $(this).data('font-id');
294
- }).get();
295
-
296
- omgf_admin.preload_font_styles = $('.omgf-font-preload:checked').map(function () {
297
- return this.value;
298
- }).get();
299
-
300
- omgf_admin.process_font_styles_xhr = $.ajax({
301
- type: 'POST',
302
- url: ajaxurl,
303
- data: {
304
- action: 'omgf_ajax_process_font_styles_queue',
305
- font_styles: omgf_admin.font_style_list,
306
- preload_font_styles: omgf_admin.preload_font_styles
307
- },
308
- dataType: 'json',
309
- beforeSend: function() {
310
- omgf_admin.show_loader('#omgf-font-styles-list');
311
- },
312
- success: function() {
313
- location.reload();
314
- }
315
- });
316
- },
317
-
318
- /**
319
- * Download fonts and refresh window.
320
- */
321
- download_fonts: function () {
322
- if (omgf_admin.download_fonts_xhr) {
323
- omgf_admin.download_fonts_xhr.abort();
324
- }
325
-
326
- omgf_admin.download_fonts_xhr = $.ajax({
327
- type: 'POST',
328
- url: ajaxurl,
329
- data: {
330
- action: 'omgf_ajax_download_fonts'
331
- },
332
- beforeSend: function() {
333
- $('#omgf-download').attr('disabled', true);
334
- omgf_admin.show_loader('.omgf-search-section');
335
- },
336
- complete: function() {
337
- location.reload();
338
- }
339
- });
340
- },
341
-
342
- /**
343
- * Generate stylesheet and refresh window.
344
- */
345
- generate_stylesheet: function () {
346
- if (omgf_admin.generate_stylesheet_xhr) {
347
- omgf_admin.generate_stylesheet_xhr.abort();
348
- }
349
-
350
- omgf_admin.generate_stylesheet_xhr = $.ajax({
351
- type: 'POST',
352
- url: ajaxurl,
353
- data: {
354
- action: 'omgf_ajax_generate_styles',
355
- },
356
- beforeSend: function() {
357
- $('#omgf-generate').attr('disabled', true);
358
- omgf_admin.show_loader('.omgf-search-section');
359
- },
360
- complete: function() {
361
- location.reload();
362
- }
363
- });
364
  },
365
 
366
  /**
@@ -377,47 +39,15 @@ jQuery(document).ready(function ($) {
377
  data: {
378
  action: 'omgf_ajax_empty_dir'
379
  },
380
- beforeSend: function() {
381
- omgf_admin.show_loader('.omgf-search-section');
382
- },
383
  complete: function() {
384
  location.reload();
385
  }
386
  });
387
  },
388
-
389
- /**
390
- * Show loader on element
391
- *
392
- * @param element
393
- */
394
- show_loader: function (element) {
395
- var clone = omgf_admin.$loader.clone();
396
-
397
- $(element).append(clone).css({
398
- 'position': 'relative',
399
- 'opacity': '0.5'
400
- });
401
-
402
- clone.show();
403
- },
404
  };
405
 
406
  omgf_admin.init();
407
 
408
- /**
409
- * Toggle different options that aren't compatible with each other.
410
- */
411
- $('#omgf_web_font_loader, #omgf_preload').click(function () {
412
- if (this.className === 'omgf_web_font_loader' && this.checked === true) {
413
- $('#omgf_preload').attr('checked', false);
414
- }
415
-
416
- if (this.className === 'omgf_preload' && this.checked === true) {
417
- $('#omgf_web_font_loader').attr('checked', false);
418
- }
419
- });
420
-
421
  $('#omgf_relative_url').click(function () {
422
  if (this.checked === true) {
423
  $('#omgf_cdn_url').prop('disabled', true);
15
 
16
  jQuery(document).ready(function ($) {
17
  var omgf_admin = {
 
 
 
 
 
18
  empty_cache_directory_xhr: false,
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  /**
21
  * Initialize all on click events.
22
  */
23
  init: function () {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  // Buttons
25
+ $('.omgf-empty').on('click', this.empty_cache_directory);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  },
27
 
28
  /**
39
  data: {
40
  action: 'omgf_ajax_empty_dir'
41
  },
 
 
 
42
  complete: function() {
43
  location.reload();
44
  }
45
  });
46
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  };
48
 
49
  omgf_admin.init();
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  $('#omgf_relative_url').click(function () {
52
  if (this.checked === true) {
53
  $('#omgf_cdn_url').prop('disabled', true);
ffwp-autoload.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* * * * * * * * * * * * * * * * * * * * * *
3
+ * @author : Daan van den Bergh
4
+ * @url : https://ffwp.dev/wordpress-plugins/
5
+ * @copyright: (c) 2020 Daan van den Bergh
6
+ * @license : GPL2v2 or later
7
+ * * * * * * * * * * * * * * * * * * * * * */
8
+
9
+ class FFWP_Autoloader
10
+ {
11
+ /** @var string $class */
12
+ private $class;
13
+
14
+ /** @var string $file */
15
+ private $file;
16
+
17
+ /**
18
+ * FFWP_Autoloader constructor.
19
+ *
20
+ * @param $class
21
+ */
22
+ public function __construct(
23
+ $class
24
+ ) {
25
+ $this->class = $class;
26
+ }
27
+
28
+ /**
29
+ * Build filepath for requested class.
30
+ */
31
+ public function load()
32
+ {
33
+ $path = explode('_', $this->class);
34
+ $this->file = '';
35
+ $i = 0;
36
+
37
+ if (count($path) > 1) {
38
+ array_shift($path);
39
+ }
40
+ end($path);
41
+
42
+ /**
43
+ * Build directory path.
44
+ */
45
+ while ($i < key($path)) {
46
+ $this->build($path[$i], '', '/');
47
+
48
+ $i++;
49
+ }
50
+
51
+ /**
52
+ * Build filename.
53
+ */
54
+ $this->build($path[$i], 'class', '.php');
55
+
56
+ return $this->file;
57
+ }
58
+
59
+ /**
60
+ * Checks if $path is written uppercase entirely, otherwise it'll split $path up and build a string glued with
61
+ * dashes.
62
+ *
63
+ * @param $path
64
+ * @param string $prefix
65
+ * @param string $suffix
66
+ */
67
+ private function build($path, $prefix = '', $suffix = '/')
68
+ {
69
+ if (ctype_upper($path)) {
70
+ $this->file .= ($prefix ? $prefix . '-' : '') . strtolower($path) . $suffix;
71
+ } else {
72
+ $parts = preg_split('/(?=[A-Z])/', lcfirst($path));
73
+ $this->file .= ($prefix ? $prefix . '-' : '') . strtolower(implode('-', $parts)) . $suffix;
74
+ }
75
+ }
76
+ }
host-webfonts-local.php CHANGED
@@ -3,25 +3,23 @@
3
  * @formatter:off
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.8.2
8
- * Author: Daan van den Bergh
9
- * Author URI: https://daan.dev
10
  * License: GPL2v2 or later
11
  * Text Domain: host-webfonts-local
12
  * @formatter:on
13
  */
14
 
15
- defined('ABSPATH') || exit;
16
 
17
  /**
18
  * Define constants.
19
  */
20
- define('OMGF_PLUGIN_DIR', plugin_dir_path(__FILE__));
21
- define('OMGF_PLUGIN_FILE', __FILE__);
22
- define('OMGF_DB_VERSION', '3.0.0'); // Legacy
23
- define('OMGF_STATIC_VERSION', '3.4.0');
24
- define('OMGF_WEB_FONT_LOADER_VERSION', '1.6.26');
25
 
26
  /**
27
  * Takes care of loading classes on demand.
@@ -30,39 +28,37 @@ define('OMGF_WEB_FONT_LOADER_VERSION', '1.6.26');
30
  *
31
  * @return mixed|void
32
  */
33
- function omgf_autoload($class)
34
- {
35
- $path = explode('_', $class);
36
-
37
- if ($path[0] != 'OMGF') {
38
- return;
39
- }
40
-
41
- if (!class_exists('Woosh_Autoloader')) {
42
- require_once(OMGF_PLUGIN_DIR . 'woosh-autoload.php');
43
- }
44
-
45
- $autoload = new Woosh_Autoloader($class);
46
-
47
- return include OMGF_PLUGIN_DIR . 'includes/' . $autoload->load();
48
  }
49
 
50
- spl_autoload_register('omgf_autoload');
51
 
52
  /**
53
  * All systems GO!!!
54
  *
55
  * @return OMGF
56
  */
57
- function omgf_init()
58
- {
59
- static $omgf = null;
60
-
61
- if ($omgf === null) {
62
- $omgf = new OMGF();
63
- }
64
-
65
- return $omgf;
66
  }
67
 
68
- omgf_init();
3
  * @formatter:off
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 automatically saving Google Fonts to your server and removing the external Google Fonts.
7
+ * Version: 4.0.0
8
+ * Author: Daan (from Fast FW Press)
9
+ * Author URI: https://ffwp.dev
10
  * License: GPL2v2 or later
11
  * Text Domain: host-webfonts-local
12
  * @formatter:on
13
  */
14
 
15
+ defined( 'ABSPATH' ) || exit;
16
 
17
  /**
18
  * Define constants.
19
  */
20
+ define( 'OMGF_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
21
+ define( 'OMGF_PLUGIN_FILE', __FILE__ );
22
+ define( 'OMGF_STATIC_VERSION', '3.4.0' );
 
 
23
 
24
  /**
25
  * Takes care of loading classes on demand.
28
  *
29
  * @return mixed|void
30
  */
31
+ function omgf_autoload ( $class ) {
32
+ $path = explode( '_', $class );
33
+
34
+ if ( $path[0] != 'OMGF' ) {
35
+ return;
36
+ }
37
+
38
+ if ( ! class_exists( 'FFWP_Autoloader' ) ) {
39
+ require_once( OMGF_PLUGIN_DIR . 'ffwp-autoload.php' );
40
+ }
41
+
42
+ $autoload = new FFWP_Autoloader( $class );
43
+
44
+ return include OMGF_PLUGIN_DIR . 'includes/' . $autoload->load();
 
45
  }
46
 
47
+ spl_autoload_register( 'omgf_autoload' );
48
 
49
  /**
50
  * All systems GO!!!
51
  *
52
  * @return OMGF
53
  */
54
+ function omgf_init () {
55
+ static $omgf = null;
56
+
57
+ if ( $omgf === null ) {
58
+ $omgf = new OMGF();
59
+ }
60
+
61
+ return $omgf;
 
62
  }
63
 
64
+ add_action( 'plugins_loaded', 'omgf_init', 50 );
includes/admin/class-auto-detect.php DELETED
@@ -1,227 +0,0 @@
1
- <?php
2
- /* * * * * * * * * * * * * * * * * * * * *
3
- *
4
- * ██████╗ ███╗ ███╗ ██████╗ ███████╗
5
- * ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
6
- * ██║ ██║██╔████╔██║██║ ███╗█████╗
7
- * ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
8
- * ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
9
- * ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
10
- *
11
- * @package : OMGF
12
- * @author : Daan van den Bergh
13
- * @copyright: (c) 2020 Daan van den Bergh
14
- * @url : https://daan.dev
15
- * * * * * * * * * * * * * * * * * * * */
16
-
17
- defined('ABSPATH') || exit;
18
-
19
- class OMGF_Admin_AutoDetect
20
- {
21
- /** @var array $detected_fonts */
22
- private $detected_fonts = [];
23
-
24
- /** @var OMGF_API $api */
25
- private $api;
26
-
27
- /**
28
- * OMGF_Admin_AutoDetect constructor.
29
- *
30
- * @param $detected_fonts
31
- */
32
- public function __construct(
33
- $detected_fonts
34
- ) {
35
- $this->detected_fonts = $detected_fonts;
36
- $this->api = new OMGF_API();
37
-
38
- $this->init();
39
- }
40
-
41
- /**
42
- * Run Auto Detect.
43
- */
44
- private function init()
45
- {
46
- $font_properties = $this->extract_font_properties($this->detected_fonts);
47
-
48
- $subsets = $this->build_subsets_array($font_properties);
49
-
50
- foreach ($subsets as $index => &$font) {
51
- if (!is_numeric($index)) {
52
- continue;
53
- }
54
-
55
- $font_styles[$font['subset_font']] = $this->api->get_font_styles($font['subset_font'], implode(',', $font['selected_subsets']));
56
-
57
- // If subset was already detected, replace styles instead of overwriting them.
58
- if (isset($subsets[$font['subset_font']])) {
59
- $subsets[$font['subset_font']] = array_replace_recursive($subsets[$font['subset_font']], $font);
60
- } else {
61
- $subsets[$font['subset_font']] = $font;
62
- }
63
-
64
- unset($subsets[$index]);
65
- }
66
-
67
- update_option(OMGF_Admin_Settings::OMGF_SETTING_SUBSETS, $subsets);
68
-
69
- // Match used styles with available styles.
70
- foreach ($subsets as $subset) {
71
- $used_styles[] = $this->process_used_styles($subset['used_styles'], $font_styles[$subset['subset_font']]);
72
- }
73
-
74
- if (isset($used_styles)) {
75
- $detected_font_styles = array_merge(...$used_styles);
76
-
77
- update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $detected_font_styles);
78
- }
79
-
80
- /** It only needs to run once. */
81
- delete_option(OMGF_Admin_Settings::OMGF_SETTING_AUTO_DETECTION_ENABLED);
82
- delete_option(OMGF_Admin_Settings::OMGF_SETTING_DETECTED_FONTS);
83
-
84
- if (empty($subsets)) {
85
- OMGF_Admin_Notice::set_notice(__('Auto Detect completed successfully, but no Google Fonts were found.', 'host-webfonts-local'), false, 'warning');
86
-
87
- OMGF_Admin_Notice::set_notice(sprintf(__('Your theme and/or plugins are using unconventional methods (or Web Font Loader) to load Google Fonts. <strong>Upgrade to OMGF Pro</strong> (<em>starting at € 29, -</em>) to automatically detect and replace Google Fonts for your theme and plugins. <a href="%s" target="_blank">Purchase OMGF Pro</a>.', 'host-webfonts-local'), OMGF_Admin_Settings_Builder::WOOSH_WORDPRESS_PLUGINS_HOST_GOOGLE_FONTS_PRO), false, 'info');
88
- } else {
89
- $count_fonts = count($subsets);
90
- $count_subsets = 0;
91
- foreach ($subsets as $subset) {
92
- $count_subsets += count($subset['available_subsets']);
93
- }
94
- $count_font_styles = count($detected_font_styles);
95
-
96
- OMGF_Admin_Notice::set_notice(__("Auto Detect found $count_fonts fonts in $count_subsets different subsets and $count_font_styles font styles. Please check the results and proceed to download the fonts and generate the stylesheet.", 'host-webfonts-local'), false);
97
- }
98
- }
99
-
100
- /**
101
- * @param $fontSource
102
- *
103
- * @return array
104
- */
105
- private function extract_font_properties($fontSource)
106
- {
107
- $font_properties = array();
108
-
109
- $i = 0;
110
-
111
- foreach ($fontSource as $source) {
112
- $parts = parse_url($source);
113
-
114
- /**
115
- * Skip over default Admin WordPress fonts; Noto Serif and Open Sans, which are always detected first (as far as I know.)
116
- * We check on iteration value, to make sure these fonts are still returned if they are also used in the theme.
117
- */
118
- if (($i == 0 && strpos($parts['query'], 'Open+Sans') !== false) || ($i == 1 && strpos($parts['query'], 'Noto+Serif') !== false)) {
119
- $i++;
120
- continue;
121
- }
122
-
123
- parse_str($parts['query'], $font_properties[$i]);
124
-
125
- /**
126
- * Some themes (like Twenty Sixteen) do chained requests using a pipe (|).
127
- * This function explodes these requests and adds them to the query.
128
- */
129
- if (strpos($font_properties[$i]['family'], '|') !== false) {
130
- $parts_parts = explode('|', $font_properties[$i]['family']);
131
- $font_property_subset = isset($font_properties[$i]['subset']) ? $font_properties[$i]['subset'] : 'latin';
132
-
133
- foreach ($parts_parts as $part) {
134
- $font_properties[$i]['family'] = $part;
135
- $font_properties[$i]['subset'] = $font_property_subset;
136
- $i++;
137
- }
138
- }
139
-
140
- $i++;
141
- }
142
-
143
- return $font_properties;
144
- }
145
-
146
- /**
147
- * @param $font_properties
148
- *
149
- * @return array
150
- */
151
- private function build_subsets_array($font_properties)
152
- {
153
- foreach ($font_properties as $properties) {
154
- $parts = explode(':', $properties['family']);
155
- $subsets = isset($properties['subset']) ? explode(',', $properties['subset']) : null;
156
-
157
- if (!empty($parts)) {
158
- $font_family = $parts[0];
159
- $styles = explode(',', $parts[1]);
160
- }
161
-
162
- $fonts[] = [
163
- 'subset_family' => $font_family,
164
- 'subset_font' => str_replace(' ', '-', strtolower($font_family)),
165
- 'available_subsets' => $subsets ?? [ 'latin' ],
166
- 'selected_subsets' => $subsets ?? [ 'latin' ],
167
- 'used_styles' => $styles
168
- ];
169
- }
170
-
171
- return $fonts;
172
- }
173
-
174
- /**
175
- * @param $used_styles
176
- * @param $available_styles
177
- *
178
- * @return array
179
- */
180
- private function process_used_styles($used_styles, $available_styles)
181
- {
182
- foreach ($used_styles as &$style) {
183
- if (empty($style)) {
184
- $used_styles = $this->process_available_styles($available_styles);
185
-
186
- break;
187
- }
188
-
189
- $fontWeight = preg_replace('/[^0-9]/', '', $style);
190
- $fontStyle = preg_replace('/[^a-zA-Z]/', '', $style);
191
-
192
- if ($fontStyle == 'i') {
193
- $fontStyle = 'italic';
194
- }
195
-
196
- $style = $fontWeight . $fontStyle;
197
- }
198
-
199
- return array_filter(
200
- $available_styles,
201
- function ($style) use ($used_styles) {
202
- $fontStyle = $style['font_weight'] . ($style['font_style'] !== 'normal' ? $style['font_style'] : '');
203
-
204
- return in_array($fontStyle, $used_styles);
205
- }
206
- );
207
- }
208
-
209
- /**
210
- * Some themes requests font families without specifying font styles. While this is inadvisable, OMGF should be able
211
- * to deal with this. That's why, when no font styles are detected, all available font styles are returned.
212
- *
213
- * @param array $styles
214
- *
215
- * @return array
216
- */
217
- private function process_available_styles(array $styles)
218
- {
219
- foreach ($styles as $style) {
220
- $font_style = $style['font_style'] !== 'normal' ? $style['font_style'] : '';
221
-
222
- $used_styles[] = $style['font_weight'] . $font_style;
223
- }
224
-
225
- return $used_styles;
226
- }
227
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/admin/class-notice.php CHANGED
@@ -14,68 +14,66 @@
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
- defined('ABSPATH') || exit;
18
 
19
  class OMGF_Admin_Notice
20
  {
21
- const OMGF_ADMIN_NOTICE_TRANSIENT = 'omgf_admin_notice';
22
- const OMGF_ADMIN_NOTICE_EXPIRATION = 30;
23
-
24
- /** @var array $notices */
25
- public static $notices = [];
26
-
27
- /**
28
- * @param $message
29
- * @param string $type (info|warning|error|success)
30
- * @param string $screen_id
31
- * @param bool $json
32
- * @param int $code
33
- */
34
- public static function set_notice($message, $die = true, $type = 'success', $code = 200, $screen_id = 'all')
35
- {
36
- self::$notices = get_transient(self::OMGF_ADMIN_NOTICE_TRANSIENT);
37
- self::$notices[$screen_id][$type][] = $message;
38
-
39
- set_transient(self::OMGF_ADMIN_NOTICE_TRANSIENT, self::$notices, self::OMGF_ADMIN_NOTICE_EXPIRATION);
40
-
41
- if ($die) {
42
- switch ($type) {
43
- case 'error':
44
- wp_send_json_error($message, $code);
45
- break;
46
- default:
47
- wp_send_json_success($message, $code);
48
- }
49
- }
50
- }
51
-
52
- /**
53
- * Prints notice (if any) grouped by type.
54
- */
55
- public static function print_notice()
56
- {
57
- $admin_notices = get_transient(self::OMGF_ADMIN_NOTICE_TRANSIENT);
58
-
59
- if (is_array($admin_notices)) {
60
- $current_screen = get_current_screen();
61
-
62
- foreach ($admin_notices as $screen => $notice) {
63
- if ($current_screen->id != $screen && $screen != 'all') {
64
- continue;
65
- }
66
-
67
- foreach ($notice as $type => $message) {
68
- ?>
69
  <div id="message" class="notice notice-<?php echo $type; ?> is-dismissible">
70
- <?php foreach ($message as $line): ?>
71
  <p><?= $line; ?></p>
72
- <?php endforeach; ?>
73
  </div>
74
- <?php
75
- }
76
- }
77
- }
78
-
79
- delete_transient(self::OMGF_ADMIN_NOTICE_TRANSIENT);
80
- }
81
  }
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
+ defined( 'ABSPATH' ) || exit;
18
 
19
  class OMGF_Admin_Notice
20
  {
21
+ const OMGF_ADMIN_NOTICE_TRANSIENT = 'omgf_admin_notice';
22
+ const OMGF_ADMIN_NOTICE_EXPIRATION = 30;
23
+
24
+ /** @var array $notices */
25
+ public static $notices = [];
26
+
27
+ /**
28
+ * @param $message
29
+ * @param string $type (info|warning|error|success)
30
+ * @param string $screen_id
31
+ * @param bool $json
32
+ * @param int $code
33
+ */
34
+ public static function set_notice ( $message, $die = true, $type = 'success', $code = 200, $screen_id = 'all' ) {
35
+ self::$notices = get_transient( self::OMGF_ADMIN_NOTICE_TRANSIENT );
36
+ self::$notices[ $screen_id ][ $type ][] = $message;
37
+
38
+ set_transient( self::OMGF_ADMIN_NOTICE_TRANSIENT, self::$notices, self::OMGF_ADMIN_NOTICE_EXPIRATION );
39
+
40
+ if ( $die ) {
41
+ switch ( $type ) {
42
+ case 'error':
43
+ wp_send_json_error( $message, $code );
44
+ break;
45
+ default:
46
+ wp_send_json_success( $message, $code );
47
+ }
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Prints notice (if any) grouped by type.
53
+ */
54
+ public static function print_notices () {
55
+ $admin_notices = get_transient( self::OMGF_ADMIN_NOTICE_TRANSIENT );
56
+
57
+ if ( is_array( $admin_notices ) ) {
58
+ $current_screen = get_current_screen();
59
+
60
+ foreach ( $admin_notices as $screen => $notice ) {
61
+ if ( $current_screen->id != $screen && $screen != 'all' ) {
62
+ continue;
63
+ }
64
+
65
+ foreach ( $notice as $type => $message ) {
66
+ ?>
 
 
67
  <div id="message" class="notice notice-<?php echo $type; ?> is-dismissible">
68
+ <?php foreach ( $message as $line ): ?>
69
  <p><?= $line; ?></p>
70
+ <?php endforeach; ?>
71
  </div>
72
+ <?php
73
+ }
74
+ }
75
+ }
76
+
77
+ delete_transient( self::OMGF_ADMIN_NOTICE_TRANSIENT );
78
+ }
79
  }
includes/admin/class-settings.php CHANGED
@@ -14,313 +14,293 @@
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
- defined('ABSPATH') || exit;
18
 
19
  class OMGF_Admin_Settings extends OMGF_Admin
20
  {
21
- /**
22
- * Settings Fields
23
- */
24
- const OMGF_SETTINGS_FIELD_GENERATE_STYLESHEET = 'omgf-generate-stylesheet';
25
- const OMGF_SETTINGS_FIELD_ADVANCED = 'omgf-advanced-settings';
26
- const OMGF_SETTINGS_FIELD_EXTENSIONS = 'omgf-extensions-settings';
27
-
28
- /**
29
- * Option Values
30
- */
31
- const OMGF_FONT_DISPLAY_OPTIONS = [
32
- 'swap' => 'Swap (recommended)',
33
- 'auto' => 'Auto',
34
- 'block' => 'Block',
35
- 'fallback' => 'Fallback',
36
- 'optional' => 'Optional'
37
- ];
38
-
39
- /**
40
- * Generate Stylesheet
41
- */
42
- const OMGF_SETTING_DB_VERSION = 'omgf_db_version';
43
- const OMGF_SETTING_AUTO_DETECTION_ENABLED = 'omgf_auto_detection_enabled';
44
- const OMGF_SETTING_DETECTED_FONTS = 'omgf_detected_fonts';
45
- const OMGF_SETTING_SUBSETS = 'omgf_subsets';
46
- const OMGF_SETTING_FONTS = 'omgf_fonts';
47
-
48
- /**
49
- * Advanced Settings
50
- */
51
- const OMGF_ADV_SETTING_CACHE_PATH = 'omgf_cache_dir';
52
- const OMGF_ADV_SETTING_CACHE_URI = 'omgf_cache_uri';
53
- const OMGF_ADV_SETTING_CDN_URL = 'omgf_cdn_url';
54
- const OMGF_ADV_SETTING_WEB_FONT_LOADER = 'omgf_web_font_loader';
55
- const OMGF_ADV_SETTING_REMOVE_VERSION = 'omgf_remove_version';
56
- const OMGF_ADV_SETTING_DISPLAY_OPTION = 'omgf_display_option';
57
- const OMGF_ADV_SETTING_REMOVE_GOOGLE_FONTS = 'omgf_remove_gfonts';
58
- const OMGF_ADV_SETTING_OPTIMIZE_EDIT_ROLES = 'omgf_optimize_edit_roles';
59
- const OMGF_ADV_SETTING_UNINSTALL = 'omgf_uninstall';
60
- const OMGF_ADV_SETTING_ENQUEUE_ORDER = 'omgf_enqueue_order';
61
- const OMGF_ADV_SETTING_FORCE_SSL = 'omgf_force_ssl';
62
- const OMGF_ADV_SETTING_RELATIVE_URL = 'omgf_relative_url';
63
-
64
- /** @var string $active_tab */
65
- private $active_tab;
66
-
67
- /** @var string $page */
68
- private $page;
69
-
70
- /** @var string $plugin_text_domain */
71
- private $plugin_text_domain = 'host-webfonts-local';
72
-
73
- /**
74
- * OMGF_Admin_Settings constructor.
75
- */
76
- public function __construct()
77
- {
78
- parent::__construct();
79
-
80
- $this->active_tab = isset($_GET['tab']) ? $_GET['tab'] : self::OMGF_SETTINGS_FIELD_GENERATE_STYLESHEET;
81
- $this->page = isset($_GET['page']) ? $_GET['page'] : '';
82
-
83
- // @formatter:off
84
- add_action('admin_menu', [$this, 'create_menu']);
85
- add_filter('plugin_action_links_' . plugin_basename(OMGF_PLUGIN_FILE), [$this, 'create_settings_link']);
86
-
87
- if ($this->page !== 'optimize-webfonts') {
88
- return;
89
- }
90
-
91
- // Tabs
92
- add_action('omgf_settings_tab', [$this, 'generate_stylesheet_tab'], 1);
93
- add_action('omgf_settings_tab', [$this, 'advanced_settings_tab'], 2);
94
- add_action('omgf_settings_tab', [$this, 'extensions_settings_tab'], 3);
95
-
96
- // Content
97
- add_action('omgf_settings_content', [$this, 'generate_stylesheet_content'], 1);
98
- add_action('omgf_settings_content', [$this, 'advanced_settings_content'], 2);
99
- add_action('omgf_settings_content', [$this, 'extensions_settings_content'], 3);
100
- // @formatter:on
101
- }
102
-
103
- /**
104
- * Creates the menu item.
105
- */
106
- public function create_menu()
107
- {
108
- add_options_page(
109
- 'OMGF',
110
- 'Optimize Google Fonts',
111
- 'manage_options',
112
- 'optimize-webfonts',
113
- [$this, 'create_settings_page']
114
- );
115
-
116
- // @formatter:off
117
- add_action('admin_init', array($this, 'register_settings'));
118
- // @formatter:on
119
- }
120
-
121
- /**
122
- * Display the settings page.
123
- */
124
- public function create_settings_page()
125
- {
126
- if (!current_user_can('manage_options')) {
127
- wp_die(__("You're not cool enough to access this page.", $this->plugin_text_domain));
128
- }
129
- ?>
130
- <div class="wrap">
131
- <h1><?= apply_filters('omgf_settings_page_title', __('OMGF | Optimize My Google Fonts', $this->plugin_text_domain)); ?></h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  <p>
134
- <?= get_plugin_data(OMGF_PLUGIN_FILE)['Description']; ?>
135
  </p>
136
 
137
  <div class="settings-column left">
138
  <h2 class="omgf-nav nav-tab-wrapper">
139
- <?php do_action('omgf_settings_tab'); ?>
140
  </h2>
141
-
142
- <?php do_action('omgf_settings_content'); ?>
143
  </div>
144
 
145
  <div class="settings-column right">
146
  <div id="omgf-welcome-panel" class="welcome-panel">
147
- <?php $this->get_template('welcome'); ?>
148
  </div>
149
  </div>
150
  </div>
151
- <?php
152
- }
153
-
154
- /**
155
- * Register all settings.
156
- *
157
- * @throws ReflectionException
158
- */
159
- public function register_settings()
160
- {
161
- if ($this->active_tab !== self::OMGF_SETTINGS_FIELD_GENERATE_STYLESHEET
162
- && $this->active_tab !== self::OMGF_SETTINGS_FIELD_ADVANCED
163
- && $this->active_tab !== self::OMGF_SETTINGS_FIELD_EXTENSIONS) {
164
- $this->active_tab = self::OMGF_SETTINGS_FIELD_GENERATE_STYLESHEET;
165
- }
166
-
167
- foreach ($this->get_settings() as $constant => $value)
168
- {
169
- register_setting(
170
- $this->active_tab,
171
- $value
172
- );
173
- }
174
- }
175
-
176
- /**
177
- * Get all settings using the constants in this class.
178
- *
179
- * @return array
180
- * @throws ReflectionException
181
- */
182
- public function get_settings()
183
- {
184
- if ($this->active_tab == self::OMGF_SETTINGS_FIELD_GENERATE_STYLESHEET) {
185
- return [];
186
- }
187
-
188
- $reflection = new ReflectionClass($this);
189
- $constants = apply_filters('omgf_settings_constants', $reflection->getConstants());
190
- $needle = 'OMGF_ADV_SETTING';
191
-
192
- if ($this->active_tab == self::OMGF_SETTINGS_FIELD_EXTENSIONS) {
193
- $needle = 'OMGF_EXT_SETTING';
194
- }
195
-
196
- return array_filter(
197
- $constants,
198
- function ($key) use ($needle) {
199
- return strpos($key, $needle) !== false;
200
- },
201
- ARRAY_FILTER_USE_KEY
202
- );
203
- }
204
-
205
- /**
206
- * Add Generate Stylesheet Tab to Settings Screen.
207
- */
208
- public function generate_stylesheet_tab()
209
- {
210
- $this->generate_tab(self::OMGF_SETTINGS_FIELD_GENERATE_STYLESHEET, 'dashicons-admin-appearance', __('Generate Stylesheet', $this->plugin_text_domain));
211
- }
212
-
213
- /**
214
- * Add Advanced Settings Tab to Settings Screen.
215
- */
216
- public function advanced_settings_tab()
217
- {
218
- $this->generate_tab(self::OMGF_SETTINGS_FIELD_ADVANCED, 'dashicons-admin-settings', __('Advanced Settings', $this->plugin_text_domain));
219
- }
220
-
221
- /**
222
- * Add Extensions tab to Settings Screen.
223
- */
224
- public function extensions_settings_tab()
225
- {
226
- $this->generate_tab(self::OMGF_SETTINGS_FIELD_EXTENSIONS, 'dashicons-admin-plugins', __('Extensions', $this->plugin_text_domain));
227
- }
228
-
229
- /**
230
- * @param $id
231
- * @param null $icon
232
- * @param null $label
233
- */
234
- private function generate_tab($id, $icon = null, $label = null)
235
- {
236
- ?>
237
- <a class="nav-tab dashicons-before <?= $icon; ?> <?= $this->active_tab == $id ? 'nav-tab-active' : ''; ?>" href="<?= $this->generate_tab_link($id);?>">
238
- <?= $label; ?>
239
  </a>
240
- <?php
241
- }
242
-
243
- /**
244
- * @param $tab
245
- *
246
- * @return string
247
- */
248
- private function generate_tab_link($tab)
249
- {
250
- return admin_url("options-general.php?page=optimize-webfonts&tab=$tab");
251
- }
252
-
253
- /**
254
- * Render Generate Stylesheet
255
- */
256
- public function generate_stylesheet_content()
257
- {
258
- if ($this->active_tab != self::OMGF_SETTINGS_FIELD_GENERATE_STYLESHEET) {
259
- return;
260
- }
261
- ?>
262
- <form id="omgf-generate-stylesheet-form" name="omgf-generate-stylesheet-form">
263
- <?php
264
- $this->get_template('generate-stylesheet');
265
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  </form>
267
- <?php
268
- }
269
-
270
- /**
271
- * Render Advanced Settings content
272
- */
273
- public function advanced_settings_content()
274
- {
275
- $this->do_settings_content(self::OMGF_SETTINGS_FIELD_ADVANCED);
276
- }
277
-
278
- /**
279
- * Render Extensions content
280
- */
281
- public function extensions_settings_content()
282
- {
283
- $this->do_settings_content(self::OMGF_SETTINGS_FIELD_EXTENSIONS);
284
- }
285
-
286
- /**
287
- * @param $id
288
- * @param $field
289
- */
290
- private function do_settings_content($field)
291
- {
292
- if ($this->active_tab != $field) {
293
- return;
294
- }
295
- ?>
296
- <form id="<?= $field; ?>-form" name="omgf-settings-form" method="post" action="options.php?tab=<?= $this->active_tab; ?>">
297
- <?php
298
- settings_fields($field);
299
- do_settings_sections($field);
300
-
301
- do_action('omgf_before_settings_form_settings');
302
-
303
- echo apply_filters(str_replace('-', '_', $field) . '_content', '');
304
-
305
- do_action('omgf_after_settings_form_settings');
306
-
307
- submit_button();
308
- ?>
309
- </form>
310
- <?php
311
- }
312
-
313
- /**
314
- * Adds the 'settings' link to the Plugin overview.
315
- *
316
- * @return mixed
317
- */
318
- public function create_settings_link($links)
319
- {
320
- $adminUrl = admin_url() . 'options-general.php?page=optimize-webfonts';
321
- $settingsLink = "<a href='$adminUrl'>" . __('Settings') . "</a>";
322
- array_push($links, $settingsLink);
323
-
324
- return $links;
325
- }
326
  }
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
+ defined( 'ABSPATH' ) || exit;
18
 
19
  class OMGF_Admin_Settings extends OMGF_Admin
20
  {
21
+ /**
22
+ * Settings Fields
23
+ */
24
+ const OMGF_SETTINGS_FIELD_BASIC = 'omgf-basic-settings';
25
+ const OMGF_SETTINGS_FIELD_ADVANCED = 'omgf-advanced-settings';
26
+
27
+ /**
28
+ * Option Values
29
+ */
30
+ const OMGF_FONT_PROCESSING_OPTIONS = [
31
+ 'replace' => 'Replace (default)',
32
+ 'remove' => 'Remove only'
33
+ ];
34
+ const OMGF_FONT_DISPLAY_OPTIONS = [
35
+ 'swap' => 'Swap (recommended)',
36
+ 'auto' => 'Auto',
37
+ 'block' => 'Block',
38
+ 'fallback' => 'Fallback',
39
+ 'optional' => 'Optional'
40
+ ];
41
+ const OMGF_FORCE_SUBSETS_OPTIONS = [
42
+ 'arabic' => 'Arabic',
43
+ 'bengali' => 'Bengali',
44
+ 'chinese-hongkong' => 'Chinese (Hong Kong)',
45
+ 'chinese-simplified' => 'Chinese (Simplified)',
46
+ 'chinese-traditional' => 'Chinese (Traditional)',
47
+ 'cyrillic' => 'Cyrillic',
48
+ 'cyrillic-ext' => 'Cyrillic Extended',
49
+ 'devanagari' => 'Devanagari',
50
+ 'greek' => 'Greek',
51
+ 'greek-ext' => 'Greek Extended',
52
+ 'gujarati' => 'Gujarati',
53
+ 'gurmukhi' => 'Gurmukhi',
54
+ 'hebrew' => 'Hebrew',
55
+ 'japanese' => 'Japanese',
56
+ 'kannada' => 'Kannada',
57
+ 'khmer' => 'Khmer',
58
+ 'korean' => 'Korean',
59
+ 'latin' => 'Latin',
60
+ 'latin-ext' => 'Latin Extended',
61
+ 'malayalam' => 'Malayalam',
62
+ 'myanmar' => 'Myanmar',
63
+ 'oriya' => 'Oriya',
64
+ 'sinhala' => 'Sinhala',
65
+ 'tamil' => 'Tamil',
66
+ 'telugu' => 'Telugu',
67
+ 'thai' => 'Thai',
68
+ 'tibetan' => 'Tibetan',
69
+ 'vietnamese' => 'Vietnamese'
70
+ ];
71
+
72
+ /**
73
+ * Basic Settings
74
+ */
75
+ const OMGF_BASIC_SETTING_FONT_PROCESSING = 'omgf_font_processing';
76
+ const OMGF_BASIC_SETTING_DISPLAY_OPTION = 'omgf_display_option';
77
+ const OMGF_BASIC_SETTING_CACHE_PATH = 'omgf_cache_dir';
78
+ const OMGF_BASIC_SETTING_OPTIMIZE_EDIT_ROLES = 'omgf_optimize_edit_roles';
79
+
80
+ /**
81
+ * Advanced Settings
82
+ */
83
+ const OMGF_ADV_SETTING_CACHE_URI = 'omgf_cache_uri';
84
+ const OMGF_ADV_SETTING_CDN_URL = 'omgf_cdn_url';
85
+ const OMGF_ADV_SETTING_UNINSTALL = 'omgf_uninstall';
86
+ const OMGF_ADV_SETTING_RELATIVE_URL = 'omgf_relative_url';
87
+
88
+ /** @var string $active_tab */
89
+ private $active_tab;
90
+
91
+ /** @var string $page */
92
+ private $page;
93
+
94
+ /** @var string $plugin_text_domain */
95
+ private $plugin_text_domain = 'host-webfonts-local';
96
+
97
+ /**
98
+ * OMGF_Admin_Settings constructor.
99
+ */
100
+ public function __construct () {
101
+ parent::__construct();
102
+
103
+ $this->active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : self::OMGF_SETTINGS_FIELD_BASIC;
104
+ $this->page = isset( $_GET['page'] ) ? $_GET['page'] : '';
105
+
106
+ add_action( 'admin_menu', [ $this, 'create_menu' ] );
107
+ add_filter( 'plugin_action_links_' . plugin_basename( OMGF_PLUGIN_FILE ), [ $this, 'create_settings_link' ] );
108
+
109
+ if ( $this->page !== 'optimize-webfonts' ) {
110
+ return;
111
+ }
112
+
113
+ // Tabs
114
+ add_action( 'omgf_settings_tab', [ $this, 'basic_settings_tab' ], 0 );
115
+ add_action( 'omgf_settings_tab', [ $this, 'advanced_settings_tab' ], 1 );
116
+
117
+ // Content
118
+ add_action( 'omgf_settings_content', [ $this, 'basic_settings_content' ], 0 );
119
+ add_action( 'omgf_settings_content', [ $this, 'advanced_settings_content' ], 1 );
120
+ }
121
+
122
+ /**
123
+ * Creates the menu item.
124
+ */
125
+ public function create_menu () {
126
+ add_options_page(
127
+ 'OMGF',
128
+ 'Optimize Google Fonts',
129
+ 'manage_options',
130
+ 'optimize-webfonts',
131
+ [ $this, 'create_settings_page' ]
132
+ );
133
+
134
+ // @formatter:off
135
+ add_action( 'admin_init', [ $this, 'register_settings' ] );
136
+ // @formatter:on
137
+ }
138
+
139
+ /**
140
+ * Display the settings page.
141
+ */
142
+ public function create_settings_page () {
143
+ if ( ! current_user_can( 'manage_options' ) ) {
144
+ wp_die( __( "You're not cool enough to access this page.", $this->plugin_text_domain ) );
145
+ }
146
+ ?>
147
+ <div class="wrap omgf">
148
+ <h1><?= apply_filters( 'omgf_settings_page_title', __( 'OMGF | Optimize My Google Fonts', $this->plugin_text_domain ) ); ?></h1>
149
 
150
  <p>
151
+ <?= get_plugin_data( OMGF_PLUGIN_FILE )['Description']; ?>
152
  </p>
153
 
154
  <div class="settings-column left">
155
  <h2 class="omgf-nav nav-tab-wrapper">
156
+ <?php do_action( 'omgf_settings_tab' ); ?>
157
  </h2>
158
+
159
+ <?php do_action( 'omgf_settings_content' ); ?>
160
  </div>
161
 
162
  <div class="settings-column right">
163
  <div id="omgf-welcome-panel" class="welcome-panel">
164
+ <?php $this->get_template( 'welcome' ); ?>
165
  </div>
166
  </div>
167
  </div>
168
+ <?php
169
+ }
170
+
171
+ /**
172
+ * Register all settings.
173
+ *
174
+ * @throws ReflectionException
175
+ */
176
+ public function register_settings () {
177
+ if ( $this->active_tab !== self::OMGF_SETTINGS_FIELD_BASIC
178
+ && $this->active_tab !== self::OMGF_SETTINGS_FIELD_ADVANCED ) {
179
+ $this->active_tab = self::OMGF_SETTINGS_FIELD_BASIC;
180
+ }
181
+
182
+ foreach ( $this->get_settings() as $constant => $value ) {
183
+ register_setting(
184
+ $this->active_tab,
185
+ $value
186
+ );
187
+ }
188
+ }
189
+
190
+ /**
191
+ * Get all settings using the constants in this class.
192
+ *
193
+ * @return array
194
+ * @throws ReflectionException
195
+ */
196
+ public function get_settings () {
197
+ $reflection = new ReflectionClass( $this );
198
+ $constants = apply_filters( 'omgf_settings_constants', $reflection->getConstants() );
199
+
200
+ switch ( $this->active_tab ) {
201
+ case ( self::OMGF_SETTINGS_FIELD_BASIC ):
202
+ $needle = 'OMGF_BASIC_SETTING_';
203
+ break;
204
+ default:
205
+ $needle = 'OMGF_ADV_SETTING';
206
+ }
207
+
208
+ return array_filter(
209
+ $constants,
210
+ function ( $key ) use ( $needle ) {
211
+ return strpos( $key, $needle ) !== false;
212
+ },
213
+ ARRAY_FILTER_USE_KEY
214
+ );
215
+ }
216
+
217
+ /**
218
+ * Add Basic Settings Tab to Settings Screen.
219
+ */
220
+ public function basic_settings_tab () {
221
+ $this->generate_tab( self::OMGF_SETTINGS_FIELD_BASIC, 'dashicons-analytics', __( 'Basic Settings', $this->plugin_text_domain ) );
222
+ }
223
+
224
+ /**
225
+ * Add Advanced Settings Tab to Settings Screen.
226
+ */
227
+ public function advanced_settings_tab () {
228
+ $this->generate_tab( self::OMGF_SETTINGS_FIELD_ADVANCED, 'dashicons-admin-settings', __( 'Advanced Settings', $this->plugin_text_domain ) );
229
+ }
230
+
231
+ /**
232
+ * @param $id
233
+ * @param null $icon
234
+ * @param null $label
235
+ */
236
+ private function generate_tab ( $id, $icon = null, $label = null ) {
237
+ ?>
238
+ <a class="nav-tab dashicons-before <?= $icon; ?> <?= $this->active_tab == $id ? 'nav-tab-active' : ''; ?>"
239
+ href="<?= $this->generate_tab_link( $id ); ?>">
240
+ <?= $label; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  </a>
242
+ <?php
243
+ }
244
+
245
+ /**
246
+ * @param $tab
247
+ *
248
+ * @return string
249
+ */
250
+ private function generate_tab_link ( $tab ) {
251
+ return admin_url( "options-general.php?page=optimize-webfonts&tab=$tab" );
252
+ }
253
+
254
+ /**
255
+ * Render Basic Settings content
256
+ */
257
+ public function basic_settings_content () {
258
+ $this->do_settings_content( self::OMGF_SETTINGS_FIELD_BASIC );
259
+ }
260
+
261
+ /**
262
+ * Render Advanced Settings content
263
+ */
264
+ public function advanced_settings_content () {
265
+ $this->do_settings_content( self::OMGF_SETTINGS_FIELD_ADVANCED );
266
+ }
267
+
268
+ /**
269
+ * @param $field
270
+ */
271
+ private function do_settings_content ( $field ) {
272
+ if ( $this->active_tab != $field ) {
273
+ return;
274
+ }
275
+ ?>
276
+ <form id="<?= $field; ?>-form" name="omgf-settings-form" method="post" action="<?= admin_url('options.php?tab=' . $this->active_tab); ?>">
277
+ <?php
278
+ settings_fields( $field );
279
+ do_settings_sections( $field );
280
+
281
+ do_action( 'omgf_before_settings_form_settings' );
282
+
283
+ echo apply_filters( str_replace( '-', '_', $field ) . '_content', '' );
284
+
285
+ do_action( 'omgf_after_settings_form_settings' );
286
+
287
+ submit_button(__('Save Changes', $this->plugin_text_domain), 'primary', 'submit', false);
288
+ ?>
289
+ <a id="omgf-empty" class="omgf-empty button-cancel"><?php _e('Empty Cache Directory', $this->plugin_text_domain); ?></a>
290
  </form>
291
+ <?php
292
+ }
293
+
294
+ /**
295
+ * @param $links
296
+ *
297
+ * @return mixed
298
+ */
299
+ public function create_settings_link ( $links ) {
300
+ $adminUrl = admin_url() . 'options-general.php?page=optimize-webfonts';
301
+ $settingsLink = "<a href='$adminUrl'>" . __( 'Settings' ) . "</a>";
302
+ array_push( $links, $settingsLink );
303
+
304
+ return $links;
305
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306
  }
includes/admin/settings/class-advanced.php CHANGED
@@ -14,223 +14,174 @@
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
- defined('ABSPATH') || exit;
18
 
19
  class OMGF_Admin_Settings_Advanced extends OMGF_Admin_Settings_Builder
20
  {
21
- /** @var string $utmTags */
22
- private $utmTags = '?utm_source=omgf&utm_medium=plugin&utm_campaign=settings';
23
-
24
- /**
25
- * OMGF_Admin_Settings_Advanced constructor.
26
- */
27
- public function __construct()
28
- {
29
- $this->title = __('Advanced Settings', $this->plugin_text_domain);
30
-
31
- // Open
32
- // @formatter:off
33
- add_filter('omgf_advanced_settings_content', [$this, 'do_title'], 10);
34
- add_filter('omgf_advanced_settings_content', [$this, 'do_description'], 15);
35
- add_filter('omgf_advanced_settings_content', [$this, 'do_before'], 20);
36
-
37
- // Settings
38
- add_filter('omgf_advanced_settings_content', [$this, 'do_remove_google_fonts'], 25);
39
- add_filter('omgf_advanced_settings_content', [$this, 'do_display_option'], 30);
40
- add_filter('omgf_advanced_settings_content', [$this, 'do_cache_dir'], 35);
41
- add_filter('omgf_advanced_settings_content', [$this, 'do_cache_uri'], 40);
42
- add_filter('omgf_advanced_settings_content', [$this, 'do_force_ssl'], 45);
43
- add_filter('omgf_advanced_settings_content', [$this, 'do_relative_url'], 50);
44
- add_filter('omgf_advanced_settings_content', [$this, 'do_cdn_url'], 55);
45
- add_filter('omgf_advanced_settings_content', [$this, 'do_webfont_loader'], 60);
46
- add_filter('omgf_advanced_settings_content', [$this, 'do_remove_version'], 65);
47
- add_filter('omgf_advanced_settings_content', [$this, 'do_enqueue_order'], 70);
48
- add_filter('omgf_advanced_settings_content', [$this, 'do_optimize_edit_roles'], 75);
49
- add_filter('omgf_advanced_settings_content', [$this, 'do_uninstall'], 80);
50
-
51
- // Close
52
- add_filter('omgf_advanced_settings_content', [$this, 'do_after'], 100);
53
- // @formatter:on
54
- }
55
-
56
- /**
57
- * Description
58
- */
59
- public function do_description()
60
- {
61
- ?>
62
  <p>
63
- <?php _e('* <strong>Generate stylesheet</strong> after changing this setting.', $this->plugin_text_domain); ?>
64
- <br/>
65
- <?php _e('** <strong>Download Fonts</strong> and <strong>Generate Stylesheet</strong> after changing this setting.', $this->plugin_text_domain); ?>
66
  </p>
67
- <?php
68
- }
69
-
70
- /**
71
- *
72
- */
73
- public function do_remove_google_fonts()
74
- {
75
- $this->do_checkbox(
76
- __('Auto Remove', $this->plugin_text_domain),
77
- OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_GOOGLE_FONTS,
78
- OMGF_REMOVE_GFONTS,
79
- sprintf(__('Remove any requests to externally hosted Google Fonts-stylesheets from your WordPress-blog. If it doesn\'t work, your theme and/or plugin(s) are using unconventional methods or Web Font Loader to load Google Fonts. <a href="%s" target="_blank">Upgrade to OMGF Pro</a> to automatically remove Google Fonts incl. resource hints (e.g. <code>dns-prefetch</code>, <code>preconnect</code> and <code>preload</code>).', $this->plugin_text_domain), self::WOOSH_WORDPRESS_PLUGINS_HOST_GOOGLE_FONTS_PRO . $this->utmTags)
80
- );
81
- }
82
-
83
- /**
84
- *
85
- */
86
- public function do_display_option()
87
- {
88
- $this->do_select(
89
- __('Font-display option', $this->plugin_text_domain),
90
- OMGF_Admin_Settings::OMGF_ADV_SETTING_DISPLAY_OPTION,
91
- OMGF_Admin_Settings::OMGF_FONT_DISPLAY_OPTIONS,
92
- OMGF_DISPLAY_OPTION,
93
- __('Select which font-display strategy to use. Defaults to Swap (recommended).', $this->plugin_text_domain),
94
- '*'
95
- );
96
- }
97
-
98
- /**
99
- *
100
- */
101
- public function do_cache_dir()
102
- {
103
- $this->do_text(
104
- __('Save font files to...', $this->plugin_text_domain),
105
- OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH,
106
- __('e.g. /uploads/omgf', $this->plugin_text_domain),
107
- OMGF_CACHE_PATH,
108
- __("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>/uploads/omgf</code>. After changing this setting, the folder will be created if it doesn't exist and existing files will be moved automatically.", $this->plugin_text_domain),
109
- '**'
110
- );
111
- }
112
-
113
- /**
114
- *
115
- */
116
- public function do_cache_uri()
117
- {
118
- $this->do_text(
119
- __('Serve font files from...', $this->plugin_text_domain),
120
- OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI,
121
- __('e.g. /app/uploads/omgf', $this->plugin_text_domain),
122
- OMGF_CACHE_URI,
123
- __('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.', $this->plugin_text_domain),
124
- '**'
125
- );
126
- }
127
-
128
- /**
129
- *
130
- */
131
- public function do_force_ssl()
132
- {
133
- $this->do_checkbox(
134
- __('Force SSL?', $this->plugin_text_domain),
135
- OMGF_Admin_Settings::OMGF_ADV_SETTING_FORCE_SSL,
136
- OMGF_FORCE_SSL,
137
- __('Some plugins mess up WordPress\' URL structure, which can cause OMGF to generate incorrect URLs in the stylesheet. If OMGF is generating non-SSL (<code>http://...</code>) URLs in the stylesheet, and you have the <strong>Site</strong> and <strong>WordPress Address</strong> (in <strong>Settings</strong> > <strong>General</strong>) set to SSL (<code>https://</code>), then enable this option.', $this->plugin_text_domain),
138
- '**'
139
- );
140
- }
141
-
142
- /**
143
- *
144
- */
145
- public function do_relative_url()
146
- {
147
- $this->do_checkbox(
148
- __('Use Relative URLs?', $this->plugin_text_domain),
149
- OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL,
150
- OMGF_RELATIVE_URL,
151
- __('Use relative instead of absolute (full) URLs to generate the stylesheet. <strong>Warning!</strong> This disables the CDN URL!', $this->plugin_text_domain),
152
- '**'
153
- );
154
- }
155
-
156
- /**
157
- *
158
- */
159
- public function do_cdn_url()
160
- {
161
- $this->do_text(
162
- __('Serve fonts from CDN', $this->plugin_text_domain),
163
- OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL,
164
- __('e.g. cdn.mydomain.com', $this->plugin_text_domain),
165
- OMGF_CDN_URL,
166
- __("Are you using a CDN? Then enter the URL here. Leave empty when using CloudFlare.", $this->plugin_text_domain),
167
- '**'
168
- );
169
- }
170
-
171
- /**
172
- *
173
- */
174
- public function do_webfont_loader()
175
- {
176
- $this->do_checkbox(
177
- __('Use Web Font Loader?', $this->plugin_text_domain),
178
- OMGF_Admin_Settings::OMGF_ADV_SETTING_WEB_FONT_LOADER,
179
- OMGF_WEB_FONT_LOADER,
180
- __('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.', $this->plugin_text_domain)
181
- );
182
- }
183
-
184
- /**
185
- *
186
- */
187
- public function do_remove_version()
188
- {
189
- $this->do_checkbox(
190
- __('Remove version parameter?', $this->plugin_text_domain),
191
- OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_VERSION,
192
- OMGF_REMOVE_VERSION,
193
- __('This removes the <code>?ver=x.x.x</code> parameter from the Stylesheet\'s (<code>fonts.css</code>) request. ', $this->plugin_text_domain)
194
- );
195
- }
196
-
197
- /**
198
- *
199
- */
200
- public function do_enqueue_order()
201
- {
202
- $this->do_number(
203
- __('Change enqueue order of stylesheet? (experimental)', $this->plugin_text_domain),
204
- OMGF_Admin_Settings::OMGF_ADV_SETTING_ENQUEUE_ORDER,
205
- OMGF_ENQUEUE_ORDER,
206
- __('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.', $this->plugin_text_domain),
207
- 0
208
- );
209
- }
210
-
211
- /**
212
- *
213
- */
214
- public function do_optimize_edit_roles()
215
- {
216
- $this->do_checkbox(
217
- __('Optimize fonts for logged in editors/administrators?', $this->plugin_text_domain),
218
- OMGF_Admin_Settings::OMGF_ADV_SETTING_OPTIMIZE_EDIT_ROLES,
219
- OMGF_OPTIMIZE_EDIT_ROLES,
220
- __('Should only be used for debugging/testing purposes. Leave disabled when e.g. using a page builder or switching themes.', $this->plugin_text_domain)
221
- );
222
- }
223
-
224
- /**
225
- *
226
- */
227
- public function do_uninstall()
228
- {
229
- $this->do_checkbox(
230
- __('Remove settings and files at uninstall?', $this->plugin_text_domain),
231
- OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL,
232
- OMGF_UNINSTALL,
233
- __('Warning! This will remove all settings and cached fonts upon plugin deletion.', $this->plugin_text_domain)
234
- );
235
- }
236
  }
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
+ defined( 'ABSPATH' ) || exit;
18
 
19
  class OMGF_Admin_Settings_Advanced extends OMGF_Admin_Settings_Builder
20
  {
21
+ /**
22
+ * OMGF_Admin_Settings_Advanced constructor.
23
+ */
24
+ public function __construct () {
25
+ parent::__construct();
26
+
27
+ $this->title = __( 'Advanced Settings', $this->plugin_text_domain );
28
+
29
+ // Open
30
+ add_filter( 'omgf_advanced_settings_content', [ $this, 'do_title' ], 10 );
31
+ add_filter( 'omgf_advanced_settings_content', [ $this, 'do_description' ], 15 );
32
+ add_filter( 'omgf_advanced_settings_content', [ $this, 'do_before' ], 20 );
33
+
34
+ // Settings
35
+ add_filter( 'omgf_advanced_settings_content', [ $this, 'do_promo_fonts_processing' ], 50 );
36
+ add_filter( 'omgf_advanced_settings_content', [ $this, 'do_promo_process_resource_hints' ], 60 );
37
+ add_filter( 'omgf_advanced_settings_content', [ $this, 'do_promo_force_subsets' ], 70 );
38
+ add_filter( 'omgf_advanced_settings_content', [ $this, 'do_cdn_url' ], 80 );
39
+ add_filter( 'omgf_advanced_settings_content', [ $this, 'do_cache_uri' ], 90 );
40
+ add_filter( 'omgf_advanced_settings_content', [ $this, 'do_relative_url' ], 100 );
41
+ add_filter( 'omgf_advanced_settings_content', [ $this, 'do_uninstall' ], 110 );
42
+
43
+ // Close
44
+ add_filter( 'omgf_advanced_settings_content', [ $this, 'do_after' ], 200 );
45
+ }
46
+
47
+ /**
48
+ * Description
49
+ */
50
+ public function do_description () {
51
+ ?>
 
 
 
 
 
 
 
 
 
 
52
  <p>
 
 
 
53
  </p>
54
+ <?php
55
+ }
56
+
57
+ /**
58
+ *
59
+ */
60
+ public function do_promo_fonts_processing () {
61
+ ?>
62
+ <tr>
63
+ <th scope="row"><?= __( 'Google Fonts Processing (Pro)', $this->plugin_text_domain ); ?></th>
64
+ <td>
65
+ <fieldset id="" class="scheme-list">
66
+ <?php foreach ( $this->fonts_processing_pro_options() as $name => $data ): ?>
67
+ <?php
68
+ $checked = defined( strtoupper( $name ) ) ? constant( strtoupper( $name ) ) : false;
69
+ $disabled = apply_filters( $name . '_setting_disabled', true ) ? 'disabled' : '';
70
+ ?>
71
+ <label for="<?= $name; ?>">
72
+ <input type="checkbox" name="<?= $name; ?>" <?= $checked ? 'checked="checked"' : ''; ?> <?= $disabled; ?> /><?= $data['label']; ?>
73
+ &nbsp;
74
+ </label>
75
+ <?php endforeach; ?>
76
+ </fieldset>
77
+ <p class="description">
78
+ <?= $this->promo; ?>
79
+ <ul>
80
+ <?php foreach ( $this->fonts_processing_pro_options() as $name => $data ): ?>
81
+ <li><strong><?= $data['label']; ?></strong>: <?= $data['description']; ?></li>
82
+ <?php endforeach; ?>
83
+ </ul>
84
+ </p>
85
+ </td>
86
+ </tr>
87
+ <?php
88
+ }
89
+
90
+ /**
91
+ * @return array
92
+ */
93
+ private function fonts_processing_pro_options () {
94
+ return [
95
+ 'omgf_pro_process_stylesheets' => [
96
+ 'label' => __( 'Process Stylesheets', $this->plugin_text_domain ),
97
+ 'description' => __( 'Process stylesheets loaded from <code>fonts.googleapis.com</code> or <code>fonts.gstatic.com</code>.', $this->plugin_text_domain )
98
+ ],
99
+ 'omgf_pro_process_inline_styles' => [
100
+ 'label' => __( 'Process Inline Styles', $this->plugin_text_domain ),
101
+ 'description' => __( 'Process all <code>@font-face</code> and <code>@import</code> rules loading Google Fonts.', $this->plugin_text_domain )
102
+ ],
103
+ 'omgf_pro_process_webfont_loader' => [
104
+ 'label' => __( 'Process Webfont Loader', $this->plugin_text_domain ),
105
+ 'description' => __( 'Process <code>webfont.js</code> libraries and the corresponding configuration defining which Google Fonts to load.', $this->plugin_text_domain )
106
+ ]
107
+ ];
108
+ }
109
+
110
+ /**
111
+ *
112
+ */
113
+ public function do_promo_process_resource_hints () {
114
+ $this->do_checkbox(
115
+ __( 'Remove Resource Hints (Pro)', $this->plugin_text_domain ),
116
+ 'omgf_pro_process_resource_hints',
117
+ defined( 'OMGF_PRO_PROCESS_RESOURCE_HINTS' ) ? OMGF_PRO_PROCESS_RESOURCE_HINTS : false,
118
+ __( 'Remove all <code>link</code> elements with a <code>rel</code> attribute value of <code>dns-prefetch</code>, <code>preload</code> or <code>preconnect</code> pointing to <code>fonts.googleapis.com</code> or <code>fonts.gstatic.com</code>.', $this->plugin_text_domain ) . ' ' . $this->promo,
119
+ true
120
+ );
121
+ }
122
+
123
+ /**
124
+ *
125
+ */
126
+ public function do_promo_force_subsets () {
127
+ $this->do_select(
128
+ __( 'Force Subsets (Pro)', $this->plugin_text_domain ),
129
+ 'omgf_pro_force_subsets',
130
+ OMGF_Admin_Settings::OMGF_FORCE_SUBSETS_OPTIONS,
131
+ defined( 'OMGF_PRO_FORCE_SUBSETS' ) ? OMGF_PRO_FORCE_SUBSETS : [],
132
+ __( 'If a theme or plugin loads subsets you don\'t need, use this option to force all Google Fonts to be loaded in the selected subsets.', $this->plugin_text_domain ) . ' ' . $this->promo,
133
+ true,
134
+ true
135
+ );
136
+ }
137
+
138
+ /**
139
+ *
140
+ */
141
+ public function do_cache_uri () {
142
+ $this->do_text(
143
+ __( 'Serve font files from...', $this->plugin_text_domain ),
144
+ OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI,
145
+ __( 'e.g. /app/uploads/omgf', $this->plugin_text_domain ),
146
+ OMGF_CACHE_URI,
147
+ __( '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 under Basic Settings will be used.', $this->plugin_text_domain )
148
+ );
149
+ }
150
+
151
+ /**
152
+ *
153
+ */
154
+ public function do_relative_url () {
155
+ $this->do_checkbox(
156
+ __( 'Use Relative URLs?', $this->plugin_text_domain ),
157
+ OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL,
158
+ OMGF_RELATIVE_URL,
159
+ __( 'Use relative instead of absolute (full) URLs to generate the stylesheet.', $this->plugin_text_domain )
160
+ );
161
+ }
162
+
163
+ /**
164
+ *
165
+ */
166
+ public function do_cdn_url () {
167
+ $this->do_text(
168
+ __( 'Serve fonts from CDN', $this->plugin_text_domain ),
169
+ OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL,
170
+ __( 'e.g. https://cdn.mydomain.com', $this->plugin_text_domain ),
171
+ OMGF_CDN_URL,
172
+ __( "If you're using a CDN, enter the URL here incl. protocol (e.g. <code>https://</code>.) Leave empty when using CloudFlare.", $this->plugin_text_domain )
173
+ );
174
+ }
175
+
176
+ /**
177
+ *
178
+ */
179
+ public function do_uninstall () {
180
+ $this->do_checkbox(
181
+ __( 'Remove settings and files at uninstall?', $this->plugin_text_domain ),
182
+ OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL,
183
+ OMGF_UNINSTALL,
184
+ __( 'Warning! This will remove all settings and cached fonts upon plugin deletion.', $this->plugin_text_domain )
185
+ );
186
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  }
includes/admin/settings/class-basic.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* * * * * * * * * * * * * * * * * * * * *
3
+ *
4
+ * ██████╗ ███╗ ███╗ ██████╗ ███████╗
5
+ * ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
6
+ * ██║ ██║██╔████╔██║██║ ███╗█████╗
7
+ * ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
8
+ * ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
9
+ * ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
10
+ *
11
+ * @package : OMGF
12
+ * @author : Daan van den Bergh
13
+ * @copyright: (c) 2020 Daan van den Bergh
14
+ * @url : https://daan.dev
15
+ * * * * * * * * * * * * * * * * * * * */
16
+
17
+ defined( 'ABSPATH' ) || exit;
18
+
19
+ class OMGF_Admin_Settings_Basic extends OMGF_Admin_Settings_Builder
20
+ {
21
+ public function __construct () {
22
+ parent::__construct();
23
+
24
+ $this->title = __( 'Basic Settings', $this->plugin_text_domain );
25
+
26
+ // Open
27
+ add_filter( 'omgf_basic_settings_content', [ $this, 'do_title' ], 10 );
28
+ add_filter( 'omgf_basic_settings_content', [ $this, 'do_description' ], 15 );
29
+ add_filter( 'omgf_basic_settings_content', [ $this, 'do_before' ], 20 );
30
+
31
+ // Settings
32
+ add_filter( 'omgf_basic_settings_content', [ $this, 'do_process_google_fonts' ], 30 );
33
+ add_filter( 'omgf_basic_settings_content', [ $this, 'do_promo_advanced_processing' ], 40 );
34
+ add_filter( 'omgf_basic_settings_content', [ $this, 'do_display_option' ], 50 );
35
+ add_filter( 'omgf_basic_settings_content', [ $this, 'do_promo_combine_requests' ], 60 );
36
+ add_filter( 'omgf_basic_settings_content', [ $this, 'do_cache_dir' ], 70 );
37
+ add_filter( 'omgf_basic_settings_content', [ $this, 'do_optimize_edit_roles' ], 80 );
38
+
39
+ // Close
40
+ add_filter( 'omgf_basic_settings_content', [ $this, 'do_after' ], 100 );
41
+ }
42
+
43
+ /**
44
+ * Description
45
+ */
46
+ public function do_description () {
47
+ ?>
48
+ <p>
49
+ * <?= __( 'If you\'re looking to replace your Google Fonts for locally hosted copies, then the default settings will suffice. OMGF will run silently in the background and download any Google Fonts while you and/or your visitors are browsing your site.', $this->plugin_text_domain ); ?>
50
+ </p>
51
+ <p>
52
+ <?= __( 'If <strong>Google Fonts Processing</strong> is set to Replace, loading the locally hosted stylesheet for the first time (or after emptying OMGF\'s cache directory) might take a few seconds. This depends on your server\'s capacity and the size of the stylesheet. This is because OMGF\'s Download API captures the request and automatically downloads the fonts, before serving the local copy. Once the stylesheet and fonts are downloaded, every consecutive request will be fast again.', $this->plugin_text_domain ); ?>
53
+ </p>
54
+ <?php
55
+ }
56
+
57
+ /**
58
+ *
59
+ */
60
+ public function do_process_google_fonts () {
61
+ $this->do_select(
62
+ __( 'Google Fonts Processing', $this->plugin_text_domain ),
63
+ OMGF_Admin_Settings::OMGF_BASIC_SETTING_FONT_PROCESSING,
64
+ OMGF_Admin_Settings::OMGF_FONT_PROCESSING_OPTIONS,
65
+ OMGF_FONT_PROCESSING,
66
+ sprintf( __( "Choose whether OMGF should (find, download and) <strong>replace</strong> all Google Fonts, or just <strong>remove</strong> them. Choosing Remove will force WordPress to fallback to system fonts or install your own.", $this->plugin_text_domain ), self::FFWP_WORDPRESS_PLUGINS_OMGF_PRO )
67
+ );
68
+ }
69
+
70
+ /**
71
+ *
72
+ */
73
+ public function do_promo_advanced_processing () {
74
+ $this->do_checkbox(
75
+ __( 'Advanced Processing (Pro)', $this->plugin_text_domain ),
76
+ 'omgf_pro_advanced_processing',
77
+ defined( 'OMGF_PRO_ADVANCED_PROCESSING' ) ? true : false,
78
+ __( 'By default, OMGF scans for Google Fonts which are registered/enqueued in the <code>wp_enqueue_scripts()</code> action in WordPress\' header (<code>wp_head()</code>). Advanced Processing will process all Google Fonts throughout the entire document. This setting can be tweaked further under Advanced Settings.', $this->plugin_text_domain ) . ' ' . $this->promo,
79
+ true
80
+ );
81
+ }
82
+
83
+ /**
84
+ *
85
+ */
86
+ public function do_display_option () {
87
+ $this->do_select(
88
+ __( 'Font-display option', $this->plugin_text_domain ),
89
+ OMGF_Admin_Settings::OMGF_BASIC_SETTING_DISPLAY_OPTION,
90
+ OMGF_Admin_Settings::OMGF_FONT_DISPLAY_OPTIONS,
91
+ OMGF_DISPLAY_OPTION,
92
+ __( 'Select which font-display strategy to use. Defaults to Swap (recommended).', $this->plugin_text_domain )
93
+ );
94
+ }
95
+
96
+ /**
97
+ *
98
+ */
99
+ public function do_promo_combine_requests () {
100
+ $this->do_checkbox(
101
+ __( 'Combine & Dedupe Google Fonts (Pro)', $this->plugin_text_domain ),
102
+ 'omgf_pro_combine_requests',
103
+ defined( 'OMGF_PRO_COMBINE_REQUESTS' ) ? true : false,
104
+ __( 'Combine and deduplicate multiple font requests into one request. This feature is always on in OMGF Pro and can\'t be disabled.', $this->plugin_text_domain ) . ' ' . $this->promo,
105
+ true
106
+ );
107
+ }
108
+
109
+ /**
110
+ *
111
+ */
112
+ public function do_cache_dir () {
113
+ $this->do_text(
114
+ __( 'Save font files to...', $this->plugin_text_domain ),
115
+ OMGF_Admin_Settings::OMGF_BASIC_SETTING_CACHE_PATH,
116
+ __( 'e.g. /uploads/omgf', $this->plugin_text_domain ),
117
+ OMGF_CACHE_PATH,
118
+ __( "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>/uploads/omgf</code>. After changing this setting, the folder will be created if it doesn't exist and existing files will be moved automatically.", $this->plugin_text_domain )
119
+ );
120
+ }
121
+
122
+ /**
123
+ *
124
+ */
125
+ public function do_optimize_edit_roles () {
126
+ $this->do_checkbox(
127
+ __( 'Optimize fonts for logged in editors/administrators?', $this->plugin_text_domain ),
128
+ OMGF_Admin_Settings::OMGF_BASIC_SETTING_OPTIMIZE_EDIT_ROLES,
129
+ OMGF_OPTIMIZE_EDIT_ROLES,
130
+ __( 'Should only be disabled while debugging/testing, e.g. using a page builder or switching themes.', $this->plugin_text_domain )
131
+ );
132
+ }
133
+ }
includes/admin/settings/class-builder.php CHANGED
@@ -14,151 +14,173 @@
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
- defined('ABSPATH') || exit;
18
 
19
  class OMGF_Admin_Settings_Builder
20
  {
21
- const WOOSH_WORDPRESS_PLUGINS_HOST_GOOGLE_FONTS_PRO = 'https://woosh.dev/wordpress-plugins/host-google-fonts-pro/#get-omgf-pro';
22
-
23
- /** @var string $plugin_text_domain */
24
- protected $plugin_text_domain = 'host-webfonts-local';
25
-
26
- /** @var $title */
27
- protected $title;
28
-
29
- /**
 
 
 
 
30
  *
31
- */
32
- public function do_before()
33
- {
34
- ?>
35
- <table class="form-table">
36
- <?php
37
  }
38
-
39
- /**
40
- *
41
- */
42
- public function do_after()
43
- {
44
- ?>
45
- </table>
46
- <?php
47
  }
48
-
49
- /**
50
- *
51
- */
52
- public function do_title()
53
- {
54
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  <h3><?= $this->title ?></h3>
56
- <?php
57
- }
58
-
59
- /**
60
- * Generate select setting
61
- *
62
- * @param $label
63
- * @param $select
64
- * @param $options
65
- * @param $selected
66
- * @param $description
67
- * @param bool $update_required
68
- */
69
- public function do_select($label, $select, $options, $selected, $description, $update_required = false)
70
- {
71
- ?>
72
  <tr>
73
  <th scope="row">
74
- <?= apply_filters($select . '_setting_label', $label); ?> <?= $update_required ?: ''; ?>
75
  </th>
76
  <td>
77
- <select name="<?= $select; ?>" class="<?= str_replace('_', '-', $select); ?>">
 
 
 
 
78
  <?php
79
- $options = apply_filters($select . '_setting_options', $options);
 
 
 
 
80
  ?>
81
- <?php foreach ($options as $option => $option_label): ?>
82
- <option value="<?= $option; ?>" <?= ($selected == $option) ? 'selected' : ''; ?>><?= $option_label; ?></option>
83
- <?php endforeach; ?>
84
  </select>
85
  <p class="description">
86
- <?= apply_filters($select . '_setting_description', $description); ?>
87
  </p>
88
  </td>
89
  </tr>
90
- <?php
91
- }
92
-
93
- /**
94
- * Generate number setting.
95
- *
96
- * @param $label
97
- * @param $name
98
- * @param $value
99
- * @param $description
100
- */
101
- public function do_number($label, $name, $value, $description, $min = 0)
102
- {
103
- ?>
104
  <tr valign="top">
105
- <th scope="row"><?= apply_filters($name . '_setting_label', $label); ?></th>
106
  <td>
107
- <input class="<?= str_replace('_', '-', $name); ?>" type="number" name="<?= $name; ?>" min="<?= $min; ?>" value="<?= $value; ?>"/>
108
  <p class="description">
109
- <?= apply_filters($name . '_setting_description', $description); ?>
110
  </p>
111
  </td>
112
  </tr>
113
- <?php
114
- }
115
-
116
- /**
117
- * Generate text setting.
118
- *
119
- * @param $label
120
- * @param $name
121
- * @param $placeholder
122
- * @param $value
123
- * @param string $description
124
- * @param bool $update_required
125
- */
126
- public function do_text($label, $name, $placeholder, $value, $description = '', $update_required = false, $visible = true)
127
- {
128
- ?>
129
- <tr class="<?= str_replace('_', '-', $name); ?>-row" <?= $visible ? '' : 'style="display: none;"'; ?>>
130
- <th scope="row"><?= apply_filters($name . '_setting_label', $label); ?> <?= $update_required ?: ''; ?></th>
131
  <td>
132
- <input class="<?= str_replace('_', '-', $name); ?>" type="text" name="<?= $name; ?>" placeholder="<?= $placeholder; ?>" value="<?= $value; ?>"/>
 
133
  <p class="description">
134
- <?= apply_filters($name . 'setting_description', $description); ?>
135
  </p>
136
  </td>
137
  </tr>
138
- <?php
139
- }
140
-
141
- /**
142
- * Generate checkbox setting.
143
- *
144
- * @param $label
145
- * @param $name
146
- * @param $checked
147
- * @param $description
148
- */
149
- public function do_checkbox($label, $name, $checked, $description, $update_required = false, $disabled = false)
150
- {
151
- ?>
152
  <tr>
153
- <th scope="row"><?= apply_filters($name . '_setting_label', $label); ?> <?= $update_required ?: ''; ?></th>
154
  <td>
155
- <input type="checkbox" <?= apply_filters($name . '_setting_disabled', $disabled) ? 'disabled' : ''; ?> class="<?= str_replace('_' , '-' , $name); ?>" name="<?= $name; ?>"
156
- <?= $checked == "on" ? 'checked = "checked"' : ''; ?> />
157
- <p class="description">
158
- <?= apply_filters($name . '_setting_description', $description); ?>
159
- </p>
160
  </td>
161
  </tr>
162
- <?php
163
- }
164
  }
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
+ defined( 'ABSPATH' ) || exit;
18
 
19
  class OMGF_Admin_Settings_Builder
20
  {
21
+ const FFWP_WORDPRESS_PLUGINS_OMGF_PRO = 'https://ffwp.dev/wordpress/omgf-pro/';
22
+
23
+ /** @var string $plugin_text_domain */
24
+ protected $plugin_text_domain = 'host-webfonts-local';
25
+
26
+ /** @var $title */
27
+ protected $title;
28
+
29
+ /** @var $promo string */
30
+ protected $promo;
31
+
32
+ /**
33
+ * Only sets the promo string on settings load.
34
  *
35
+ * OMGF_Admin_Settings_Builder constructor.
36
+ */
37
+ public function __construct () {
38
+ add_filter('omgf_basic_settings_content', [ $this, 'do_promo' ]);
39
+ add_filter('omgf_advanced_settings_content', [ $this, 'do_promo' ]);
 
40
  }
41
+
42
+ /**
43
+ *
44
+ */
45
+ public function do_promo () {
46
+ if (apply_filters('apply_omgf_pro_promo', true)) {
47
+ $this->promo = apply_filters('omgf_pro_promo', sprintf(__('<a href="%s" target="_blank">Upgrade to Pro</a> to enable this option.', $this->plugin_text_domain), self::FFWP_WORDPRESS_PLUGINS_OMGF_PRO));
48
+ }
 
49
  }
50
+
51
+ /**
52
+ *
53
+ */
54
+ public function do_before () {
55
+ ?>
56
+ <table class="form-table">
57
+ <?php
58
+ }
59
+
60
+ /**
61
+ *
62
+ */
63
+ public function do_after () {
64
+ ?>
65
+ </table>
66
+ <?php
67
+ }
68
+
69
+ /**
70
+ *
71
+ */
72
+ public function do_title () {
73
+ ?>
74
  <h3><?= $this->title ?></h3>
75
+ <?php
76
+ }
77
+
78
+ /**
79
+ * Generate select setting
80
+ *
81
+ * @param $label
82
+ * @param $name
83
+ * @param $options
84
+ * @param $selected
85
+ * @param $description
86
+ * @param bool $update_required
87
+ */
88
+ public function do_select ( $label, $name, $options, $selected, $description, $is_multiselect = false, $disabled = false ) {
89
+ ?>
 
90
  <tr>
91
  <th scope="row">
92
+ <?= apply_filters( $name . '_setting_label', $label ); ?>
93
  </th>
94
  <td>
95
+ <select name="<?= $name; ?><?= $is_multiselect ? '[]' : ''; ?>" class="<?= str_replace( '_', '-', $name ); ?>" <?= $is_multiselect ? 'size="10" multiple="multiple"' : ''; ?> <?= apply_filters( $name . '_setting_disabled', $disabled ) ? 'disabled' : ''; ?>>
96
+ <?php
97
+ $options = apply_filters( $name . '_setting_options', $options );
98
+ ?>
99
+ <?php foreach ( $options as $option => $option_label ): ?>
100
  <?php
101
+ if (is_array($selected)) {
102
+ $is_selected = in_array($option, $selected);
103
+ } else {
104
+ $is_selected = $selected == $option;
105
+ }
106
  ?>
107
+ <option value="<?= $option; ?>" <?= $is_selected ? 'selected="selected"' : ''; ?>><?= $option_label; ?></option>
108
+ <?php endforeach; ?>
 
109
  </select>
110
  <p class="description">
111
+ <?= apply_filters( $name . '_setting_description', $description ); ?>
112
  </p>
113
  </td>
114
  </tr>
115
+ <?php
116
+ }
117
+
118
+ /**
119
+ * Generate number setting.
120
+ *
121
+ * @param $label
122
+ * @param $name
123
+ * @param $value
124
+ * @param $description
125
+ */
126
+ public function do_number ( $label, $name, $value, $description, $min = 0 ) {
127
+ ?>
 
128
  <tr valign="top">
129
+ <th scope="row"><?= apply_filters( $name . '_setting_label', $label ); ?></th>
130
  <td>
131
+ <input class="<?= str_replace( '_', '-', $name ); ?>" type="number" name="<?= $name; ?>" min="<?= $min; ?>" value="<?= $value; ?>"/>
132
  <p class="description">
133
+ <?= apply_filters( $name . '_setting_description', $description ); ?>
134
  </p>
135
  </td>
136
  </tr>
137
+ <?php
138
+ }
139
+
140
+ /**
141
+ * Generate text setting.
142
+ *
143
+ * @param $label
144
+ * @param $name
145
+ * @param $placeholder
146
+ * @param $value
147
+ * @param string $description
148
+ * @param bool $update_required
149
+ */
150
+ public function do_text ( $label, $name, $placeholder, $value, $description = '', $update_required = false, $visible = true ) {
151
+ ?>
152
+ <tr class="<?= str_replace( '_', '-', $name ); ?>-row" <?= $visible ? '' : 'style="display: none;"'; ?>>
153
+ <th scope="row"><?= apply_filters( $name . '_setting_label', $label ); ?> <?= $update_required ?: ''; ?></th>
 
154
  <td>
155
+ <input class="<?= str_replace( '_', '-', $name ); ?>" type="text" name="<?= $name; ?>" placeholder="<?= $placeholder; ?>"
156
+ value="<?= $value; ?>"/>
157
  <p class="description">
158
+ <?= apply_filters( $name . 'setting_description', $description ); ?>
159
  </p>
160
  </td>
161
  </tr>
162
+ <?php
163
+ }
164
+
165
+ /**
166
+ * Generate checkbox setting.
167
+ *
168
+ * @param $label
169
+ * @param $name
170
+ * @param $checked
171
+ * @param $description
172
+ */
173
+ public function do_checkbox ( $label, $name, $checked, $description, $disabled = false ) {
174
+ ?>
 
175
  <tr>
176
+ <th scope="row"><?= apply_filters( $name . '_setting_label', $label ); ?></th>
177
  <td>
178
+ <label for="<?= $name; ?>">
179
+ <input id="<?= $name; ?>" type="checkbox" <?= apply_filters( $name . '_setting_disabled', $disabled ) ? 'disabled' : ''; ?> class="<?= str_replace( '_', '-', $name ); ?>" name="<?= $name; ?>" <?= $checked == "on" ? 'checked = "checked"' : ''; ?> />
180
+ <?= apply_filters( $name . '_setting_description', $description ); ?>
181
+ </label>
 
182
  </td>
183
  </tr>
184
+ <?php
185
+ }
186
  }
includes/admin/settings/class-extensions.php DELETED
@@ -1,119 +0,0 @@
1
- <?php
2
- /* * * * * * * * * * * * * * * * * * * * *
3
- *
4
- * ██████╗ ███╗ ███╗ ██████╗ ███████╗
5
- * ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
6
- * ██║ ██║██╔████╔██║██║ ███╗█████╗
7
- * ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
8
- * ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
9
- * ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
10
- *
11
- * @package : OMGF
12
- * @author : Daan van den Bergh
13
- * @copyright: (c) 2020 Daan van den Bergh
14
- * @url : https://daan.dev
15
- * * * * * * * * * * * * * * * * * * * */
16
-
17
- defined('ABSPATH') || exit;
18
-
19
- class OMGF_Admin_Settings_Extensions extends OMGF_Admin_Settings_Builder
20
- {
21
- /**
22
- * OMGF_Admin_Settings_Advanced constructor.
23
- */
24
- public function __construct()
25
- {
26
- $this->title = __('Extensions', $this->plugin_text_domain);
27
-
28
- // Open
29
- // @formatter:off
30
- add_filter('omgf_extensions_settings_content', [$this, 'do_title'], 10);
31
- add_filter('omgf_extensions_settings_content', [$this, 'do_description'], 15);
32
- add_filter('omgf_extensions_settings_content', [$this, 'do_before'], 20);
33
-
34
- // Settings
35
- add_filter('omgf_extensions_settings_content', [$this, 'do_promo_remove_stylesheets'], 30);
36
- add_filter('omgf_extensions_settings_content', [$this, 'do_promo_remove_inline_styles'], 40);
37
- add_filter('omgf_extensions_settings_content', [$this, 'do_promo_remove_webfont_loader'], 50);
38
- add_filter('omgf_extensions_settings_content', [$this, 'do_promo_remove_resource_hints'], 60);
39
-
40
- // Close
41
- add_filter('omgf_extensions_settings_content', [$this, 'do_after'], 100);
42
- // @formatter:on
43
- }
44
-
45
- /**
46
- * Description
47
- */
48
- public function do_description()
49
- {
50
- ?>
51
- <p>
52
- <?= __('Fine tune and enhance the functionality of OMGF using extensions.', $this->plugin_text_domain); ?>
53
- </p>
54
- <p>
55
- <?= sprintf(__('For a list of available plugins, click <a target="_blank" href="%s">here</a>.', $this->plugin_text_domain), 'https://woosh.dev/wordpress-plugins/'); ?>
56
- </p>
57
- <?php
58
- }
59
-
60
- /**
61
- * Add (overridable) promo options for Remove Stylesheets Pro.
62
- */
63
- public function do_promo_remove_stylesheets()
64
- {
65
- $this->do_checkbox(
66
- __('Remove Stylesheets (Pro)', $this->plugin_text_domain),
67
- 'omgf_pro_remove_stylesheets',
68
- defined('OMGF_PRO_REMOVE_STYLESHEETS') ? OMGF_PRO_REMOVE_STYLESHEETS : false,
69
- sprintf(__('Remove all stylesheets loaded from <code>fonts.googleapis.com</code> or <code>fonts.gstatic.com</code>. <a href="%s" target="_blank">Purchase OMGF Pro</a> to enable this option.', $this->plugin_text_domain), OMGF_Admin_Settings_Builder::WOOSH_WORDPRESS_PLUGINS_HOST_GOOGLE_FONTS_PRO),
70
- false,
71
- true
72
- );
73
- }
74
-
75
- /**
76
- *
77
- */
78
- public function do_promo_remove_inline_styles()
79
- {
80
- $this->do_checkbox(
81
- __('Remove Inline Styles (Pro)', $this->plugin_text_domain),
82
- 'omgf_pro_remove_inline_styles',
83
- defined('OMGF_PRO_REMOVE_INLINE_STYLES') ? OMGF_PRO_REMOVE_INLINE_STYLES : false,
84
- sprintf(__('Remove all <code>@font-face</code> and <code>@import</code> rules loading Google Fonts. <a href="%s" target="_blank">Purchase OMGF Pro</a> to enable this option.', $this->plugin_text_domain), OMGF_Admin_Settings_Builder::WOOSH_WORDPRESS_PLUGINS_HOST_GOOGLE_FONTS_PRO),
85
- false,
86
- true
87
- );
88
- }
89
-
90
- /**
91
- *
92
- */
93
- public function do_promo_remove_webfont_loader()
94
- {
95
- $this->do_checkbox(
96
- __('Remove WebFont Loader (Pro)', $this->plugin_text_domain),
97
- 'omgf_pro_remove_webfont_loader',
98
- defined('OMGF_PRO_REMOVE_WEBFONT_LOADER') ? OMGF_PRO_REMOVE_WEBFONT_LOADER : false,
99
- sprintf(__('Remove any WebFont Loader (<code>webfont.js</code>) libraries and the corresponding configuration defining which Google Fonts to load (WebFont Config). <a href="%s" target="_blank">Purchase OMGF Pro</a> to enable this option.', $this->plugin_text_domain), OMGF_Admin_Settings_Builder::WOOSH_WORDPRESS_PLUGINS_HOST_GOOGLE_FONTS_PRO),
100
- false,
101
- true
102
- );
103
- }
104
-
105
- /**
106
- *
107
- */
108
- public function do_promo_remove_resource_hints()
109
- {
110
- $this->do_checkbox(
111
- __('Remove Resource Hints (Pro)', $this->plugin_text_domain),
112
- 'omgf_pro_remove_resource_hints',
113
- defined('OMGF_PRO_REMOVE_RESOURCE_HINTS') ? OMGF_PRO_REMOVE_RESOURCE_HINTS : false,
114
- sprintf(__('Remove all <code>link</code> elements with a <code>rel</code> attribute value of <code>dns-prefetch</code>, <code>preload</code> or <code>preconnect</code>. <a href="%s" target="_blank">Purchase OMGF Pro</a> to enable this option.', $this->plugin_text_domain), OMGF_Admin_Settings_Builder::WOOSH_WORDPRESS_PLUGINS_HOST_GOOGLE_FONTS_PRO),
115
- false,
116
- true
117
- );
118
- }
119
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/ajax/class-download.php DELETED
@@ -1,147 +0,0 @@
1
- <?php
2
- /* * * * * * * * * * * * * * * * * * * * *
3
- *
4
- * ██████╗ ███╗ ███╗ ██████╗ ███████╗
5
- * ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
6
- * ██║ ██║██╔████╔██║██║ ███╗█████╗
7
- * ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
8
- * ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
9
- * ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
10
- *
11
- * @package : OMGF
12
- * @author : Daan van den Bergh
13
- * @copyright: (c) 2020 Daan van den Bergh
14
- * @url : https://daan.dev
15
- * * * * * * * * * * * * * * * * * * * */
16
-
17
- defined('ABSPATH') || exit;
18
-
19
- class OMGF_AJAX_Download extends OMGF_AJAX
20
- {
21
- /** @var QM_DB $wpdb */
22
- private $wpdb;
23
-
24
- /** @var OMGF_DB $db */
25
- protected $db;
26
-
27
- /**
28
- * OMGF_Download_Fonts constructor.
29
- */
30
- public function __construct()
31
- {
32
- global $wpdb;
33
-
34
- $this->wpdb = $wpdb;
35
-
36
- parent::__construct();
37
-
38
- $this->init();
39
- }
40
-
41
- /**
42
- * Initialize the download process.
43
- */
44
- private function init()
45
- {
46
- $this->create_dir_recursive();
47
-
48
- $this->download();
49
- }
50
-
51
- /**
52
- * If cache directory doesn't exist, we should create it.
53
- */
54
- private function create_dir_recursive()
55
- {
56
- $uploadDir = OMGF_FONTS_DIR;
57
- if (!file_exists($uploadDir)) {
58
- wp_mkdir_p($uploadDir);
59
- }
60
- }
61
-
62
- /**
63
- * Download the fonts and write them to the database.
64
- */
65
- private function download()
66
- {
67
- $selectedFonts = $this->db->get_total_fonts();
68
-
69
- if (empty($selectedFonts)) {
70
- OMGF_Admin_Notice::set_notice(__('Hmmm... Seems like there\'s nothing to do here. Have you tried using <strong>search</strong> or <strong>auto detect</strong>?', 'host-webfonts-local'), true, 'error');
71
- }
72
-
73
- foreach ($selectedFonts as $id => &$font) {
74
- $urls['url_ttf'] = $font['url_ttf'];
75
- $urls['url_woff'] = $font['url_woff'];
76
- $urls['url_woff2'] = $font['url_woff2'];
77
- $urls['url_eot'] = $font['url_eot'];
78
-
79
- foreach ($urls as $type => $url) {
80
- if (!$url) {
81
- continue;
82
- }
83
-
84
- $remoteFile = esc_url_raw($url);
85
-
86
- /**
87
- * We rewrite the local filename for easier debugging in the waterfall.
88
- */
89
- $filename = sanitize_title_with_dashes($font['font_family']) . '-' . $font['font_weight'] . '-' . $font['font_style'] . '-' . substr(basename($remoteFile), -10);
90
- $localFile = OMGF_FONTS_DIR . '/' . $filename;
91
-
92
- try {
93
- $this->download_file($localFile, $remoteFile);
94
- $font['downloaded'] = 1;
95
- } catch (Exception $e) {
96
- OMGF_Admin_Notice::set_notice(__("File ($remoteFile) could not be downloaded: ", 'host-webfonts-local') . $e->getMessage(), false, 'error', $e->getCode());
97
- }
98
-
99
- clearstatcache();
100
-
101
- $font[$type . '_local'] = OMGF_FONTS_URL . '/' . $filename;
102
- }
103
- }
104
-
105
- update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $selectedFonts);
106
-
107
- OMGF_Admin_Notice::set_notice(count($selectedFonts) . ' ' . __('fonts downloaded. You can now proceed to generate the stylesheet.', 'host-webfonts-local'));
108
- }
109
-
110
- /**
111
- * Download $remoteFile and write to $localFile
112
- *
113
- * @param $localFile
114
- * @param $remoteFile
115
- */
116
- private function download_file($localFile, $remoteFile)
117
- {
118
- $file = wp_remote_get($remoteFile);
119
-
120
- if (is_wp_error($file)) {
121
- OMGF_Admin_Notice::set_notice($file->get_error_message(), true, 'error', $file->get_error_code());
122
- }
123
-
124
- $this->filesystem()->put_contents($localFile, $file['body']);
125
-
126
- if (file_exists($localFile)) {
127
- return;
128
- }
129
- }
130
-
131
- /**
132
- * Helper to return WordPress filesystem subclass.
133
- *
134
- * @return WP_Filesystem_Base $wp_filesystem
135
- */
136
- private function filesystem()
137
- {
138
- global $wp_filesystem;
139
-
140
- if ( is_null( $wp_filesystem ) ) {
141
- require_once ABSPATH . '/wp-admin/includes/file.php';
142
- WP_Filesystem();
143
- }
144
-
145
- return $wp_filesystem;
146
- }
147
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/ajax/class-generate.php DELETED
@@ -1,162 +0,0 @@
1
- <?php
2
- /* * * * * * * * * * * * * * * * * * * * *
3
- *
4
- * ██████╗ ███╗ ███╗ ██████╗ ███████╗
5
- * ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
6
- * ██║ ██║██╔████╔██║██║ ███╗█████╗
7
- * ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
8
- * ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
9
- * ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
10
- *
11
- * @package : OMGF
12
- * @author : Daan van den Bergh
13
- * @copyright: (c) 2020 Daan van den Bergh
14
- * @url : https://daan.dev
15
- * * * * * * * * * * * * * * * * * * * */
16
-
17
- defined('ABSPATH') || exit;
18
-
19
- class OMGF_AJAX_Generate extends OMGF_AJAX
20
- {
21
- /** @var array $fonts */
22
- private $fonts = [];
23
-
24
- /**
25
- * OMGF_AJAX_Generate_Styles constructor.
26
- */
27
- public function __construct()
28
- {
29
- parent::__construct();
30
-
31
- $this->init();
32
- }
33
-
34
- /**
35
- * Generate the Stylesheet
36
- */
37
- private function init()
38
- {
39
- header("Content-type: text/css");
40
-
41
- $this->insert_promo();
42
-
43
- $selectedFonts = $this->db->get_total_fonts();
44
-
45
- if (empty($selectedFonts)) {
46
- OMGF_Admin_Notice::set_notice(__('Hmmm... Seems like there\'s nothing to do here. Have you tried using <strong>search</strong> or <strong>auto detect</strong>?', 'host-webfonts-local'), true, 'error');
47
- }
48
-
49
- $this->process_fonts($selectedFonts);
50
-
51
- $fonts = implode("\n", $this->fonts);
52
- $file = OMGF_FONTS_DIR . '/' . OMGF_FILENAME;
53
-
54
- /**
55
- * If the file can be created and written. Let's try to write it.
56
- */
57
- try {
58
- $stylesheet = fopen($file, 'w') or OMGF_Admin_Notice::set_notice(__("Cannot create file {$file}", 'host-webfonts-local', true, 'error', 400));
59
- fwrite($stylesheet, $fonts);
60
- fclose($stylesheet);
61
-
62
- OMGF_Admin_Notice::set_notice(__('Congratulations! Your stylesheet was generated successfully and added to your theme\'s header.', 'host-webfonts-local'), false);
63
-
64
- $count = count($selectedFonts);
65
- $review = apply_filters('omgf_generate_stylesheet_review_link', 'https://wordpress.org/support/plugin/host-webfonts-local/reviews/?rate=5#new-post');
66
- $tweet = apply_filters('omgf_generate_stylesheet_tweet_link', "https://twitter.com/intent/tweet?text=I+just+optimized+$count+Google+Fonts+with+OMGF+for+@WordPress!+Try+it+for+yourself:&via=Dan0sz&hashtags=GoogleFonts,WordPress,Pagespeed,Insights&url=https://wordpress.org/plugins/host-webfonts-local/", $count);
67
-
68
- OMGF_Admin_Notice::set_notice(sprintf(__('OMGF has optimized %s fonts. Enjoy your performance boost! Would you like to <a href="%s" target="_blank">write a review</a> or <a href="%s" target="_blank">tweet about it</a>?', 'host-webfonts-local'), $count, $review, $tweet), true, 'info');
69
- } catch (Exception $e) {
70
- OMGF_Admin_Notice::set_notice(__("Stylesheet could not be generated:", 'host-webfonts-local') . " $e", true, 'error', $e->getCode());
71
- }
72
- }
73
-
74
- /**
75
- * Insert promo material :)
76
- *
77
- * The alignment is crooked, so it'll look nice in the stylesheet.
78
- */
79
- private function insert_promo()
80
- {
81
- $this->fonts[] = "/**
82
- * This file is automagically generated by OMGF
83
- *
84
- * @author: Daan van den Bergh
85
- * @copyright: (c) 2020 Daan van den Bergh
86
- * @url: " . OMGF_SITE_URL . "
87
- */";
88
- }
89
-
90
- /**
91
- * Prepare fonts for generation.
92
- */
93
- private function process_fonts($fonts)
94
- {
95
- $fontDisplay = OMGF_DISPLAY_OPTION;
96
-
97
- $i = 1;
98
-
99
- foreach ($fonts as $font) {
100
- $fontUrlEot = isset($font['url_eot_local']) ? array(0 => esc_url_raw($font['url_eot_local'])) : array();
101
- $fontSources = isset($font['url_woff2_local']) ? array('woff2' => esc_url_raw($font['url_woff2_local'])) : array();
102
- $fontSources = $fontSources + (isset($font['url_woff_local']) ? array('woff' => esc_url_raw($font['url_woff_local'])) : array());
103
- $fontSources = $fontSources + (isset($font['url_ttf_local']) ? array('truetype' => esc_url_raw($font['url_ttf_local'])) : array());
104
- $locals = explode(',', sanitize_text_field($font['local']));
105
-
106
- if (empty($fontSources)) {
107
- OMGF_Admin_Notice::set_notice(__('<strong>Download Fonts</strong> before generating the stylesheet.', 'host-webfonts-local'), true, 'error');
108
- }
109
-
110
- $this->fonts[$i] = "@font-face { \n";
111
- $this->fonts[$i] .= $this->build_property('font-family', $font['font_family']);
112
- $this->fonts[$i] .= $this->build_property('font-display', $fontDisplay);
113
- $this->fonts[$i] .= $this->build_property('font-style', $font['font_style']);
114
- $this->fonts[$i] .= $this->build_property('font-weight', $font['font_weight']);
115
- $this->fonts[$i] .= isset($fontUrlEot) ? " src: " . $this->build_source_string($fontUrlEot) : '';
116
- $this->fonts[$i] .= " src: " . $this->build_source_string($locals, 'local', false);
117
- // There'll always be at least one font available, so no need to check here if $fontSources is set.
118
- $this->fonts[$i] .= $this->build_source_string($fontSources);
119
- $this->fonts[$i] .= "}";
120
-
121
- $i++;
122
- }
123
- }
124
-
125
- /**
126
- * @param $property
127
- * @param $value
128
- *
129
- * @return string
130
- */
131
- private function build_property($property, $value)
132
- {
133
- $value = sanitize_text_field($value);
134
-
135
- return " $property: $value;\n";
136
- }
137
-
138
- /**
139
- * @param $sources
140
- * @param string $type
141
- * @param bool $endSemiColon
142
- *
143
- * @return string
144
- */
145
- private function build_source_string($sources, $type = 'url', $endSemiColon = true)
146
- {
147
- $lastSrc = end($sources);
148
- $source = '';
149
-
150
- foreach ($sources as $format => $url) {
151
- $source .= " $type('$url')" . (!is_numeric($format) ? " format('$format')" : '');
152
-
153
- if ($url === $lastSrc && $endSemiColon) {
154
- $source .= ";\n";
155
- } else {
156
- $source .= ",\n";
157
- }
158
- }
159
-
160
- return $source;
161
- }
162
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/api/class-download.php ADDED
@@ -0,0 +1,293 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* * * * * * * * * * * * * * * * * * * * *
3
+ *
4
+ * ██████╗ ███╗ ███╗ ██████╗ ███████╗
5
+ * ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
6
+ * ██║ ██║██╔████╔██║██║ ███╗█████╗
7
+ * ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
8
+ * ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
9
+ * ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
10
+ *
11
+ * @package : OMGF
12
+ * @author : Daan van den Bergh
13
+ * @copyright: (c) 2020 Daan van den Bergh
14
+ * @url : https://daan.dev
15
+ * * * * * * * * * * * * * * * * * * * */
16
+
17
+ defined( 'ABSPATH' ) || exit;
18
+
19
+ class OMGF_API_Download extends WP_REST_Controller
20
+ {
21
+ const OMGF_GOOGLE_FONTS_API_URL = 'https://google-webfonts-helper.herokuapp.com';
22
+
23
+ /** @var array $endpoints */
24
+ private $endpoints = [ 'css' ];
25
+
26
+ /** @var string $namespace */
27
+ protected $namespace = 'omgf/v1';
28
+
29
+ /** @var string $rest_base */
30
+ protected $rest_base = '/download/';
31
+
32
+ /** @var string $handle */
33
+ private $handle = '';
34
+
35
+ /** @var string $path */
36
+ private $path = '';
37
+
38
+ public function __construct () {
39
+ add_filter( 'content_url', [ $this, 'rewrite_url' ], 10, 2 );
40
+ }
41
+
42
+ /**
43
+ *
44
+ */
45
+ public function register_routes () {
46
+ foreach ( $this->endpoints as $endpoint ) {
47
+ register_rest_route(
48
+ $this->namespace,
49
+ '/' . $this->rest_base . $endpoint,
50
+ [
51
+ [
52
+ 'methods' => 'GET',
53
+ 'callback' => [ $this, 'process' ],
54
+ 'permission_callback' => [ $this, 'permissions_check' ]
55
+ ],
56
+ 'schema' => null,
57
+ ]
58
+ );
59
+ }
60
+ }
61
+
62
+ /**
63
+ * @return bool
64
+ */
65
+ public function permissions_check () {
66
+ return true;
67
+ }
68
+
69
+ /**
70
+ * @param $request
71
+ */
72
+ public function process ( $request ) {
73
+ $params = $request->get_params();
74
+ $this->handle = $params['handle'] ?? '';
75
+
76
+ if ( ! $this->handle ) {
77
+ wp_send_json_error( 'Handle not provided.', 406 );
78
+ }
79
+
80
+ $this->path = WP_CONTENT_DIR . OMGF_CACHE_PATH . '/' . $this->handle;
81
+
82
+ $url = self::OMGF_GOOGLE_FONTS_API_URL . '/api/fonts/%s';
83
+ $font_families = explode( '|', $params['family'] );
84
+
85
+ foreach ( $font_families as $font_family ) {
86
+ list( $family, $variants ) = explode( ':', $font_family );
87
+ $family = str_replace( ' ', '-', strtolower( $family ) );
88
+
89
+ if ( defined( 'OMGF_PRO_FORCE_SUBSETS' ) && ! empty( OMGF_PRO_FORCE_SUBSETS ) ) {
90
+ $query['subsets'] = implode( ',', OMGF_PRO_FORCE_SUBSETS );
91
+ } else {
92
+ $query['subsets'] = $params['subset'] ?? 'latin,latin-ext';
93
+ }
94
+
95
+ $response = wp_remote_get(
96
+ sprintf( $url, $family ) . '?' . http_build_query( $query )
97
+ );
98
+
99
+ if ( ! is_wp_error( $response ) && wp_remote_retrieve_response_code( $response ) == 200 ) {
100
+ $fonts[] = json_decode( wp_remote_retrieve_body( $response ) );
101
+ }
102
+ }
103
+
104
+ foreach ( $fonts as &$font ) {
105
+ $font_request = array_filter(
106
+ $font_families,
107
+ function ( $value ) use ( $font ) {
108
+ return strpos( $value, $font->family ) !== false;
109
+ }
110
+ );
111
+ $font->variants = $this->filter_variants( $font->variants, reset( $font_request ) );
112
+ }
113
+
114
+ foreach ( $fonts as &$font ) {
115
+ foreach ( $font->variants as &$variant ) {
116
+ $font_family = trim($variant->fontFamily, '\'"');
117
+ $filename = strtolower( $font_family . '-' . $variant->fontStyle . '-' . $variant->fontWeight );
118
+ $variant->woff = $this->download( $variant->woff, $filename );
119
+ $variant->woff2 = $this->download( $variant->woff2, $filename );
120
+ $variant->eot = $this->download( $variant->eot, $filename );
121
+ $variant->ttf = $this->download( $variant->ttf, $filename );
122
+ }
123
+ }
124
+
125
+ $stylesheet = $this->generate_stylesheet( $fonts );
126
+
127
+ $local_file = $this->path . '/' . $this->handle . '.css';
128
+
129
+ file_put_contents( $local_file, $stylesheet );
130
+
131
+ // After downloading it, serve it.
132
+ header( 'Content-Type: text/css' );
133
+ header( "Content-Transfer-Encoding: Binary" );
134
+ header( 'Content-Length: ' . filesize( $local_file ) );
135
+ flush();
136
+ readfile( $local_file );
137
+ die();
138
+ }
139
+
140
+ /**
141
+ * @param $available_variants
142
+ * @param $wanted
143
+ *
144
+ * @return array
145
+ */
146
+ private function filter_variants ( $available_variants, $wanted ) {
147
+ list ( $family, $variants ) = explode( ':', $wanted );
148
+
149
+ if ( ! $variants ) {
150
+ return $available_variants;
151
+ }
152
+
153
+ $variants = explode( ',', $variants );
154
+
155
+ return array_filter(
156
+ $available_variants,
157
+ function ( $font ) use ( $variants ) {
158
+ $id = $font->id;
159
+
160
+ if ( $id == 'regular' || $id == 'italic' ) {
161
+ $id = '400';
162
+ }
163
+
164
+ return in_array( $id, $variants );
165
+ }
166
+ );
167
+ }
168
+
169
+ /**
170
+ * @param $urls
171
+ *
172
+ * @return bool
173
+ */
174
+ private function download ( $url, $filename ) {
175
+ if ( ! function_exists( 'download_url' ) ) {
176
+ require_once ABSPATH . 'wp-admin/includes/file.php';
177
+ }
178
+
179
+ wp_mkdir_p( $this->path );
180
+
181
+ $file = $this->path . '/' . $filename . '.' . pathinfo($url, PATHINFO_EXTENSION);
182
+ $file_uri = str_replace( WP_CONTENT_DIR, '', $file );
183
+
184
+ if ( file_exists( $file ) ) {
185
+ return content_url( $file_uri );
186
+ }
187
+
188
+ $tmp = download_url( $url );
189
+ copy( $tmp, $file );
190
+ @unlink( $tmp );
191
+
192
+ return content_url( $file_uri );
193
+ }
194
+
195
+ /**
196
+ * @param $url
197
+ * @param $path
198
+ *
199
+ * @return mixed
200
+ */
201
+ public function rewrite_url ( $url, $path ) {
202
+ /**
203
+ * Exit early if this isn't requested by OMGF.
204
+ */
205
+ if ( strpos( $url, OMGF_CACHE_PATH ) === false ) {
206
+ return $url;
207
+ }
208
+
209
+ /**
210
+ * If Relative URLs is enabled, overwrite URL with Path and continue execution.
211
+ */
212
+ if ( OMGF_RELATIVE_URL ) {
213
+ $content_dir = str_replace( site_url(), '', content_url() );
214
+
215
+ $url = $content_dir . $path;
216
+ }
217
+
218
+ if ( OMGF_CDN_URL ) {
219
+ $url = str_replace( site_url(), OMGF_CDN_URL, $url );
220
+ }
221
+
222
+ if ( OMGF_CACHE_URI ) {
223
+ $url = str_replace( OMGF_CACHE_PATH, OMGF_CACHE_URI, $url );
224
+ }
225
+
226
+ return $url;
227
+ }
228
+
229
+ /**
230
+ * @param $fonts
231
+ *
232
+ * @return string
233
+ */
234
+ private function generate_stylesheet ( $fonts ) {
235
+ $stylesheet = "/**\n * Auto Generated by OMGF\n * @author: Daan van den Bergh\n * @url: https://ffwp.dev\n */\n\n";
236
+ $font_display = OMGF_DISPLAY_OPTION;
237
+
238
+ foreach ( $fonts as $font ) {
239
+ foreach ( $font->variants as $variant ) {
240
+ $font_family = $variant->fontFamily;
241
+ $font_style = $variant->fontStyle;
242
+ $font_weight = $variant->fontWeight;
243
+ $stylesheet .= "@font-face {\n";
244
+ $stylesheet .= " font-family: $font_family;\n";
245
+ $stylesheet .= " font-style: $font_style;\n";
246
+ $stylesheet .= " font-weight: $font_weight;\n";
247
+ $stylesheet .= " font-display: $font_display;\n";
248
+ $stylesheet .= " src: url('" . $variant->eot . "');\n";
249
+
250
+ $local_src = '';
251
+
252
+ foreach ( $variant->local as $local ) {
253
+ $local_src .= "local('$local'), ";
254
+ }
255
+
256
+ $stylesheet .= " src: $local_src\n";
257
+
258
+ $font_src_url = isset( $variant->woff2 ) ? [ 'woff2' => $variant->woff2 ] : [];
259
+ $font_src_url = $font_src_url + ( isset( $variant->woff ) ? [ 'woff' => $variant->woff ] : [] );
260
+ $font_src_url = $font_src_url + ( isset( $variant->ttf ) ? [ 'ttf' => $variant->ttf ] : [] );
261
+
262
+ $stylesheet .= $this->build_source_string( $font_src_url );
263
+ $stylesheet .= "}\n";
264
+ }
265
+ }
266
+
267
+ return $stylesheet;
268
+ }
269
+
270
+ /**
271
+ * @param $sources
272
+ * @param string $type
273
+ * @param bool $endSemiColon
274
+ *
275
+ * @return string
276
+ */
277
+ private function build_source_string ( $sources, $type = 'url', $end_semi_colon = true ) {
278
+ $lastSrc = end( $sources );
279
+ $source = '';
280
+
281
+ foreach ( $sources as $format => $url ) {
282
+ $source .= " $type('$url')" . ( ! is_numeric( $format ) ? " format('$format')" : '' );
283
+
284
+ if ( $url === $lastSrc && $end_semi_colon ) {
285
+ $source .= ";\n";
286
+ } else {
287
+ $source .= ",\n";
288
+ }
289
+ }
290
+
291
+ return $source;
292
+ }
293
+ }
includes/class-admin.php CHANGED
@@ -14,312 +14,102 @@
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
- defined('ABSPATH') || exit;
18
 
19
  class OMGF_Admin
20
  {
21
- const OMGF_ADMIN_JS_HANDLE = 'omgf-admin-js';
22
- const OMGF_ADMIN_CSS_HANDLE = 'omgf-admin-css';
23
-
24
- /** @var OMGF_DB */
25
- private $db;
26
-
27
- /**
28
- * OMGF_Admin constructor.
29
- */
30
- public function __construct()
31
- {
32
- $this->db = new OMGF_DB();
33
-
34
- // @formatter:off
35
- add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']);
36
- add_action('admin_notices', [$this, 'add_notice']);
37
-
38
- $this->do_advanced_settings();
39
- $this->do_extensions_settings();
40
-
41
- add_filter('pre_update_option_omgf_cache_dir', [$this, 'cache_dir_changed'], 10, 2);
42
- add_filter('pre_update_option_omgf_cache_uri', [$this, 'serve_uri_changed'], 10, 2);
43
- add_filter('pre_update_option_omgf_relative_url', [$this, 'relative_url_changed'], 10, 2);
44
- add_filter('pre_update_option_omgf_cdn_url', [$this, 'cdn_url_changed'], 10, 2);
45
- // @formatter:on
46
- }
47
-
48
- /**
49
- * Enqueues the necessary JS and CSS and passes options as a JS object.
50
- *
51
- * @param $hook
52
- */
53
- public function enqueue_admin_scripts($hook)
54
- {
55
- if ($hook == 'settings_page_optimize-webfonts') {
56
- wp_enqueue_script(self::OMGF_ADMIN_JS_HANDLE, plugin_dir_url(OMGF_PLUGIN_FILE) . 'assets/js/omgf-admin.js', array('jquery'), OMGF_STATIC_VERSION, true);
57
- wp_enqueue_style(self::OMGF_ADMIN_CSS_HANDLE, plugin_dir_url(OMGF_PLUGIN_FILE) . 'assets/css/omgf-admin.css', array(), OMGF_STATIC_VERSION);
58
-
59
- $options = array(
60
- 'auto_detect_enabled' => OMGF_AUTO_DETECT_ENABLED,
61
- 'detected_fonts' => get_option('omgf_detected_fonts')
62
- );
63
-
64
- wp_localize_script(self::OMGF_ADMIN_JS_HANDLE, 'omgf', $options);
65
- }
66
- }
67
-
68
- /**
69
- * @param $name
70
- *
71
- * @return mixed
72
- */
73
- protected function get_template($name)
74
- {
75
- return include OMGF_PLUGIN_DIR . 'templates/admin/block-' . $name . '.phtml';
76
- }
77
-
78
- /**
79
- * Add notice to admin screen.
80
- */
81
- public function add_notice()
82
- {
83
- OMGF_Admin_Notice::print_notice();
84
- }
85
-
86
- /**
87
- * @return OMGF_Admin_Settings_Advanced
88
- */
89
- private function do_advanced_settings()
90
- {
91
- return new OMGF_Admin_Settings_Advanced();
92
- }
93
-
94
- /**
95
- * @return OMGF_Admin_Settings_Extensions
96
- */
97
- private function do_extensions_settings()
98
- {
99
- return new OMGF_Admin_Settings_Extensions();
100
- }
101
-
102
- /**
103
- * When the cache path is changed, OMGF moves the entire fonts folder to its new destination and throws a notice to
104
- * regenerate the stylesheet.
105
- *
106
- * @param $new_cache_dir
107
- * @param $old_cache_dir
108
- *
109
- * @return mixed
110
- */
111
- public function cache_dir_changed($new_cache_dir, $old_cache_dir)
112
- {
113
- if ($new_cache_dir !== $old_cache_dir && !empty($new_cache_dir)) {
114
- $font_styles = $this->db->get_downloaded_fonts();
115
-
116
- if (empty($font_styles)) {
117
- return $new_cache_dir;
118
- }
119
-
120
- $files = array_diff(scandir(OMGF_FONTS_DIR), ['.', '..']);
121
-
122
- $this->move_files($files, $new_cache_dir);
123
-
124
- if (!OMGF_CACHE_URI) {
125
- $font_styles = $this->rewrite_urls($font_styles, $old_cache_dir, $new_cache_dir);
126
-
127
- OMGF_Admin_Notice::set_notice(__("You've changed OMGF's storage folder to <strong>$new_cache_dir</strong>. Regenerate the stylesheet to implement this change.", 'host-webfonts-local'), false, 'info');
128
- } else {
129
- OMGF_Admin_Notice::set_notice(__("You've changed OMGF's storage folder to <strong>$new_cache_dir</strong>. Make sure the setting <em>Serve font files from...</em> reflects your changes and regenerate the stylesheet.", 'host-webfonts-local'), false);
130
- }
131
-
132
- update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $font_styles);
133
- }
134
-
135
- return $new_cache_dir;
136
- }
137
-
138
- /**
139
- * @param $new_uri
140
- * @param $old_uri
141
- *
142
- * @return mixed
143
- */
144
- public function serve_uri_changed($new_uri, $old_uri)
145
- {
146
- if ($new_uri !== $old_uri && !empty($new_uri)) {
147
- $font_styles = $this->db->get_downloaded_fonts();
148
-
149
- if (empty($font_styles)) {
150
- return $new_uri;
151
- }
152
-
153
- preg_match('/[^\/]+$/u', WP_CONTENT_DIR, $match);
154
-
155
- $font_styles = $this->rewrite_urls($font_styles, $old_uri, $new_uri);
156
-
157
- update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $font_styles);
158
-
159
- OMGF_Admin_Notice::set_notice(__("Fonts updated successfully. Regenerate the stylesheet to <em>serve font files from</em> $new_uri.", 'host-webfonts-local'), false, 'info');
160
- }
161
-
162
- return $new_uri;
163
- }
164
-
165
- /**
166
- * @param $new_value
167
- * @param $old_value
168
- *
169
- * @return mixed
170
- */
171
- public function relative_url_changed($new_value, $old_value)
172
- {
173
- if ($new_value != $old_value) {
174
- $font_styles = $this->db->get_downloaded_fonts();
175
-
176
- if (empty($font_styles)) {
177
- return $new_value;
178
- }
179
-
180
- $result = $this->unset_downloaded_value($font_styles);
181
-
182
- if ($new_value == 'on') {
183
- $status = 'enabled';
184
- } elseif (!$new_value) {
185
- $status = 'disabled';
186
- }
187
-
188
- if ($result) {
189
- OMGF_Admin_Notice::set_notice(sprintf(__('You\'ve %s using <em>relative URLs</em>. <strong>Download</strong> the <strong>fonts</strong> again and (re-)<strong>generate</strong> the <strong>stylesheet</strong> to implement this change.', 'host-webfonts-local'), $status), false, 'info');
190
-
191
- return $new_value;
192
- }
193
-
194
- OMGF_Admin_Notice::set_notice(__('You\'ve %s using <em>relative URLs</em>. Something went wrong while updating the fonts. <strong>Empty</strong> the <strong>cache directory</strong>, <strong>download</strong> the <strong>fonts</strong> and <strong>generate</strong> the <strong>stylesheet</strong> to implement this change.', 'host-webfonts-local'), false, 'error');
195
- }
196
-
197
- return $new_value;
198
- }
199
-
200
- public function cdn_url_changed($new_url, $old_url)
201
- {
202
- if ($new_url != $old_url) {
203
- $font_styles = $this->db->get_downloaded_fonts();
204
-
205
- if (empty($font_styles)) {
206
- return $new_url;
207
- }
208
-
209
- $result = $this->unset_downloaded_value($font_styles);
210
-
211
- if ($result) {
212
- OMGF_Admin_Notice::set_notice(__('Fonts updated successfully. <strong>Download</strong> the <strong>fonts</strong> and (re-)<strong>generate</strong> the <strong>stylesheet</strong> to <em>serve fonts from CDN</em>.', 'host-webfonts-local'), false, 'info');
213
- } else {
214
- OMGF_Admin_Notice::set_notice(__('Something went wrong while updating your settings. <strong>Empty</strong> the <strong>Cache Directory</strong>, <strong>download</strong> the <strong>fonts</strong> and <strong>generate</strong> the <strong>stylesheet</strong> to <em>serve fonts from CDN</em>.', 'host-webfonts-local'), false, 'error');
215
- }
216
- }
217
-
218
- return $new_url;
219
- }
220
-
221
- /**
222
- * @param $files
223
- * @param $destination
224
- *
225
- * @return bool
226
- */
227
- private function move_files($files, $destination)
228
- {
229
- $this->create_dir_recursive($destination);
230
-
231
- foreach($files as $filename) {
232
- $old_path = OMGF_FONTS_DIR . "/$filename";
233
- $new_path = WP_CONTENT_DIR . $destination . "/$filename";
234
- $move = rename($old_path, $new_path);
235
-
236
- if ($move == false) {
237
- $errors[] = $filename;
238
- }
239
- }
240
-
241
- if (!empty($errors)) {
242
- $errored_files = ucfirst(implode(', ', $errors));
243
-
244
- OMGF_Admin_Notice::set_notice($errored_files . __('could not be moved. Do it manually and then regenerate the stylesheet.', 'host-webfonts-local'), false, 'error');
245
-
246
- return false;
247
- }
248
-
249
- $message = sprintf(__('Moved %s files', 'host-webfonts-local'), count($files));
250
- $remove_dir = rmdir(OMGF_FONTS_DIR);
251
-
252
- if ($remove_dir) {
253
- $message .= ' ' . __('and succesfully removed the previously set storage folder.', 'host-webfonts-local');
254
- } else {
255
- $message .= '.';
256
- }
257
-
258
- OMGF_Admin_Notice::set_notice($message, false);
259
-
260
- return true;
261
- }
262
-
263
- /**
264
- * @param $font_styles
265
- * @param $old_path
266
- * @param $new_path
267
- *
268
- * @return mixed
269
- */
270
- private function rewrite_urls($font_styles, $old_path, $new_path)
271
- {
272
- foreach ($font_styles as &$font) {
273
- $urls = array_filter($font, function($key) {
274
- return strpos($key, 'url') !== false;
275
- }, ARRAY_FILTER_USE_KEY);
276
-
277
- foreach ($urls as &$url) {
278
- $url = str_replace($old_path, $new_path, $url);
279
- }
280
-
281
- $font = array_replace($font, $urls);
282
- }
283
-
284
- return $font_styles;
285
- }
286
-
287
- /**
288
- * @param $fonts
289
- *
290
- * @return bool
291
- */
292
- private function unset_downloaded_value($fonts)
293
- {
294
- foreach ($fonts as &$font_style) {
295
- $font_style['downloaded'] = 0;
296
- }
297
-
298
- $updated = update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $fonts);
299
-
300
- if ($updated) {
301
- return true;
302
- }
303
-
304
- return false;
305
- }
306
-
307
- /**
308
- * @param $dir
309
- */
310
- private function create_dir_recursive($dir)
311
- {
312
- $uploadDir = WP_CONTENT_DIR . $dir;
313
- if (!file_exists($uploadDir)) {
314
- wp_mkdir_p($uploadDir);
315
- }
316
- }
317
-
318
- /**
319
- * @param $path
320
- */
321
- private function remove_dir_recursive($path)
322
- {
323
- $dirs = explode('/', $path);
324
- }
325
  }
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
+ defined( 'ABSPATH' ) || exit;
18
 
19
  class OMGF_Admin
20
  {
21
+ const OMGF_ADMIN_JS_HANDLE = 'omgf-admin-js';
22
+ const OMGF_ADMIN_CSS_HANDLE = 'omgf-admin-css';
23
+
24
+ /** @var array $show_notice */
25
+ private $show_notice = [];
26
+
27
+ /** @var string $plugin_text_domain */
28
+ private $plugin_text_domain = 'host-webfonts-local';
29
+
30
+ /**
31
+ * OMGF_Admin constructor.
32
+ */
33
+ public function __construct () {
34
+ /**
35
+ * Filterable list of options that require the cache to be emptied.
36
+ */
37
+ $this->show_notice = apply_filters('omgf_admin_options_show_notice', [
38
+ OMGF_Admin_Settings::OMGF_BASIC_SETTING_CACHE_PATH,
39
+ OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI,
40
+ OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL,
41
+ OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL
42
+ ]);
43
+
44
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] );
45
+ add_action( 'admin_notices', [ $this, 'print_notices' ] );
46
+
47
+ $this->do_basic_settings();
48
+ $this->do_advanced_settings();
49
+
50
+ add_filter( 'pre_update_option', [ $this, 'settings_changed' ], 10, 3 );
51
+ }
52
+
53
+ /**
54
+ * Enqueues the necessary JS and CSS and passes options as a JS object.
55
+ *
56
+ * @param $hook
57
+ */
58
+ public function enqueue_admin_scripts ( $hook ) {
59
+ if ( $hook == 'settings_page_optimize-webfonts' ) {
60
+ wp_enqueue_script( self::OMGF_ADMIN_JS_HANDLE, plugin_dir_url( OMGF_PLUGIN_FILE ) . 'assets/js/omgf-admin.js', [ 'jquery' ], OMGF_STATIC_VERSION, true );
61
+ wp_enqueue_style( self::OMGF_ADMIN_CSS_HANDLE, plugin_dir_url( OMGF_PLUGIN_FILE ) . 'assets/css/omgf-admin.css', [], OMGF_STATIC_VERSION );
62
+ }
63
+ }
64
+
65
+ /**
66
+ * @param $name
67
+ *
68
+ * @return mixed
69
+ */
70
+ protected function get_template ( $name ) {
71
+ return include OMGF_PLUGIN_DIR . 'templates/admin/block-' . $name . '.phtml';
72
+ }
73
+
74
+ /**
75
+ * Add notice to admin screen.
76
+ */
77
+ public function print_notices () {
78
+ OMGF_Admin_Notice::print_notices();
79
+ }
80
+
81
+ /**
82
+ * @return OMGF_Admin_Settings_Basic
83
+ */
84
+ private function do_basic_settings () {
85
+ return new OMGF_Admin_Settings_Basic();
86
+ }
87
+
88
+ /**
89
+ * @return OMGF_Admin_Settings_Advanced
90
+ */
91
+ private function do_advanced_settings () {
92
+ return new OMGF_Admin_Settings_Advanced();
93
+ }
94
+
95
+ /**
96
+ * @param $new_value
97
+ * @param $old_settings
98
+ *
99
+ * @return mixed
100
+ */
101
+ public function settings_changed ( $value, $option_name, $old_value ) {
102
+ if (!in_array($option_name, $this->show_notice)) {
103
+ return $value;
104
+ }
105
+
106
+ if ( $value != $old_value ) {
107
+ OMGF_Admin_Notice::set_notice(
108
+ __('Settings changed. <a href="#" class="omgf-empty">Click here</a> to flush OMGF\'s cache.', $this->plugin_text_domain),
109
+ false
110
+ );
111
+ }
112
+
113
+ return $value;
114
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  }
includes/class-ajax.php CHANGED
@@ -14,189 +14,58 @@
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
- defined('ABSPATH') || exit;
18
 
19
  class OMGF_AJAX
20
  {
21
- /** @var OMGF_DB $db */
22
- protected $db;
23
-
24
- /** @var string $plugin_text_domain */
25
- private $plugin_text_domain = 'host-webfonts-local';
26
-
27
- /**
28
- * OMGF_AJAX constructor.
29
- */
30
- public function __construct()
31
- {
32
- $this->db = new OMGF_DB();
33
-
34
- // @formatter:off
35
- add_action('wp_ajax_omgf_ajax_search_font_subsets', array($this, 'search_font_subsets'));
36
- add_action('wp_ajax_omgf_ajax_enable_auto_detect', [$this, 'enable_auto_detect']);
37
- add_action('wp_ajax_omgf_ajax_search_google_fonts', array($this, 'search_fonts'));
38
- add_action('wp_ajax_omgf_ajax_process_font_styles_queue', [$this, 'process_font_styles_queue']);
39
- add_action('wp_ajax_omgf_ajax_download_fonts', array($this, 'download_fonts'));
40
- add_action('wp_ajax_omgf_ajax_generate_styles', array($this, 'generate_styles'));
41
- add_action('wp_ajax_omgf_ajax_empty_dir', array($this, 'empty_directory'));
42
- // @formatter:on
43
- }
44
-
45
- /**
46
- * Search the API for the requested fonts and return the available subsets.
47
- */
48
- public function search_font_subsets()
49
- {
50
- $option_subsets = get_option(OMGF_Admin_Settings::OMGF_SETTING_SUBSETS) ?: [];
51
-
52
- delete_option(OMGF_Admin_Settings::OMGF_SETTING_SUBSETS);
53
-
54
-
55
- if (!($query = $_POST['search_query'])) {
56
- OMGF_Admin_Notice::set_notice(__('Search query not found.', $this->plugin_text_domain), true, 'warning');
57
- }
58
-
59
- $query = strtolower(str_replace(', ', ',', $query));
60
- $query = str_replace(' ', '-', $query);
61
- $searchQueries = explode(',', sanitize_text_field($query));
62
-
63
- foreach ($searchQueries as $searchQuery) {
64
- $api = new OMGF_API();
65
-
66
- $subsets = $api->get_subsets($searchQuery);
67
-
68
- // If subset search comes back empty. Add a notice and skip to the next one.
69
- if (empty($subsets)) {
70
- OMGF_Admin_Notice::set_notice(sprintf(__('Font %s not found. Are you sure it\'s a Google Font?', $this->plugin_text_domain), $searchQuery), false, 'error');
71
-
72
- continue;
73
- }
74
-
75
- $response[$subsets['subset_font']] = $subsets;
76
- }
77
-
78
- $option_subsets = array_merge($option_subsets, $response);
79
-
80
- update_option(OMGF_Admin_Settings::OMGF_SETTING_SUBSETS, $option_subsets);
81
-
82
- OMGF_Admin_Notice::set_notice(__('Subset search complete. Select subsets to generate a list of available font styles.', $this->plugin_text_domain));
83
- }
84
-
85
- /**
86
- * Enable Auto Detect
87
- */
88
- public function enable_auto_detect()
89
- {
90
- update_option(OMGF_Admin_Settings::OMGF_SETTING_AUTO_DETECTION_ENABLED, true);
91
-
92
- $url = get_permalink(get_posts()[0]->ID);
93
-
94
- OMGF_Admin_Notice::set_notice(__("Auto Detect enabled. Open any page on your frontend (e.g. your <a href='$url' target='_blank'>latest post</a>). After the page is fully loaded, return here and <a href='javascript:location.reload()'>click here</a> to refresh this page.", $this->plugin_text_domain));
95
- }
96
-
97
- /**
98
- * Return the available fonts for the selected subset(s) from the API.
99
- */
100
- public function search_fonts()
101
- {
102
- if (!isset($_POST['search_google_fonts'])) {
103
- delete_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS);
104
-
105
- OMGF_Admin_Notice::set_notice(__('Search query not found. Did you select any subsets? If so, try again.'), true, 'warning');
106
- }
107
-
108
- $search_google_fonts = $_POST['search_google_fonts'];
109
-
110
- foreach ($search_google_fonts as $index => $google_font) {
111
- $search_google_fonts[$google_font['subset_font']] = $google_font;
112
- unset($search_google_fonts[$index]);
113
- }
114
-
115
- $subsets = get_option(OMGF_Admin_Settings::OMGF_SETTING_SUBSETS);
116
-
117
- // Unset subsets which were checked before, but aren't now.
118
- foreach ($subsets as $index => &$font) {
119
- if (!in_array($index, array_keys($search_google_fonts))) {
120
- $font['selected_subsets'] = [];
121
- }
122
- }
123
-
124
- // Overwrite current selected subsets in settings with new values.
125
- $subsets = array_replace_recursive($subsets, $search_google_fonts);
126
-
127
- update_option(OMGF_Admin_Settings::OMGF_SETTING_SUBSETS, $subsets);
128
-
129
- // Retrieve available font styles.
130
- foreach ($search_google_fonts as $font) {
131
- $selected_subsets = implode(',', $font['selected_subsets']);
132
- $api = new OMGF_API();
133
- $fonts[] = $api->get_font_styles($font['subset_font'], $selected_subsets);
134
- }
135
-
136
- // Create font styles list.
137
- $fonts = array_merge(...$fonts);
138
-
139
- update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $fonts);
140
-
141
- OMGF_Admin_Notice::set_notice(count($fonts) . ' ' . __('font styles found. Trim the list to your needs and click <strong>Download Fonts</strong>.', $this->plugin_text_domain));
142
- }
143
-
144
- /**
145
- * Update options with font styles selected for preloading.
146
- */
147
- public function process_font_styles_queue()
148
- {
149
- $current_fonts = get_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS);
150
- $selected_fonts = $_POST['font_styles'];
151
- $to_be_preloaded = $_POST['preload_font_styles'];
152
-
153
- $selected_fonts = array_filter($current_fonts, function ($font_style) use ($selected_fonts) {
154
- return in_array($font_style['font_id'], $selected_fonts);
155
- });
156
-
157
- foreach ($selected_fonts as &$font) {
158
- if (in_array($font['font_id'], $to_be_preloaded)) {
159
- $font['preload'] = 1;
160
- } else {
161
- $font['preload'] = 0;
162
- }
163
- }
164
-
165
- update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $selected_fonts);
166
-
167
- OMGF_Admin_Notice::set_notice(count($current_fonts) - count($selected_fonts) . ' ' . __('fonts removed from list and', $this->plugin_text_domain) . ' ' . 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>.', $this->plugin_text_domain), false);
168
- }
169
-
170
- /**
171
- * @return OMGF_AJAX_Download
172
- */
173
- public function download_fonts()
174
- {
175
- return new OMGF_AJAX_Download();
176
- }
177
-
178
- /**
179
- * @return OMGF_AJAX_Generate
180
- */
181
- public function generate_styles()
182
- {
183
- return new OMGF_AJAX_Generate();
184
- }
185
-
186
- /**
187
- * Empty cache directory.
188
- */
189
- public function empty_directory()
190
- {
191
- try {
192
- delete_option(OMGF_Admin_Settings::OMGF_SETTING_SUBSETS);
193
- delete_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS);
194
-
195
- array_map('unlink', array_filter((array) glob(OMGF_FONTS_DIR . '/*')));
196
-
197
- OMGF_Admin_Notice::set_notice(__('Cache directory successfully emptied.', $this->plugin_text_domain));
198
- } catch (\Exception $e) {
199
- OMGF_Admin_Notice::set_notice(__('Something went wrong while emptying the cache directory: ', $this->plugin_text_domain) . $e->getMessage(), true, 'error', $e->getCode());
200
- }
201
- }
202
  }
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
+ defined( 'ABSPATH' ) || exit;
18
 
19
  class OMGF_AJAX
20
  {
21
+ /** @var string $plugin_text_domain */
22
+ private $plugin_text_domain = 'host-webfonts-local';
23
+
24
+ /**
25
+ * OMGF_AJAX constructor.
26
+ */
27
+ public function __construct () {
28
+ add_action( 'wp_ajax_omgf_ajax_empty_dir', [ $this, 'empty_directory' ] );
29
+ }
30
+
31
+ /**
32
+ * Empty cache directory.
33
+ */
34
+ public function empty_directory () {
35
+ try {
36
+ $entries = array_filter( (array) glob( OMGF_FONTS_DIR . '/*' ) );
37
+
38
+ foreach ( $entries as $entry ) {
39
+ $this->delete( $entry );
40
+ }
41
+
42
+ OMGF_Admin_Notice::set_notice( __( 'Cache directory successfully emptied.', $this->plugin_text_domain ) );
43
+ } catch ( \Exception $e ) {
44
+ OMGF_Admin_Notice::set_notice(
45
+ __( 'Something went wrong while emptying the cache directory: ', $this->plugin_text_domain ) . $e->getMessage(),
46
+ true,
47
+ 'error',
48
+ $e->getCode()
49
+ );
50
+ }
51
+ }
52
+
53
+ /**
54
+ * @param $entry
55
+ */
56
+ public function delete ( $entry ) {
57
+ if ( is_dir( $entry ) ) {
58
+ $file = new \FilesystemIterator( $entry );
59
+
60
+ // If dir is empty, valid() returns false.
61
+ while ( $file->valid() ) {
62
+ $this->delete( $file->getPathName() );
63
+ $file->next();
64
+ }
65
+
66
+ rmdir( $entry );
67
+ } else {
68
+ unlink( $entry );
69
+ }
70
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
includes/class-api.php DELETED
@@ -1,99 +0,0 @@
1
- <?php
2
- /* * * * * * * * * * * * * * * * * * * * *
3
- *
4
- * ██████╗ ███╗ ███╗ ██████╗ ███████╗
5
- * ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
6
- * ██║ ██║██╔████╔██║██║ ███╗█████╗
7
- * ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
8
- * ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
9
- * ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
10
- *
11
- * @package : OMGF
12
- * @author : Daan van den Bergh
13
- * @copyright: (c) 2020 Daan van den Bergh
14
- * @url : https://daan.dev
15
- * * * * * * * * * * * * * * * * * * * */
16
-
17
- defined('ABSPATH') || exit;
18
-
19
- class OMGF_API
20
- {
21
- /**
22
- * @param $query
23
- *
24
- * @return array
25
- */
26
- public function get_subsets($query)
27
- {
28
- $response = wp_remote_get(OMGF_HELPER_URL . $query);
29
-
30
- if (wp_remote_retrieve_response_code($response) != 200) {
31
- $this->throw_error($response, $query);
32
-
33
- return [];
34
- }
35
-
36
- $result = json_decode(wp_remote_retrieve_body($response));
37
-
38
- return [
39
- 'subset_family' => $result->family,
40
- 'subset_font' => $result->id,
41
- 'available_subsets' => $result->subsets,
42
- 'selected_subsets' => []
43
- ];
44
- }
45
-
46
- /**
47
- * @param $font_family
48
- * @param $selected_subsets
49
- *
50
- * @return array
51
- */
52
- public function get_font_styles($font_family, $selected_subsets)
53
- {
54
- if (empty($font_family)) {
55
- return [];
56
- }
57
-
58
- $response = wp_remote_get(OMGF_HELPER_URL . $font_family . '?subsets=' . $selected_subsets);
59
-
60
- if (wp_remote_retrieve_response_code($response) != 200) {
61
- $this->throw_error($response, $font_family);
62
-
63
- return [];
64
- }
65
-
66
- $result = json_decode(wp_remote_retrieve_body($response));
67
-
68
- foreach ($result->variants as $variant) {
69
- $fonts[] = [
70
- 'font_id' => $result->id . '-' . $variant->id,
71
- 'font_family' => $variant->fontFamily,
72
- 'font_weight' => $variant->fontWeight,
73
- 'font_style' => $variant->fontStyle,
74
- 'local' => implode(',', $variant->local ?? []),
75
- 'preload' => 0,
76
- 'downloaded' => 0,
77
- 'url_ttf' => $variant->ttf,
78
- 'url_woff' => $variant->woff,
79
- 'url_woff2' => $variant->woff2,
80
- 'url_eot' => $variant->eot
81
- ];
82
- }
83
-
84
- return $fonts;
85
- }
86
-
87
- /**
88
- * Throw error based on response
89
- *
90
- * @param $response
91
- * @param $query
92
- */
93
- private function throw_error($response, $query)
94
- {
95
- $message = wp_remote_retrieve_response_message($response);
96
- $code = wp_remote_retrieve_response_code($response);
97
- OMGF_Admin_Notice::set_notice(sprintf(__('An error occurred while searching for %s: %s', 'host-webfonts-local'), $query, $message), false, 'error', $code);
98
- }
99
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-db.php DELETED
@@ -1,104 +0,0 @@
1
- <?php
2
- /* * * * * * * * * * * * * * * * * * * * *
3
- *
4
- * ██████╗ ███╗ ███╗ ██████╗ ███████╗
5
- * ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
6
- * ██║ ██║██╔████╔██║██║ ███╗█████╗
7
- * ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
8
- * ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
9
- * ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
10
- *
11
- * @package : OMGF
12
- * @author : Daan van den Bergh
13
- * @copyright: (c) 2020 Daan van den Bergh
14
- * @url : https://daan.dev
15
- * * * * * * * * * * * * * * * * * * * */
16
-
17
- defined('ABSPATH') || exit;
18
-
19
- class OMGF_DB
20
- {
21
- /** @var QM_DB $wpdb */
22
- private $wpdb;
23
-
24
- /**
25
- * OMGF_DB constructor.
26
- */
27
- public function __construct()
28
- {
29
- global $wpdb;
30
-
31
- $this->wpdb = $wpdb;
32
- }
33
-
34
- /**
35
- * @param bool $clean
36
- *
37
- * @return array|Exception
38
- */
39
- public function get_downloaded_fonts($clean = false)
40
- {
41
- try {
42
- $fonts = $this->get_total_fonts();
43
-
44
- $downloaded = array_filter($fonts, function($font) {
45
- return $font['downloaded'] == 1;
46
- });
47
-
48
- if ($clean) {
49
- foreach ($downloaded as &$download) {
50
- $download['font_family'] = str_replace('\'', '', $download['font_family']);
51
- }
52
- }
53
-
54
- return $downloaded;
55
- } catch (\Exception $e) {
56
- return $e;
57
- }
58
- }
59
-
60
- /**
61
- * @return array|Exception
62
- */
63
- public function get_preload_fonts()
64
- {
65
- try {
66
- $fonts = $this->get_total_fonts();
67
-
68
- $preload = array_filter($fonts, function($font) {
69
- return $font['preload'] == 1;
70
- });
71
-
72
- return $preload;
73
- } catch(\Exception $e) {
74
- return $e;
75
- }
76
- }
77
-
78
- /**
79
- * @return array
80
- */
81
- public function get_total_fonts()
82
- {
83
- return get_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS) ?: [];
84
- }
85
-
86
- /**
87
- * @return array
88
- */
89
- public function get_subsets()
90
- {
91
- return get_option(OMGF_Admin_Settings::OMGF_SETTING_SUBSETS) ?: [];
92
- }
93
-
94
- /**
95
- * @return bool
96
- */
97
- public function clean_queue()
98
- {
99
- delete_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS);
100
- delete_option(OMGF_Admin_Settings::OMGF_SETTING_SUBSETS);
101
-
102
- return true;
103
- }
104
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-omgf.php CHANGED
@@ -18,46 +18,23 @@ defined('ABSPATH') || exit;
18
 
19
  class OMGF
20
  {
21
- /**
22
- * @var array These cache plugins empty the entire cache-folder, instead of just removing
23
- * its own files.
24
- */
25
- const OMGF_EVIL_PLUGINS = [
26
- 'WP Super Cache' => 'wp-super-cache/wp-cache.php',
27
- 'WP Rocket' => 'wp-rocket/wp-rocket.php'
28
- ];
29
-
30
- /** @var string */
31
- private $page = '';
32
-
33
  /**
34
  * OMGF constructor.
35
  */
36
  public function __construct()
37
  {
38
  $this->define_constants();
39
- $this->page = isset($_GET['page']) ?: '';
40
 
41
  if (is_admin()) {
42
  $this->do_settings();
43
  $this->add_ajax_hooks();
44
-
45
- /**
46
- * If auto detect can't finish properly, due to e.g. an invalid API response, OMGF's settings page crashes.
47
- * This will prevent it from crashing the entire admin area.
48
- */
49
- if ($this->page == 'optimize-webfonts') {
50
- $this->do_auto_detect();
51
- }
52
-
53
- add_action('plugin_loaded', array($this, 'do_setup'));
54
  }
55
 
56
  if (!is_admin()) {
57
  add_action('plugins_loaded', [$this, 'do_frontend']);
58
  }
59
-
60
- register_activation_hook(OMGF_PLUGIN_FILE, [$this, 'check_cache_plugins']);
61
  }
62
 
63
  /**
@@ -65,28 +42,15 @@ class OMGF
65
  */
66
  public function define_constants()
67
  {
68
- global $wpdb;
69
-
70
  define('OMGF_SITE_URL', 'https://daan.dev');
71
- define('OMGF_DB_TABLENAME', $wpdb->prefix . 'omgf_fonts'); // legacy
72
- define('OMGF_DB_CHARSET', $wpdb->get_charset_collate());
73
- define('OMGF_HELPER_URL', 'https://google-webfonts-helper.herokuapp.com/api/fonts/');
74
- define('OMGF_FILENAME', 'fonts.css');
75
- define('OMGF_AUTO_DETECT_ENABLED', esc_attr(get_option(OMGF_Admin_Settings::OMGF_SETTING_AUTO_DETECTION_ENABLED, false)));
76
- define('OMGF_CACHE_PATH', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_PATH)) ?: '/uploads/omgf');
77
- define('OMGF_CACHE_URI', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI)) ?: '');
78
- define('OMGF_FORCE_SSL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_FORCE_SSL)));
79
- define('OMGF_RELATIVE_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL)));
80
- define('OMGF_CDN_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL)));
81
- define('OMGF_WEB_FONT_LOADER', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_WEB_FONT_LOADER)));
82
- define('OMGF_REMOVE_VERSION', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_VERSION)));
83
- define('OMGF_CURRENT_BLOG_ID', get_current_blog_id());
84
- define('OMGF_FONTS_DIR', WP_CONTENT_DIR . OMGF_CACHE_PATH);
85
- define('OMGF_FONTS_URL', $this->get_fonts_url());
86
- define('OMGF_DISPLAY_OPTION', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_DISPLAY_OPTION, 'swap')) ?: 'swap');
87
- define('OMGF_REMOVE_GFONTS', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_REMOVE_GOOGLE_FONTS)));
88
- define('OMGF_ENQUEUE_ORDER', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_ENQUEUE_ORDER, 10)));
89
- define('OMGF_OPTIMIZE_EDIT_ROLES', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_OPTIMIZE_EDIT_ROLES, 'on')));
90
  define('OMGF_UNINSTALL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL)));
91
  }
92
 
@@ -106,28 +70,6 @@ class OMGF
106
  return new OMGF_AJAX();
107
  }
108
 
109
- /**
110
- * @return OMGF_Admin_AutoDetect|void
111
- */
112
- public function do_auto_detect()
113
- {
114
- $fonts = json_decode(get_option(OMGF_Admin_Settings::OMGF_SETTING_DETECTED_FONTS));
115
-
116
- if (OMGF_AUTO_DETECT_ENABLED && $fonts) {
117
- return new OMGF_Admin_AutoDetect($fonts);
118
- }
119
- }
120
-
121
- /**
122
- * @return OMGF_Setup
123
- */
124
- public function do_setup()
125
- {
126
- register_uninstall_hook(OMGF_PLUGIN_FILE, 'OMGF::do_uninstall');
127
-
128
- return new OMGF_Setup();
129
- }
130
-
131
  /**
132
  * @return OMGF_Frontend_Functions
133
  */
@@ -135,66 +77,15 @@ class OMGF
135
  {
136
  return new OMGF_Frontend_Functions();
137
  }
138
-
139
- /**
140
- * Throw a warning if any of the Evil Cache Plugins are used.
141
- */
142
- public function check_cache_plugins()
143
- {
144
- if (strpos(OMGF_CACHE_PATH, '/cache/') === false) {
145
- return;
146
- }
147
-
148
- $cache_path = OMGF_CACHE_PATH;
149
- $admin_url = admin_url('options-general.php?page=optimize-webfonts&tab=advanced-settings');
150
-
151
- foreach (self::OMGF_EVIL_PLUGINS as $name => $basename) {
152
- if (is_plugin_active($basename)) {
153
- OMGF_Admin_Notice::set_notice(sprintf(__("It looks like <strong>you're using %s</strong>. This plugin empties the entire <code>wp-content/cache</code> folder after a cache flush. To prevent this, <strong>move OMGF's fonts</strong> by changing the <em>Save font files to...</em> option under OMGF's <a href='%s'>Advanced Settings</a> from <code>%s</code> to something else, e.g. <code>/omgf-cache</code>.", 'host-webfonts-local'), $name, $admin_url, $cache_path), false, 'warning');
154
- }
155
- }
156
- }
157
-
158
- /**
159
- * Returns the configured name of WordPress' content directory.
160
- *
161
- * @return mixed
162
- */
163
- private function get_content_dir()
164
- {
165
- if (OMGF_CACHE_URI) {
166
- $match = array_filter(explode('/', OMGF_CACHE_URI));
167
- $match = array_values($match);
168
- } else {
169
- preg_match('/[^\/]+$/u', WP_CONTENT_DIR, $match);
170
- }
171
-
172
- return $match[0];
173
- }
174
-
175
- /**
176
- * @return string
177
- */
178
- public function get_fonts_url()
179
- {
180
- if (OMGF_RELATIVE_URL) {
181
- return '/' . $this->get_content_dir() . OMGF_CACHE_PATH;
182
- }
183
-
184
- if (OMGF_CDN_URL) {
185
- $uploadUrl = '//' . OMGF_CDN_URL . '/' . $this->get_content_dir() . OMGF_CACHE_PATH;
186
- } elseif (OMGF_CACHE_URI) {
187
- $uploadUrl = get_site_url(OMGF_CURRENT_BLOG_ID, OMGF_CACHE_URI);
188
- } else {
189
- $uploadUrl = get_site_url(OMGF_CURRENT_BLOG_ID, $this->get_content_dir() . OMGF_CACHE_PATH);
190
- }
191
-
192
- if (OMGF_FORCE_SSL) {
193
- $uploadUrl = str_replace('http://', 'https://', $uploadUrl);
194
- }
195
-
196
- return $uploadUrl;
197
- }
198
 
199
  /**
200
  * @return OMGF_Uninstall
18
 
19
  class OMGF
20
  {
 
 
 
 
 
 
 
 
 
 
 
 
21
  /**
22
  * OMGF constructor.
23
  */
24
  public function __construct()
25
  {
26
  $this->define_constants();
 
27
 
28
  if (is_admin()) {
29
  $this->do_settings();
30
  $this->add_ajax_hooks();
 
 
 
 
 
 
 
 
 
 
31
  }
32
 
33
  if (!is_admin()) {
34
  add_action('plugins_loaded', [$this, 'do_frontend']);
35
  }
36
+
37
+ add_action('rest_api_init', [$this, 'register_routes']);
38
  }
39
 
40
  /**
42
  */
43
  public function define_constants()
44
  {
 
 
45
  define('OMGF_SITE_URL', 'https://daan.dev');
46
+ define('OMGF_FONT_PROCESSING', esc_attr(get_option(OMGF_Admin_Settings::OMGF_BASIC_SETTING_FONT_PROCESSING, 'replace')));
47
+ define('OMGF_DISPLAY_OPTION', esc_attr(get_option( OMGF_Admin_Settings::OMGF_BASIC_SETTING_DISPLAY_OPTION, 'swap')) ?: 'swap');
48
+ define('OMGF_OPTIMIZE_EDIT_ROLES', esc_attr(get_option( OMGF_Admin_Settings::OMGF_BASIC_SETTING_OPTIMIZE_EDIT_ROLES, 'on')));
49
+ define('OMGF_CACHE_PATH', esc_attr(get_option(OMGF_Admin_Settings::OMGF_BASIC_SETTING_CACHE_PATH)) ?: '/uploads/omgf');
50
+ define('OMGF_CACHE_URI', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CACHE_URI)) ?: '');
51
+ define('OMGF_RELATIVE_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_RELATIVE_URL)));
52
+ define('OMGF_CDN_URL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_CDN_URL)));
53
+ define('OMGF_FONTS_DIR', WP_CONTENT_DIR . OMGF_CACHE_PATH);
 
 
 
 
 
 
 
 
 
 
 
54
  define('OMGF_UNINSTALL', esc_attr(get_option(OMGF_Admin_Settings::OMGF_ADV_SETTING_UNINSTALL)));
55
  }
56
 
70
  return new OMGF_AJAX();
71
  }
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  /**
74
  * @return OMGF_Frontend_Functions
75
  */
77
  {
78
  return new OMGF_Frontend_Functions();
79
  }
80
+
81
+ /**
82
+ *
83
+ */
84
+ public function register_routes()
85
+ {
86
+ $proxy = new OMGF_API_Download();
87
+ $proxy->register_routes();
88
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
  /**
91
  * @return OMGF_Uninstall
includes/class-setup.php DELETED
@@ -1,102 +0,0 @@
1
- <?php
2
- /* * * * * * * * * * * * * * * * * * * * *
3
- *
4
- * ██████╗ ███╗ ███╗ ██████╗ ███████╗
5
- * ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
6
- * ██║ ██║██╔████╔██║██║ ███╗█████╗
7
- * ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
8
- * ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
9
- * ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
10
- *
11
- * @package : OMGF
12
- * @author : Daan van den Bergh
13
- * @copyright: (c) 2020 Daan van den Bergh
14
- * @url : https://daan.dev
15
- * * * * * * * * * * * * * * * * * * * */
16
-
17
- defined('ABSPATH') || exit;
18
-
19
- class OMGF_Setup
20
- {
21
- /** @var QM_DB $wpdb */
22
- private $wpdb;
23
-
24
- /** @var string $version */
25
- private $version;
26
-
27
- /** @var string $table */
28
- private $table;
29
-
30
- /**
31
- * OMGF_Admin_Setup constructor.
32
- */
33
- public function __construct()
34
- {
35
- global $wpdb;
36
-
37
- $this->wpdb = $wpdb;
38
- $this->version = get_option(OMGF_Admin_Settings::OMGF_SETTING_DB_VERSION);
39
- $this->table = OMGF_DB_TABLENAME;
40
-
41
- if (version_compare($this->version, OMGF_DB_VERSION) < 0) {
42
- $this->run_db_updates();
43
- }
44
- }
45
-
46
- /**
47
- * Run initial database updates.
48
- */
49
- public function run_db_updates()
50
- {
51
- $table_exists = $this->wpdb->query("SHOW TABLES LIKE '" . OMGF_DB_TABLENAME . "'");
52
-
53
- if ($table_exists) {
54
- $this->migrate_db();
55
- }
56
-
57
- $this->drop_tables();
58
- }
59
-
60
- /**
61
- *
62
- */
63
- private function migrate_db()
64
- {
65
- $current_fonts = $this->wpdb->get_results("SELECT * FROM " . OMGF_DB_TABLENAME);
66
- $fonts_array = json_decode(json_encode($current_fonts), true);
67
-
68
- update_option(OMGF_Admin_Settings::OMGF_SETTING_FONTS, $fonts_array);
69
-
70
- $current_subsets = $this->wpdb->get_results("SELECT * FROM " . OMGF_DB_TABLENAME . '_subsets');
71
- $subsets_array = json_decode(json_encode($current_subsets), true);
72
-
73
- foreach ($subsets_array as &$subset) {
74
- $available = $subset['available_subsets'];
75
- $selected = $subset['selected_subsets'];
76
- $subset['available_subsets'] = strpos($available, ',') !== false ? explode(',', $available) : [ $available ];
77
- $subset['selected_subsets'] = strpos($selected, ',') !== false ? explode(',', $selected) : [ $selected ];
78
- }
79
-
80
- update_option(OMGF_Admin_Settings::OMGF_SETTING_SUBSETS, $subsets_array);
81
- }
82
-
83
- /**
84
- * Drop all tables associated with OMGF.
85
- */
86
- private function drop_tables()
87
- {
88
- $this->wpdb->query(
89
- 'DROP TABLE IF EXISTS ' . $this->table . ', ' . $this->table . '_subsets;'
90
- );
91
-
92
- $this->set_db_version(OMGF_DB_VERSION);
93
- }
94
-
95
- /**
96
- * @param $value
97
- */
98
- private function set_db_version($value)
99
- {
100
- update_option(OMGF_Admin_Settings::OMGF_SETTING_DB_VERSION, $value);
101
- }
102
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/frontend/class-functions.php CHANGED
@@ -14,210 +14,117 @@
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
- defined('ABSPATH') || exit;
18
 
19
  class OMGF_Frontend_Functions
20
  {
21
- const OMGF_STYLE_HANDLE = 'omgf-fonts';
22
-
23
- /** @var OMGF_DB */
24
- private $db;
25
-
26
- /** @var string */
27
- private $stylesheet_file;
28
-
29
- /** @var string */
30
- private $stylesheet_url;
31
-
32
- /** @var bool $do_optimize */
33
- private $do_optimize;
34
-
35
- /**
36
- * OMGF_Frontend_Functions constructor.
37
- */
38
- public function __construct()
39
- {
40
- $this->stylesheet_file = OMGF_FONTS_DIR . '/' . OMGF_FILENAME;
41
- $this->stylesheet_url = OMGF_FONTS_URL . '/' . OMGF_FILENAME;
42
- $this->do_optimize = $this->maybe_optimize_fonts();
43
-
44
- // @formatter:off
45
- add_action('wp_print_styles', [$this, 'is_remove_google_fonts_enabled'], PHP_INT_MAX - 1000);
46
-
47
- if (file_exists($this->stylesheet_file)) {
48
- add_action('wp_enqueue_scripts', [$this, 'enqueue_stylesheet'], OMGF_ENQUEUE_ORDER);
49
- }
50
-
51
- if (OMGF_AUTO_DETECT_ENABLED) {
52
- add_action('wp_print_styles', [$this, 'auto_detect_fonts'], PHP_INT_MAX - 10000);
53
- }
54
-
55
- $this->db = new OMGF_DB();
56
- // Needs to be loaded before stylesheet.
57
- add_action('wp_head', [$this, 'preload_fonts'], 1);
58
- // @formatter:on
59
- }
60
-
61
- /**
62
- * Check if the Remove Google Fonts option is enabled.
63
- */
64
- public function is_remove_google_fonts_enabled()
65
- {
66
- if (!$this->do_optimize) {
67
- return;
68
- }
69
-
70
- if (OMGF_REMOVE_GFONTS == 'on' && !is_admin()) {
71
- // @formatter:off
72
- add_action('wp_print_styles', [$this, 'remove_google_fonts'], PHP_INT_MAX - 500);
73
- // Theme: Enfold
74
- add_filter('avf_output_google_webfonts_script', function() { return false; });
75
- // @formatter:on
76
- }
77
- }
78
-
79
- /**
80
- * Should we optimize for logged in editors/administrators?
81
- *
82
- * @return bool
83
- */
84
- private function maybe_optimize_fonts()
85
- {
86
- if (!OMGF_OPTIMIZE_EDIT_ROLES && current_user_can('edit_pages')) {
87
- return false;
88
- }
89
-
90
- return true;
91
- }
92
-
93
- /**
94
- * Automatically dequeues any stylesheets loaded from fonts.gstatic.com or
95
- * fonts.googleapis.com. Also checks for stylesheets dependant on Google Fonts and
96
- * re-enqueues and registers them.
97
- */
98
- public function remove_google_fonts()
99
- {
100
- if (apply_filters('omgf_pro_auto_remove_enabled', false)) {
101
- return;
102
- }
103
-
104
- global $wp_styles;
105
-
106
- $registered = $wp_styles->registered;
107
- $fonts = $this->detect_registered_google_fonts($registered);
108
- $dependencies = array_filter(
109
- $registered, function ($contents) use ($fonts) {
110
- return !empty(array_intersect(array_keys($fonts), $contents->deps))
111
- && $contents->handle !== 'wp-block-editor';
112
- }
113
- );
114
-
115
- foreach ($fonts as $font) {
116
- wp_deregister_style($font->handle);
117
- wp_dequeue_style($font->handle);
118
- }
119
-
120
- foreach ($dependencies as $dependency) {
121
- /**
122
- * If Remove Google Fonts is enabled, but no stylesheet is generated, there's no need to add OMGF's stylesheet
123
- * as a dependency.
124
- */
125
- $deps = array_diff($dependency->deps, array_keys($fonts)) + (isset($registered['omgf-fonts']) ? ['omgf-fonts'] : []);
126
- wp_deregister_style($dependency->handle);
127
- wp_dequeue_style($dependency->handle);
128
-
129
- wp_register_style($dependency->handle, $dependency->src, $deps);
130
- wp_enqueue_style($dependency->handle, $dependency->src, $deps);
131
- }
132
- }
133
-
134
- /**
135
- * @param $registered_styles
136
- *
137
- * @return array
138
- */
139
- private function detect_registered_google_fonts($registered_styles)
140
- {
141
- return array_filter(
142
- $registered_styles,
143
- function ($contents) {
144
- return strpos($contents->src, 'fonts.googleapis.com/css') !== false
145
- || strpos($contents->src, 'fonts.gstatic.com') !== false;
146
- }
147
- );
148
- }
149
-
150
- /**
151
- * Once the stylesheet is generated. We can enqueue it.
152
- */
153
- public function enqueue_stylesheet()
154
- {
155
- if (!$this->do_optimize) {
156
- return;
157
- }
158
-
159
- if (OMGF_WEB_FONT_LOADER) {
160
- $this->get_template('web-font-loader');
161
- } else {
162
- wp_enqueue_style(self::OMGF_STYLE_HANDLE, OMGF_FONTS_URL . '/' . OMGF_FILENAME, array(), (OMGF_REMOVE_VERSION ? null : OMGF_STATIC_VERSION));
163
- }
164
- }
165
-
166
- /**
167
- * @param $name
168
- */
169
- public function get_template($name)
170
- {
171
- include OMGF_PLUGIN_DIR . 'templates/frontend-' . $name . '.phtml';
172
- }
173
-
174
- /**
175
- * Saves the used Google Fonts in the database, so it can be used by auto-detection.
176
- */
177
- public function auto_detect_fonts()
178
- {
179
- if (apply_filters('omgf_pro_auto_detect_enabled', false)) {
180
- return;
181
- }
182
-
183
- global $wp_styles;
184
-
185
- $registered = $wp_styles->registered;
186
-
187
- $fonts = $this->detect_registered_google_fonts($registered);
188
-
189
- foreach ($fonts as $font) {
190
- $google_fonts_src[] = $font->src;
191
- }
192
-
193
- update_option(OMGF_Admin_Settings::OMGF_SETTING_DETECTED_FONTS, json_encode($google_fonts_src));
194
- }
195
-
196
- /**
197
- * Collect and render preload fonts in wp_head().
198
- */
199
- public function preload_fonts()
200
- {
201
- if (!$this->do_optimize) {
202
- return;
203
- }
204
-
205
- $preload_fonts = $this->db->get_preload_fonts();
206
-
207
- if (!$preload_fonts) {
208
- return;
209
- }
210
-
211
- foreach ($preload_fonts as $font) {
212
- $font_urls[] = array_values(array_filter((array) $font, function ($properties) {
213
- return strpos($properties, 'woff2_local') !== false;
214
- }, ARRAY_FILTER_USE_KEY));
215
- }
216
-
217
- $urls = array_reduce($font_urls, 'array_merge', []);
218
-
219
- foreach ($urls as $url) {
220
- echo "<link rel='preload' href='$url' as='font' type='font/" . pathinfo($url, PATHINFO_EXTENSION) . "' crossorigin />\n";
221
- }
222
- }
223
  }
14
  * @url : https://daan.dev
15
  * * * * * * * * * * * * * * * * * * * */
16
 
17
+ defined( 'ABSPATH' ) || exit;
18
 
19
  class OMGF_Frontend_Functions
20
  {
21
+ const OMGF_STYLE_HANDLE = 'omgf-fonts';
22
+
23
+ /** @var bool $do_optimize */
24
+ private $do_optimize;
25
+
26
+ /**
27
+ * OMGF_Frontend_Functions constructor.
28
+ */
29
+ public function __construct () {
30
+ $this->do_optimize = $this->maybe_optimize_fonts();
31
+
32
+ add_action( 'wp_print_styles', [ $this, 'process_fonts' ], PHP_INT_MAX - 1000 );
33
+ }
34
+
35
+ /**
36
+ * Should we optimize for logged in editors/administrators?
37
+ *
38
+ * @return bool
39
+ */
40
+ private function maybe_optimize_fonts () {
41
+ if ( ! OMGF_OPTIMIZE_EDIT_ROLES && current_user_can( 'edit_pages' ) ) {
42
+ return false;
43
+ }
44
+
45
+ return true;
46
+ }
47
+
48
+ /**
49
+ * Check if the Remove Google Fonts option is enabled.
50
+ */
51
+ public function process_fonts () {
52
+ if ( ! $this->do_optimize ) {
53
+ return;
54
+ }
55
+
56
+ if ( apply_filters( 'omgf_pro_advanced_processing_enabled', false ) ) {
57
+ return;
58
+ }
59
+
60
+ if ( is_admin() ) {
61
+ return;
62
+ }
63
+
64
+ switch ( OMGF_FONT_PROCESSING ) {
65
+ case 'remove':
66
+ add_action( 'wp_print_styles', [ $this, 'remove_registered_fonts' ], PHP_INT_MAX - 500 );
67
+ break;
68
+ default:
69
+ add_action( 'wp_print_styles', [ $this, 'replace_registered_fonts' ], PHP_INT_MAX - 500 );
70
+ }
71
+ }
72
+
73
+ /**
74
+ * This function contains a nice little hack, to avoid messing with potential dependency issues. We simply set the source to an empty string!
75
+ */
76
+ public function remove_registered_fonts () {
77
+ global $wp_styles;
78
+
79
+ $registered = $wp_styles->registered;
80
+ $fonts = apply_filters( 'omgf_auto_remove', $this->detect_registered_google_fonts( $registered ) );
81
+
82
+ foreach ( $fonts as $handle => $font ) {
83
+ $wp_styles->registered [ $handle ]->src = '';
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Retrieve stylesheets from Google Fonts' API and modify the stylesheet for local storage.
89
+ */
90
+ public function replace_registered_fonts () {
91
+ global $wp_styles;
92
+
93
+ $registered = $wp_styles->registered;
94
+ $fonts = apply_filters( 'omgf_auto_replace', $this->detect_registered_google_fonts( $registered ) );
95
+
96
+ foreach ( $fonts as $handle => $font ) {
97
+ $cached_file = OMGF_CACHE_PATH . '/' . $handle . "/$handle.css";
98
+
99
+ if ( file_exists( WP_CONTENT_DIR . $cached_file ) ) {
100
+ $wp_styles->registered[ $handle ]->src = content_url( $cached_file );
101
+
102
+ continue;
103
+ }
104
+
105
+ $wp_styles->registered[ $handle ]->src = str_replace( 'https://fonts.googleapis.com/', site_url( '/wp-json/omgf/v1/download/' ), $font->src ) . "&handle=$handle";
106
+ }
107
+ }
108
+
109
+ /**
110
+ * @param $registered_styles
111
+ *
112
+ * @return array
113
+ */
114
+ private function detect_registered_google_fonts ( $registered_styles ) {
115
+ return array_filter(
116
+ $registered_styles,
117
+ function ( $contents ) {
118
+ return strpos( $contents->src, 'fonts.googleapis.com/css' ) !== false
119
+ || strpos( $contents->src, 'fonts.gstatic.com' ) !== false;
120
+ }
121
+ );
122
+ }
123
+
124
+ /**
125
+ * @param $name
126
+ */
127
+ public function get_template ( $name ) {
128
+ include OMGF_PLUGIN_DIR . 'templates/frontend-' . $name . '.phtml';
129
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  }
readme.md CHANGED
@@ -1,14 +1,41 @@
1
  # OMGF | Host Google Fonts Locally
2
 
3
- With only 2 clicks of a button, OMGF automagically downloads your Google Fonts you want to WordPress' content-folder, generates a stylesheet for it and enqueues it in your theme's header.
4
 
5
  ## Description
6
 
7
- OMGF (Optimize My Google Fonts) is written with performance in mind. Other plugins make repeated requests to your Blog's database to replace/remove requests to external Webfonts source (e.g. Google Fonts) on-the-fly. This might be user-friendly, but it's a performance killer, because locally hosting your Google Webfonts should be a set-and-forget feature. The source of your webfonts should be replaced once and kept that way.
 
8
 
9
- That's why I kept OMGF small and useful. It uses the Google Fonts Helper API to automagically download the fonts you want to WordPress' contents folder and generate a stylesheet for it. The stylesheet is automatically included to your site's header and 100% compatible with plugins like Autoptimize or W3 Total Cache. After that, all you need to do is remove any mention of requests to external webfont sources (using e.g. a child theme) and you're done!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- This will *decrease your pageload times*, *leverage browser cache*, *minimize DNS requests* and effectively bring you a perfect score on *Pagespeed Insights* and *Pingdom*, without taking toll on the performance of your webserver.
12
 
13
  ## Installation
14
 
@@ -26,8 +53,6 @@ This will *decrease your pageload times*, *leverage browser cache*, *minimize DN
26
 
27
  ## Frequently Asked Questions
28
 
29
- **Can I buy you a beer?**
30
-
31
  Visit the [FAQ at Wordpress.org](https://wordpress.org/plugins/host-webfonts-local/#faq)
32
 
33
  ## Support
1
  # OMGF | Host Google Fonts Locally
2
 
3
+ OMGF automagically caches the Google Fonts used by your theme/plugins locally. No configuration (or brains) required!
4
 
5
  ## Description
6
 
7
+ > How could using fonts via Google's service possibly run afoul of GDPR? The fact of the matter is that, when a font is requested by the user's browser, their IP is logged by Google and used for analytics.
8
+ > — Lifehacker
9
 
10
+ Leverage Browser Cache, Minimize DNS requests and serve your Google Fonts in a 100% GDPR compliant way with OMGF!
11
+
12
+ OMGF is written with performance and user-friendliness in mind. It uses the Google Fonts Helper API to automatically cache the fonts your theme and plugins use to **minimize DNS requests** and speed up your WordPress website.
13
+
14
+ ### How Does It Work?
15
+
16
+ After installing the plugin, OMGF runs silently in the background and captures any requests made to fonts.googleapis.com or fonts.gstatic.com. When a webpage is first loaded, it reroutes these requests to its own Download API and copies the fonts over to your server. Then it generates a stylesheet for your fonts including EOT, TTF, WOFF and WOFF2 formats to guarantee maximum cross browser compatibility!
17
+
18
+ When the fonts are downloaded and the stylesheet is generated, it rewrites every URL pointing to fonts.googleapis.com or fonts.gstatic.com to the locally hosted variant.
19
+
20
+ Please keep in mind that, although I try to make the configuration of this plugin as easy as possible, the concept of locally hosting a file or optimizing Google Fonts for *Pagespeed Insights* or *GT Metrix* has proven to be confusing for some people. If you're not sure of what your doing, please consult a SEO expert or Webdeveloper to help you with the configuration of this plugin or [hire me to do it for you](https://ffwp.dev/wordpress/omgf-expert-configuration/).
21
+
22
+ ### Features
23
+ - Automatically replace registered/enqueued Google Fonts in `wp_head()` with local copies,
24
+ - Automatically remove registered/enqueued Google Fonts from `wp_head()`,
25
+ - Leverage the font-display (swap) option,
26
+ - Serve fonts from CDN,
27
+ - Use OMGF with *security through obscurity* plugins.
28
+
29
+ ### Features in the PRO version
30
+ Everything in the free version, plus:
31
+ - Automatically remove/replace all Google Fonts throughout the entire HTML document,
32
+ - Combine all Google Fonts (made by your theme and/or plugins) requests into one file,
33
+ - Deduplicate Google Fonts requests,
34
+ - Reduce loading time and page size, by forcing the used subset(s) for all Google Fonts requests,
35
+ - Remove Resource Hints (preload, preconnect, dns-prefetch) pointing to fonts.googleapis.com or fonts.gstatic.com.
36
+
37
+ *Click [here](https://ffwp.dev/wordpress/omgf-pro/) for more information and to purchase OMGF Pro.*
38
 
 
39
 
40
  ## Installation
41
 
53
 
54
  ## Frequently Asked Questions
55
 
 
 
56
  Visit the [FAQ at Wordpress.org](https://wordpress.org/plugins/host-webfonts-local/#faq)
57
 
58
  ## Support
readme.txt CHANGED
@@ -3,12 +3,12 @@ Contributors: DaanvandenBergh
3
  Tags: google, fonts, gdpr, cache, speed, preload, font-display, webfonts, subsets, remove, minimize, external, requests
4
  Requires at least: 4.6
5
  Tested up to: 5.5
6
- Stable tag: 3.8.2
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- With only 2 clicks of a button, OMGF automagically downloads your Google Fonts you want to WordPress' content-folder, generates a stylesheet for it and enqueues it in your theme's header.
12
 
13
  == Description ==
14
 
@@ -17,25 +17,32 @@ With only 2 clicks of a button, OMGF automagically downloads your Google Fonts y
17
 
18
  Leverage Browser Cache, Minimize DNS requests and serve your Google Fonts in a 100% GDPR compliant way with OMGF!
19
 
20
- OMGF is written with performance and user-friendliness in mind. It uses the Google Fonts Helper API to automagically download the fonts you want to WordPress' contents folder and generate a stylesheet for it. The stylesheet is automatically included to your site's header and 100% compatible with CSS and JS optimizing/minification plugins like Autoptimize or W3 Total Cache. OMGF can efficiently remove any requests to external Google Fonts (loaded from fonts.gstatic.com or fonts.googleapis.com).
21
 
22
- That's it. You're done!
23
 
24
- This will *decrease your pageload times*, *leverage browser cache*, *minimize DNS requests* and effectively bring you a perfect score on *Pagespeed Insights* and *Pingdom*, without taking toll on the performance of your webserver.
25
 
26
- Please keep in mind that, although I try to make the configuration of this plugin as easy as possible, the concept of locally hosting a file or optimizing Google Fonts for *Pagespeed Insights* or *GT Metrix* has proven to be confusing for some people. If you're not sure of what your doing, please consult a SEO expert or Webdeveloper to help you with the configuration of this plugin or [hire me to do it for you](https://woosh.dev/wordpress-services/omgf-expert-configuration/).
27
 
28
- == Features ==
29
- - *Automatically detect* which Google Fonts your theme is using or,
30
- - Easily find fonts in multiple subsets,
31
- - Download them and generate a stylesheet, which is automatically added to your header using WordPress' wp_head()-function,
32
- - Change the caching path (where the fonts and stylesheet are saved) for increased compatibility with Multisite environments and Caching- and Security-plugins, such as WP Super Cache, Autoptimize and WordFence,
33
- - Serve your fonts from your CDN,
34
- - Enable Typekit's [Web Font Loader](https://github.com/typekit/webfontloader) to load your fonts asynchronously and further increase your Pagespeed Insights score (!),
35
- - Preload the entire stylesheet or just fonts loaded above-the-fold,
36
- - Control font performance by adding font-display property,
37
- - Auto-generates the local source for webfonts,
38
- - Automatically remove any fonts loaded from fonts.gstatic.com or fonts.googleapis.com.
 
 
 
 
 
 
 
39
 
40
  == Installation ==
41
 
@@ -47,13 +54,17 @@ For a more comprehensive guide for configuration, click [here](https://daan.dev/
47
 
48
  == Frequently Asked Questions ==
49
 
 
 
 
 
50
  = I don't know what I'm doing! Can you help? =
51
 
52
  Of course :) But first calm down and read this [comprehensive guide on how to configure OMGF](https://daan.dev/wordpress/host-google-fonts-locally/). If you have any questions afterwards, visit the [Support Forum](https://wordpress.org/support/plugin/host-webfonts-local).
53
 
54
  = I have another file I want to host locally. Could you make a plugin? =
55
 
56
- Maintaining three plugins besides my daily 9-to-5 job is a handful, so no. If you're looking for a way to host analytics.js locally; please install [CAOS](https://wordpress.org/plugins/host-analyticsjs-local/). To host other 3rd party scripts and styles locally, try [HELL](https://wordpress.org/plugins/host-everything-local/). For anything else, please follow the steps in [this how-to](https://daan.dev/how-to/host-js-locally-crontab/).
57
 
58
  = How come my font isn't available in OMGF? =
59
 
@@ -63,44 +74,33 @@ This could be for several reasons:
63
 
64
  = Does this plugin remove resource hints, e.g. preconnect, preload or dns-prefetch? =
65
 
66
- No, to automatically remove resource hints pointing to fonts.googleapis.com or fonts.gstatic.com, [upgrade to OMGF Pro](https://woosh.dev/wordpress-plugins/host-google-fonts-pro/).
67
 
68
  = Can I serve the fonts from my CDN? =
69
 
70
- Yes, you can. Enter the url of your CDN and re-download and re-generate the stylesheet. Then the fonts will be saved to and served from your CDN.
71
 
72
- = How can I make sure the fonts load asynchronously AKA non-render blocking?
73
 
74
- Enable Typekit's Web Font Loader in the settings and OMGF will take care of it for you!
75
-
76
- = I'm getting a 'Load resources from a consistent URL' after installing and configuring this plugin. What's going on? =
77
-
78
- This must be, because you're still loading the externally hosted Google Fonts, besides the fonts you downloaded using OMGF. Try checking the option 'Remove Google Fonts' and see if that helps. If it doesn't consider using a child theme to 'dequeue' any external requests. If you don't know how to do that, please [contact](https://daan.dev/contact/) me.
79
-
80
- = I have 'Remove Google Fonts' enabled, but the fonts from fonts.gstatic.com|fonts.googleapis.com are still loaded. What's going on? =
81
-
82
- The option in OMGF removes any fonts that are loaded in the conventional way. However, if it doesn't work for you you're theme is either using an unconventional method or WebFont Loader to add Google Fonts. [Upgrade to OMGF Pro](https://woosh.dev/wordpress-plugins/host-google-fonts-pro/) to automatically replace these fonts with a locally hosted version.
83
 
84
  = Does this plugin edit template files? =
85
 
86
- No, it does not. It creates a CSS Stylesheet which will be automatically added to your theme's header using a built-in WordPress queueing system.
87
 
88
  = The stylesheet isn't loaded? What's going on? =
89
 
90
- OMGF enqueues the stylesheet into WordPress' head. If the stylesheet isn't loaded, this probably means your theme isn't implementing the wp_head() function correctly in its header section.
91
 
92
  = Does this plugin support Multi Site? I'm getting CORS errors! =
93
 
94
  Yes, it does. When using subdomains, however, you might run into CORS related issues. To get around this, you should configure each site separately. Do the following:
95
 
96
  - Go to the site's own dashboard,
97
- - Change OMGF's cache directory (*Save webfonts to...*) to something unique, e.g. `/uploads/site1/omgf`,
98
- - Click 'Save Changes',
99
- - If you haven't already, find the fonts you want to use,
100
- - Click 'Download Fonts' and wait for the process to finish,
101
- - Click 'Generate stylesheet'.
102
 
103
- Repeat this for every site you want to use with OMGF. A new stylesheet, using the corresponding site's Home-URL and cache directory for each font, has been generated. Bypassing any Cross-Origin Resource Sharing (CORS) issues you might run into.
104
 
105
  = Is this plugin compatible with WPML? =
106
 
@@ -112,6 +112,23 @@ N/A
112
 
113
  == Changelog ==
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  = 3.8.2 =
116
  * Fixed notice: invalid operand type.
117
 
@@ -124,7 +141,7 @@ N/A
124
  * Improved re-enqueueing of stylesheets, if a stylesheet depends on the removed Google Font stylesheet.
125
  * Pressing Enter in the Search Bar triggers search now.
126
  * Developers can now easily add functionalities to OMGF's brand new Extensions tab, using several new filters and actions.
127
- * If OMGF is used along with other WoOSH! plugins (e.g. CAOS, OMGF Pro, etc.) the same class loader is used, significantly increasing performance.
128
  * Added dates to changelog :)
129
 
130
  = 3.7.0 | June 10th, 2020 =
@@ -246,7 +263,7 @@ N/A
246
  * WordPress' default admin fonts no longer show up as results.
247
 
248
  = 2.5.0 | January 30st, 2020 =
249
- Updated Welcome-panel with WoOSH!-services.
250
  Preload can now be used for certain fonts only (also combined with Web Font Loader).
251
 
252
  = 2.4.1 =
3
  Tags: google, fonts, gdpr, cache, speed, preload, font-display, webfonts, subsets, remove, minimize, external, requests
4
  Requires at least: 4.6
5
  Tested up to: 5.5
6
+ Stable tag: 4.0.0
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ OMGF automagically caches the Google Fonts used by your theme/plugins locally. No configuration (or brains) required!
12
 
13
  == Description ==
14
 
17
 
18
  Leverage Browser Cache, Minimize DNS requests and serve your Google Fonts in a 100% GDPR compliant way with OMGF!
19
 
20
+ OMGF is written with performance and user-friendliness in mind. It uses the Google Fonts Helper API to automatically cache the fonts your theme and plugins use to **minimize DNS requests** and speed up your WordPress website.
21
 
22
+ = How Does It Work? =
23
 
24
+ After installing the plugin, OMGF runs silently in the background and captures any requests made to fonts.googleapis.com or fonts.gstatic.com. When a webpage is first loaded, it reroutes these requests to its own Download API and copies the fonts over to your server. Then it generates a stylesheet for your fonts including EOT, TTF, WOFF and WOFF2 formats to guarantee maximum cross browser compatibility!
25
 
26
+ When the fonts are downloaded and the stylesheet is generated, it rewrites every URL pointing to fonts.googleapis.com or fonts.gstatic.com to the locally hosted variant.
27
 
28
+ Please keep in mind that, although I try to make the configuration of this plugin as easy as possible, the concept of locally hosting a file or optimizing Google Fonts for *Pagespeed Insights* or *GT Metrix* has proven to be confusing for some people. If you're not sure of what your doing, please consult a SEO expert or Webdeveloper to help you with the configuration of this plugin or [hire me to do it for you](https://ffwp.dev/wordpress/omgf-expert-configuration/).
29
+
30
+ = Features =
31
+ - Automatically replace registered/enqueued Google Fonts in wp_head() with local copies,
32
+ - Automatically remove registered/enqueued Google Fonts from wp_head(),
33
+ - Leverage the font-display (swap) option,
34
+ - Serve fonts from CDN,
35
+ - Use OMGF with *security through obscurity* plugins.
36
+
37
+ = Features in the PRO version =
38
+ Everything in the free version, plus:
39
+ - Automatically remove/replace all Google Fonts throughout the entire document/page,
40
+ - Combine all Google Fonts (made by your theme and/or plugins) requests into one file,
41
+ - Deduplicate Google Fonts requests,
42
+ - Reduce loading time and page size, by forcing the used subset(s) for all Google Fonts requests,
43
+ - Remove Resource Hints (preload, preconnect, dns-prefetch) pointing to fonts.googleapis.com or fonts.gstatic.com.
44
+
45
+ *Click [here](https://ffwp.dev/wordpress/omgf-pro/) for more information and to purchase OMGF Pro.*
46
 
47
  == Installation ==
48
 
54
 
55
  == Frequently Asked Questions ==
56
 
57
+ = Why do my fonts load slow the first time? =
58
+
59
+ That's because OMGF's download API is capturing the request and immediately downloading all the fonts. After the fonts are downloaded and the stylesheet is generated, the stylesheet will load just as fast as any other file request.
60
+
61
  = I don't know what I'm doing! Can you help? =
62
 
63
  Of course :) But first calm down and read this [comprehensive guide on how to configure OMGF](https://daan.dev/wordpress/host-google-fonts-locally/). If you have any questions afterwards, visit the [Support Forum](https://wordpress.org/support/plugin/host-webfonts-local).
64
 
65
  = I have another file I want to host locally. Could you make a plugin? =
66
 
67
+ Maintaining three plugins besides my daily 9-to-5 job is a handful, so no. If you're looking for a way to host analytics.js locally; please install [CAOS](https://wordpress.org/plugins/host-analyticsjs-local/). For anything else, please follow the steps in [this how-to](https://daan.dev/how-to/host-js-locally-crontab/).
68
 
69
  = How come my font isn't available in OMGF? =
70
 
74
 
75
  = Does this plugin remove resource hints, e.g. preconnect, preload or dns-prefetch? =
76
 
77
+ No, to automatically remove resource hints pointing to fonts.googleapis.com or fonts.gstatic.com, [upgrade to OMGF Pro](https://ffwp.dev/wordpress/omgf-pro/).
78
 
79
  = Can I serve the fonts from my CDN? =
80
 
81
+ Yes, you can. Enter the url of your CDN and empty OMGF's cache directory.
82
 
83
+ = I have Google Fonts Processing set to Replace/Remove but the fonts from fonts.gstatic.com|fonts.googleapis.com are still loaded. What's going on? =
84
 
85
+ The free version of OMGF removes any fonts that are loaded in the conventional way: wp_enqueue_scripts(). If it doesn't work for you, you're theme or plugins using other methods to load Google Fonts, e.g. in the footer, WebFont Loader, etc. [Upgrade to OMGF Pro](https://ffwp.dev/wordpress/omgf-pro/) to automatically replace these fonts with a locally hosted version.
 
 
 
 
 
 
 
 
86
 
87
  = Does this plugin edit template files? =
88
 
89
+ No, it does not. It creates a CSS Stylesheet which will be automatically added to your theme's header using WordPress built-in queueing system.
90
 
91
  = The stylesheet isn't loaded? What's going on? =
92
 
93
+ The free version of OMGF enqueues the stylesheet into WordPress' head using wp_enqueue_scripts(). If the stylesheet isn't loaded, this probably means your theme isn't implementing wp_head() correctly. [Upgrade to OMGF Pro](https://ffwp.dev/wordpress/omgf-pro/) to automatically add the stylesheet into WordPress' head.
94
 
95
  = Does this plugin support Multi Site? I'm getting CORS errors! =
96
 
97
  Yes, it does. When using subdomains, however, you might run into CORS related issues. To get around this, you should configure each site separately. Do the following:
98
 
99
  - Go to the site's own dashboard,
100
+ - Change OMGF's cache directory (*Save font files to...*) to something unique, e.g. `/uploads/site1/omgf`,
101
+ - Click 'Save Changes'.
 
 
 
102
 
103
+ Repeat this for every site you want to use with OMGF. A new stylesheet, using the corresponding site's Home-URL and cache directory for each font, will be generated. Bypassing any Cross-Origin Resource Sharing (CORS) issues you might run into.
104
 
105
  = Is this plugin compatible with WPML? =
106
 
112
 
113
  == Changelog ==
114
 
115
+ = 4.0.0 | September 30th, 2020 =
116
+ * OMGF now runs fully automatic to replace/remove Google Fonts from your pages using OMGF's new Download API. No initial configuration required!
117
+ * This means that if you use different fonts on different pages, all of them will be cached and served locally.
118
+ * HUGE performance increase in OMGF's automatic replacing/removing methods.
119
+ * Major overhaul of Settings Page:
120
+ * Removed Extensions Tab
121
+ * Some settings were moved to a new tab: Basic Settings.
122
+ * Improved Welcome and Documentation tab.
123
+ * Clarified option descriptions.
124
+ * Removed 'Generate Stylesheet' tab, which'll be released in a separate (free) add-on plugin soon.
125
+ * Removed 'Use Web Font Loader?' option, because it causes Cumulative Layout Shift and will not work with OMGF's new Auto Replace feature.
126
+ * Removed 'Remove Version Parameter' option, because it has become obsolete. The new detection method uses the initial script's version, if set.
127
+ * Font Preloading is temporarily removed and will be re-introduced (in a different form, along with new features) in a later release.
128
+
129
+ = 3.8.3 | September 15th, 2020 =
130
+ * Performance improvements for Class autoloader.
131
+
132
  = 3.8.2 =
133
  * Fixed notice: invalid operand type.
134
 
141
  * Improved re-enqueueing of stylesheets, if a stylesheet depends on the removed Google Font stylesheet.
142
  * Pressing Enter in the Search Bar triggers search now.
143
  * Developers can now easily add functionalities to OMGF's brand new Extensions tab, using several new filters and actions.
144
+ * If OMGF is used along with other Fast FW Press plugins (e.g. CAOS, OMGF Pro, etc.) the same class loader is used, significantly increasing performance.
145
  * Added dates to changelog :)
146
 
147
  = 3.7.0 | June 10th, 2020 =
263
  * WordPress' default admin fonts no longer show up as results.
264
 
265
  = 2.5.0 | January 30st, 2020 =
266
+ Updated Welcome-panel with Fast FW Press-services.
267
  Preload can now be used for certain fonts only (also combined with Web Font Loader).
268
 
269
  = 2.4.1 =
templates/admin/block-generate-stylesheet.phtml DELETED
@@ -1,160 +0,0 @@
1
- <?php
2
- /* * * * * * * * * * * * * * * * * * * * *
3
- *
4
- * ██████╗ ███╗ ███╗ ██████╗ ███████╗
5
- * ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
6
- * ██║ ██║██╔████╔██║██║ ███╗█████╗
7
- * ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
8
- * ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
9
- * ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
10
- *
11
- * @package : OMGF
12
- * @author : Daan van den Bergh
13
- * @copyright: (c) 2020 Daan van den Bergh
14
- * @url : https://daan.dev
15
- * * * * * * * * * * * * * * * * * * * */
16
-
17
- defined('ABSPATH') || exit;
18
-
19
- $db = new OMGF_DB();
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">
31
- <div class="omgf-search-box">
32
- <input type="text" id="omgf-search" class="form-input-tip ui-autocomplete-input" placeholder="<?php _e('Search... [e.g. Roboto, Open Sans, Poppins]', 'host-webfonts-local'); ?>" />
33
- <input type="button" id="omgf-search-subsets" class="button button-secondary button-hero" value="<?php _e('Search', 'host-webfonts-local'); ?>"/>
34
- <input type="button" id="omgf-auto-detect" class="button button-primary button-hero" value="<?= apply_filters('omgf_generate_stylesheet_auto_detect_title', __('Auto Detect', 'host-webfonts-local')); ?>" />
35
- </div>
36
- <table>
37
- <caption><?php _e('Available subsets', 'host-webfonts-local'); ?></caption>
38
- <tbody id="omgf-subsets">
39
- <?php
40
- $subsetFonts = $db->get_subsets();
41
- ?>
42
- <?php if ($subsetFonts): ?>
43
- <?php foreach ($subsetFonts as $subsetFont): ?>
44
- <tr valign="top" id="<?= $subsetFont['subset_font']; ?>">
45
- <td>
46
- <label>
47
- <input readonly type="text" class="omgf-subset-font-family" data-font-family="<?= $subsetFont['subset_font']; ?>" value="<?= $subsetFont['subset_family']; ?>" />
48
- </label>
49
- </td>
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>
58
- <?php endforeach; ?>
59
- </tr>
60
- <?php endforeach; ?>
61
- <tr align="center">
62
- <td class="omgf-subsets-search" align="right"><span class="omgf-apply help" style="display: none;"><strong><?= __('Search Font Styles', 'host-webfonts-local'); ?></strong></span></td>
63
- <td><a class="button-primary omgf-apply button font-styles-search" href="#" style="display: none;"><span class="dashicons-before dashicons-search">&nbsp;</span></a></td>
64
- </tr>
65
- <?php else: ?>
66
- <tr colspan="3">
67
- <td>
68
- <em><?php _e('No subsets found. Use <strong>Search</strong> or <strong>Auto Detect</strong> start.', 'host-webfonts-local'); ?></em>
69
- </td>
70
- </tr>
71
- <?php endif; ?>
72
- </tbody>
73
- </table>
74
- <table id="omgf-font-styles-list">
75
- <caption><?php _e('Available font styles', 'host-webfonts-local'); ?></caption>
76
- <?php
77
- $savedFonts = $db->get_total_fonts();
78
- ?>
79
- <?php if ($savedFonts && $subsetFonts): ?>
80
- <thead align="center">
81
- <th></th>
82
- <th>
83
- <?= __('Font Family', 'host-webfonts-local'); ?>
84
- </th>
85
- <th>
86
- <?= __('Font Style', 'host-webfonts-local'); ?>
87
- </th>
88
- <th>
89
- <?= __('Font Weight', 'host-webfonts-local'); ?>
90
- </th>
91
- <th>
92
- <?= __('Preload? *', 'host-webfonts-local'); ?>
93
- </th>
94
- <th></th>
95
- </thead>
96
- <tbody id="omgf-font-styles">
97
- <?php foreach ($savedFonts as $font):
98
- $fontId = $font['font_id'];
99
- ?>
100
- <tr class="omgf-font-style" data-font-id="<?= $fontId; ?>" id="row-<?= $fontId; ?>">
101
- <td align="center" style="width: 20px;">
102
- <span class="omgf-font-downloaded dashicons-before <?= isset($font['downloaded']) && $font['downloaded'] == 1 ? 'dashicons-yes' : ''; ?>"></span>
103
- </td>
104
- <td style="width: 195px;">
105
- <input readonly type="text" value="<?= $font['font_family']; ?>" />
106
- </td>
107
- <td style="width: 150px;">
108
- <input style="width: 150px;" readonly type="text" value="<?= $font['font_style']; ?>" />
109
- </td>
110
- <td style="width: 100px;">
111
- <input style="width: 100px;" readonly type="text" value="<?= $font['font_weight']; ?>" />
112
- </td>
113
- <td align="center" style="width: 45px;">
114
- <input type="checkbox" class="omgf-font-preload" autocomplete="off" value="<?= $fontId; ?>" <?= $font['preload'] == 1 ? 'checked' : ''; ?> />
115
- </td>
116
- <td style="width: 45px;">
117
- <input type="hidden" value="<?= $fontId; ?>" />
118
- <input type="hidden" value="<?= $font['local']; ?>" />
119
- <input type="hidden" value="<?= $font['url_ttf']; ?>" />
120
- <input type="hidden" value="<?= $font['url_woff']; ?>" />
121
- <input type="hidden" value="<?= $font['url_woff2']; ?>" />
122
- <input type="hidden" value="<?= $font['url_eot']; ?>" />
123
- <span data-row="row-<?= $fontId; ?>" class="omgf-font-remove notice-dismiss">&nbsp;</span>
124
- </td>
125
- </tr>
126
- <?php endforeach; ?>
127
- <!-- The navbar at the bottom of the table. -->
128
- <tr id="font-styles-nav" class="sticky bottom">
129
- <td colspan="4" align="right">
130
- <span class="omgf-apply help font-styles" style="display: none;"><strong><?= __('Apply Changes', 'host-webfonts-local'); ?></strong></span>
131
- </td>
132
- <td colspan="2" style="width: 100px">
133
- <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>
134
- </td>
135
- </tr>
136
- <tr>
137
- <td colspan="5">
138
- <span class="description">* <?= __('Only the <strong>woff2</strong> format is preloaded, since this format is widely supported by Modern Browsers which support preload.', 'host-webfonts-local'); ?></span>
139
- </td>
140
- </tr>
141
- </tbody>
142
- <?php else: ?>
143
- <tr>
144
- <td>
145
- <em><?php _e('No fonts found. Choose <strong>subsets</strong> to start searching for fonts.', 'host-webfonts-local'); ?></em>
146
- </td>
147
- </tr>
148
- <?php endif; ?>
149
- </table>
150
- </div>
151
-
152
- <div id="omgf-control-panel">
153
- <input type="button" id="omgf-download" class="button-primary" value="<?php _e('Download Fonts', 'host-webfonts-local'); ?>" />
154
- <input type="button" id="omgf-generate" class="button-secondary" value="<?php _e('Generate Stylesheet', 'host-webfonts-local'); ?>" />
155
- <a id="omgf-empty" class="button-cancel"><?php _e('Empty Cache Directory', 'host-webfonts-local'); ?></a>
156
- </div>
157
- </div>
158
- <div class="omgf-loading" style="display: none;">
159
- <span class="spinner is-active"> </span>
160
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
templates/admin/block-welcome.phtml CHANGED
@@ -22,27 +22,35 @@ $tweetUrl = 'https://twitter.com/intent/tweet?text=I+just+optimized+my
22
  ?>
23
  <div class="welcome-panel-content">
24
  <div class="welcome-panel-column-container">
 
25
  <div class="welcome-panel-column" style="width: 100%; margin-right: 15px;">
26
- <h2><?php _e('Quickstart', $plugin_text_domain); ?></h2>
27
  <ul>
28
- <li class="welcome-icon dashicons-before dashicons-admin-settings">
29
- <?= sprintf(__('Click %sAuto-detect%s and wait for the on-screen instructions', $plugin_text_domain), '<a class="help auto-detect" href="#">', '</a>'); ?>
30
  </li>
31
- <li class="welcome-icon dashicons-before dashicons-update">
32
- <?= sprintf(__('Click %sDownload Fonts%s and wait for the download to complete', $plugin_text_domain), '<a class="help download-fonts" href="#">', '</a>'); ?>
33
  </li>
34
- <li class="welcome-icon dashicons-before dashicons-art">
35
- <?= sprintf(__('Click %sGenerate Stylesheet%s and wait for the process to complete', $plugin_text_domain), '<a class="help generate-stylesheet" href="#">', '</a>'); ?>
 
 
 
 
 
 
36
  </li>
37
- <li class="welcome-icon dashicons-before dashicons-editor-removeformatting"><?= sprintf(__('Check <em>Auto Remove</em> in <a href="%s">Advanced Settings</a> and save your changes', $plugin_text_domain), admin_url('options-general.php?page=optimize-webfonts&tab=omgf-advanced-settings')); ?></li>
38
- <li class="welcome-icon dashicons-before dashicons-smiley"><?php _e('Done!', $plugin_text_domain); ?></li>
39
  </ul>
40
  <p>
41
- <?= sprintf(__('%sClick here%s for a more comprehensive guide.', $plugin_text_domain), '<a target="_blank" href="' . OMGF_SITE_URL . '/wordpress/host-google-fonts-locally/' . $utmTags . '">', '</a>'); ?>
 
42
  </p>
43
  <hr/>
44
  </div>
 
45
  <div class="welcome-panel-column welcome-panel-last" style="width: 100%;">
 
46
  <h3>
47
  <?php _e('Support OMGF by Spreading the Word!', $plugin_text_domain); ?>
48
  </h3>
@@ -56,13 +64,41 @@ $tweetUrl = 'https://twitter.com/intent/tweet?text=I+just+optimized+my
56
  <a target="_blank" class="button button-secondary button-hero" href="https://wordpress.org/support/plugin/host-webfonts-local/reviews/?rate=5#new-post"><span class="dashicons-before dashicons-star-filled"> <?php _e('Review', $plugin_text_domain); ?></span></a>
57
  <a target="_blank" class="button button-secondary button-hero" href="<?= $tweetUrl; ?>"><span class="dashicons-before dashicons-twitter"> <?php _e('Tweet', $plugin_text_domain); ?></span></a>
58
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
59
  <hr/>
60
  <h3>
61
  <?php _e('Need Help?', $plugin_text_domain); ?>
62
  </h3>
 
 
 
 
63
  <p>
64
  <?= sprintf(__('Visit the %sFAQ%s and %sSupport Forum%s to see if your question has already been answered. If not, ask a question on the Support Forum.', $plugin_text_domain), '<a href="https://wordpress.org/plugins/host-webfonts-local/#description" target="_blank">', '</a>', '<a href="https://wordpress.org/support/plugin/host-webfonts-local">', '</a>'); ?>
65
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
66
  </div>
67
  </div>
68
  </div>
22
  ?>
23
  <div class="welcome-panel-content">
24
  <div class="welcome-panel-column-container">
25
+ <?php if (apply_filters('apply_omgf_pro_promo', true)): ?>
26
  <div class="welcome-panel-column" style="width: 100%; margin-right: 15px;">
27
+ <h2><?php _e('Why upgrade to OMGF Pro?', $plugin_text_domain); ?></h2>
28
  <ul>
29
+ <li class="welcome-icon dashicons-before dashicons-yes">
30
+ <?= __('Automatically Replace/Remove Google Fonts throughout the entire document.', $plugin_text_domain); ?>
31
  </li>
32
+ <li class="welcome-icon dashicons-before dashicons-yes">
33
+ <?= __('Combine and de-duplicate Google Fonts into one request.', $plugin_text_domain); ?>
34
  </li>
35
+ <li class="welcome-icon dashicons-before dashicons-yes">
36
+ <?= __('Performance Fine Tuning', $plugin_text_domain); ?>
37
+ </li>
38
+ <li class="welcome-icon dashicons-before dashicons-yes">
39
+ <?= __('Automatically remove Resource Hints pointing to Google\'s Servers.', $plugin_text_domain); ?>
40
+ </li>
41
+ <li class="welcome-icon dashicons-before dashicons-yes">
42
+ <?= __('Reduce Page Size and Load Time using Subset Forcing.', $plugin_text_domain); ?>
43
  </li>
 
 
44
  </ul>
45
  <p>
46
+ <a class="button button-hero button-primary" href="https://ffwp.dev/wordpress/omgf-pro"><span class="dashicons-before dashicons-cart"> <?= __('Buy now'); ?></span></a>
47
+ <span><?= __('Starting at € 29,-', $plugin_text_domain); ?></span>
48
  </p>
49
  <hr/>
50
  </div>
51
+ <?php endif; ?>
52
  <div class="welcome-panel-column welcome-panel-last" style="width: 100%;">
53
+ <?php if (apply_filters('apply_omgf_pro_promo', true)): ?>
54
  <h3>
55
  <?php _e('Support OMGF by Spreading the Word!', $plugin_text_domain); ?>
56
  </h3>
64
  <a target="_blank" class="button button-secondary button-hero" href="https://wordpress.org/support/plugin/host-webfonts-local/reviews/?rate=5#new-post"><span class="dashicons-before dashicons-star-filled"> <?php _e('Review', $plugin_text_domain); ?></span></a>
65
  <a target="_blank" class="button button-secondary button-hero" href="<?= $tweetUrl; ?>"><span class="dashicons-before dashicons-twitter"> <?php _e('Tweet', $plugin_text_domain); ?></span></a>
66
  </p>
67
+ <?php else:; ?>
68
+ <h2>
69
+ <?= __('Do you <span class="dashicons dashicons-heart ffwp-heart"></span> OMGF Pro?', $plugin_text_domain) ;?>
70
+ </h2>
71
+ <p>
72
+ <?= __('Click the button below and receive a unique discount code for 10% off your next purchase!'); ?>
73
+ </p>
74
+ <p>
75
+ <a target="_blank" class="button button-primary button-hero" href="<?= OMGF_Admin_Settings_Builder::FFWP_WORDPRESS_PLUGINS_OMGF_PRO . '#edd-reviews-title'; ?>"><span class="dashicons-before dashicons-star-filled"> <?php _e('Review', $plugin_text_domain); ?></span></a>
76
+ <span><?= __('(login required)', $plugin_text_domain); ?></span>
77
+ </p>
78
+ <?php endif; ?>
79
  <hr/>
80
  <h3>
81
  <?php _e('Need Help?', $plugin_text_domain); ?>
82
  </h3>
83
+ <?php if (apply_filters('apply_omgf_pro_promo', true)): ?>
84
+ <p>
85
+ <?= sprintf(__('%sClick here%s for a comprehensive guide.', $plugin_text_domain), '<a target="_blank" href="' . OMGF_SITE_URL . '/wordpress/host-google-fonts-locally/' . $utmTags . '">', '</a>'); ?>
86
+ </p>
87
  <p>
88
  <?= sprintf(__('Visit the %sFAQ%s and %sSupport Forum%s to see if your question has already been answered. If not, ask a question on the Support Forum.', $plugin_text_domain), '<a href="https://wordpress.org/plugins/host-webfonts-local/#description" target="_blank">', '</a>', '<a href="https://wordpress.org/support/plugin/host-webfonts-local">', '</a>'); ?>
89
  </p>
90
+ <?php else: ?>
91
+ <ul>
92
+ <li><a target="_blank" href="https://ffwp.dev/docs/omgf-pro/quick-start/"><?= __('Quick Start Guide', $plugin_text_domain); ?></a></li>
93
+ <li><a target="_blank" href="https://ffwp.dev/docs/omgf-pro/faq/"><?= __('FAQ', $plugin_text_domain); ?></a></li>
94
+ <li><a target="_blank" href="https://ffwp.dev/contact/"><?= __('Contact', $plugin_text_domain); ?></a></li>
95
+ </ul>
96
+ <?php endif; ?>
97
+ <hr />
98
+ <h4 class="signature"><?= sprintf(__('Coded with %s in The Netherlands.', $plugin_text_domain), '<span class="dashicons dashicons-heart ffwp-heart"></span>'); ?></h4>
99
+ <p class="signature">
100
+ <a target="_blank" title="<?= __('Visit FFWP.dev', $plugin_text_domain); ?>" href="https://ffwp.dev/wordpress-plugins/"><img class="signature-image" alt="<?= __('Visit FFWP.dev', $plugin_text_domain); ?>" src="https://ffwp.dev/wp-content/uploads/2020/09/logo-color-full@05x.png" /></a>
101
+ </p>
102
  </div>
103
  </div>
104
  </div>
templates/frontend-web-font-loader.phtml DELETED
@@ -1,76 +0,0 @@
1
- <?php
2
- /* * * * * * * * * * * * * * * * * * * * *
3
- *
4
- * ██████╗ ███╗ ███╗ ██████╗ ███████╗
5
- * ██╔═══██╗████╗ ████║██╔════╝ ██╔════╝
6
- * ██║ ██║██╔████╔██║██║ ███╗█████╗
7
- * ██║ ██║██║╚██╔╝██║██║ ██║██╔══╝
8
- * ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║
9
- * ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
10
- *
11
- * @package : OMGF
12
- * @author : Daan van den Bergh
13
- * @copyright: (c) 2020 Daan van den Bergh
14
- * @url : https://daan.dev
15
- * * * * * * * * * * * * * * * * * * * */
16
-
17
- defined('ABSPATH') || exit;
18
-
19
- $db = new OMGF_DB();
20
- $fonts = $db->get_downloaded_fonts(true);
21
- $families = array_unique(
22
- array_map(
23
- function ($i) {
24
- return $i['font_family'];
25
- },
26
- $fonts
27
- )
28
- );
29
- $omgfStaticVersion = '?ver=' . OMGF_STATIC_VERSION;
30
- $omgfSrcUrl = OMGF_FONTS_URL . '/' . OMGF_FILENAME . (OMGF_REMOVE_VERSION ? null : $omgfStaticVersion);
31
- $wflVersion = '?ver=' . OMGF_WEB_FONT_LOADER_VERSION;
32
- $wflSrcUrl = plugin_dir_url(OMGF_PLUGIN_FILE) . 'assets/js/libraries/webfont.js' . (OMGF_REMOVE_VERSION ? null : $wflVersion);
33
-
34
- if ($fonts && $families): ?>
35
- <script type="text/javascript">
36
- /**
37
- * Using Typekit's Web Font Loader to load OMGF's fonts asynchronously.
38
- *
39
- * @type {{custom: {urls: string[], families: string[]}}}
40
- */
41
- WebFontConfig = {
42
- custom: {
43
- families: [
44
- <?php foreach ($families as $family): ?>
45
- <?php
46
- $fvds = [];
47
- foreach ($fonts as $font) {
48
- if ($font['font_family'] != $family) {
49
- continue;
50
- }
51
- $fvds[] = mb_substr($font['font_style'], 0, 1) . mb_substr($font['font_weight'], 0, 1);
52
- }
53
- ?>
54
- '<?= $family; ?>:<?= implode(',', $fvds); ?>',
55
- <?php endforeach; ?>
56
- ],
57
- urls: [
58
- '<?= $omgfSrcUrl; ?>'
59
- ]
60
- }
61
- };
62
-
63
- (function (d) {
64
- var wf = d.createElement(
65
- 'script'),
66
- s = d.scripts[0];
67
- wf.src = '<?= $wflSrcUrl; ?>';
68
- wf.async = true;
69
- wf.text = 'text/javascript';
70
- s.parentNode.insertBefore(
71
- wf,
72
- s
73
- );
74
- })(document);
75
- </script>
76
- <?php endif; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
woosh-autoload.php DELETED
@@ -1,74 +0,0 @@
1
- <?php
2
- /* * * * * * * * * * * * * * * * * * * * * *
3
- * _ __ ____ _____ __ ____
4
- * | | / /___ / __ \/ ___// / / / /
5
- * | | /| / / __ \/ / / /\__ \/ /_/ / /
6
- * | |/ |/ / /_/ / /_/ /___/ / __ /_/
7
- * |__/|__/\____/\____//____/_/ /_(_)
8
- *
9
- * @author : Daan van den Bergh
10
- * @url : https://woosh.dev/wordpress-plugins/
11
- * @copyright: (c) 2020 Daan van den Bergh
12
- * @license : GPL2v2 or later
13
- * * * * * * * * * * * * * * * * * * * * * */
14
-
15
- class Woosh_Autoloader
16
- {
17
- /** @var string $class */
18
- private $class;
19
-
20
- /** @var string $file */
21
- private $file;
22
-
23
- /**
24
- * Woosh_Autoloader constructor.
25
- *
26
- * @param $class
27
- */
28
- public function __construct(
29
- $class
30
- ) {
31
- $this->class = $class;
32
-
33
- $this->load();
34
- }
35
-
36
- /**
37
- * Build filepath for requested class.
38
- */
39
- public function load()
40
- {
41
- $path = explode('_', $this->class);
42
- $this->file = '';
43
-
44
- if (count($path) == 1) {
45
- if (ctype_upper($path[0])) {
46
- $this->file = 'class-' . strtolower(str_replace('_', '-', $this->class)) . '.php';
47
- } else {
48
- $parts = preg_split('/(?=[A-Z])/', lcfirst($path[0]));
49
- $this->file = 'class-' . strtolower(implode('-', $parts)) . '.php';
50
- }
51
- } else {
52
- array_shift($path);
53
- end($path);
54
- $i = 0;
55
-
56
- while ($i < key($path)) {
57
- $this->file .= strtolower($path[$i]) . '/';
58
- $i++;
59
- }
60
-
61
- // If entire part of path is written uppercase, we don't want to split.
62
- if (ctype_upper($path[$i])) {
63
- $pieces[] = $path[$i];
64
- // Words like OmgfPro or SuperStealth should be split up.
65
- } else {
66
- $pieces = preg_split('/(?=[A-Z])/', lcfirst($path[$i]));
67
- }
68
-
69
- $this->file .= 'class-' . strtolower(implode('-', $pieces)) . '.php';
70
- }
71
-
72
- return $this->file;
73
- }
74
- }