-
Notifications
You must be signed in to change notification settings - Fork 1
/
modern-font-stacks-for-wp.php
231 lines (221 loc) · 6.42 KB
/
modern-font-stacks-for-wp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
/**
* Plugin Name: Modern Font Stacks for WP
* Plugin URI: https://csaba.blog/modern-font-stacks-for-wordpress
* Description: This lightweight plugin integrates the Modern Font Stacks project into the WordPress Font Library. These are system font stacks organized by typeface classification for every modern OS. The fastest fonts available. No downloading, no layout shifts, no flashes — just instant renders.
* Requires at least: 6.5
* Requires PHP: 7.0
* Version: 2.0
* Author: LittleBigThings
* Author URI: https://littlebigthings.be
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: modern-font-stacks-for-wp
*/
namespace ModernFontStacksforWP;
class FontCollection {
/**
* Generate the stacks based on Modern Font Stacks from https://modernfontstacks.com or https://github.com/system-fonts/modern-font-stacks.
*
* @license CC0 1.0 Universal https://creativecommons.org/share-your-work/public-domain/cc0/
*
* @access public
* @since 2.0
*/
public $stacks = [
array(
'font_family_settings' => (
array (
'fontFamily' => 'Charter, "Bitstream Charter", "Sitka Text", Cambria, serif',
'name' => 'Transitional',
'slug' => 'mfswp-transitional'
)
),
'categories' => [ 'serif' ]
),
array(
'font_family_settings' => (
array (
'fontFamily' => '"Iowan Old Style", "Palatino Linotype", "URW Palladio L", P052, serif',
'name' => 'Old Style',
'slug' => 'mfswp-old-style'
)
),
'categories' => [ 'serif' ]
),
array(
'font_family_settings' => (
array(
'fontFamily' => 'Seravek, "Gill Sans Nova", Ubuntu, Calibri, "DejaVu Sans", source-sans-pro, sans-serif',
'name' => 'Humanist',
'slug' => 'mfswp-humanist'
)
),
'categories' => [ 'sans-serif' ]
),
array(
'font_family_settings' => (
array(
'fontFamily' => 'Avenir, Montserrat, Corbel, "URW Gothic", source-sans-pro, sans-serif',
'name' => 'Geometric Humanist',
'slug' => 'mfswp-geometric-humanist'
)
),
'categories' => [ 'sans-serif' ]
),
array(
'font_family_settings' => (
array(
'fontFamily' => 'Optima, Candara, "Noto Sans", source-sans-pro, sans-serif',
'name' => 'Classical Humanist',
'slug' => 'mfswp-classical-humanist'
)
),
'categories' => [ 'sans-serif' ]
),
array(
'font_family_settings' => (
array(
'fontFamily' => 'Inter, Roboto, "Helvetica Neue", "Arial Nova", "Nimbus Sans", Arial, sans-serif',
'name' => 'Neo-Grotesque',
'slug' => 'mfswp-neo-grotesque'
)
),
'categories' => [ 'sans-serif' ]
),
array(
'font_family_settings' => (
array(
'fontFamily' => '"Nimbus Mono PS", "Courier New", monospace',
'name' => 'Monospace Slab Serif',
'slug' => 'mfswp-monospace-slab-serif'
)
),
'categories' => [ 'monospace', 'slab-serif' ]
),
array(
'font_family_settings' => (
array(
'fontFamily' => 'ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, "DejaVu Sans Mono", monospace',
'name' => 'Monospace Code',
'slug' => 'mfswp-monospace-code'
)
),
'categories' => [ 'monospace' ]
),
array(
'font_family_settings' => (
array(
'fontFamily' => 'Bahnschrift, "DIN Alternate", "Franklin Gothic Medium", "Nimbus Sans Narrow", sans-serif-condensed, sans-serif',
'name' => 'Industrial',
'slug' => 'mfswp-industrial'
)
),
'categories' => [ 'sans-serif' ]
),
array(
'font_family_settings' => (
array(
'fontFamily' => 'ui-rounded, "Hiragino Maru Gothic ProN", Quicksand, Comfortaa, Manjari, "Arial Rounded MT", "Arial Rounded MT Bold", Calibri, source-sans-pro, sans-serif',
'name' => 'Rounded Sans',
'slug' => 'mfswp-rounded-sans'
)
),
'categories' => [ 'sans-serif' ]
),
array(
'font_family_settings' => (
array(
'fontFamily' => 'Rockwell, "Rockwell Nova", "Roboto Slab", "DejaVu Serif", "Sitka Small", serif',
'name' => 'Slab Serif',
'slug' => 'mfswp-slab-serif'
)
),
'categories' => [ 'slab-serif' ]
),
array(
'font_family_settings' => (
array(
'fontFamily' => 'Superclarendon, "Bookman Old Style", "URW Bookman", "URW Bookman L", "Georgia Pro", Georgia, serif',
'name' => 'Antique',
'slug' => 'mfswp-antique'
)
),
'categories' => [ 'serif' ]
),
array(
'font_family_settings' => (
array(
'fontFamily' => 'Didot, "Bodoni MT", "Noto Serif Display", "URW Palladio L", P052, Sylfaen, serif',
'name' => 'Didone',
'slug' => 'mfswp-didone'
)
),
'categories' => [ 'serif' ]
),
array(
'font_family_settings' => (
array(
'fontFamily' => '"Segoe Print", "Bradley Hand", Chilanka, TSCu_Comic, casual, cursive',
'name' => 'Handwritten',
'slug' => 'mfswp-handwritten'
)
),
'categories' => [ 'cursive' ]
)
];
/**
* Initiate the class by adding the font collection to the library.
*
* @access public
* @since 2.0
*/
public function __construct() {
wp_register_font_collection( 'modern-font-stacks', $this->config() );
}
/**
* Set up the font categories.
*
* @access public
* @since 2.0
*/
public function categories() {
return [
array(
'name' => _x( 'Serif', 'Font category name', 'modern-font-stacks-for-wp' ),
'slug' => 'serif',
),
array(
'name' => _x( 'Sans Serif', 'Font category name', 'modern-font-stacks-for-wp' ),
'slug' => 'sans-serif',
),
array(
'name' => _x( 'Slab Serif', 'Font category name', 'modern-font-stacks-for-wp' ),
'slug' => 'slab-serif',
),
array(
'name' => _x( 'Monospace', 'Font category name', 'modern-font-stacks-for-wp' ),
'slug' => 'monospace',
),
array(
'name' => _x( 'Handwriting', 'Font category name', 'modern-font-stacks-for-wp' ),
'slug' => 'cursive',
)
];
}
/**
* Configurate loading the stacks.
*
* @access public
* @since 2.0
*/
public function config() {
return array (
'name' => _x( 'Modern Stacks', 'Font collection name', 'modern-font-stacks-for-wp' ),
'description' => _x( 'These system font stacks are organized by typeface classification for every modern OS. The fastest fonts available. No downloading, no layout shifts, no flashes — just instant renders.', 'Font collection description', 'modern-font-stacks-for-wp' ),
'font_families' => $this->stacks,
'categories' => $this->categories(),
);
}
}
new \ModernFontStacksforWP\FontCollection();