PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.1.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.1.0
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / customizer / packages / modules / webfonts / src / Webfonts / Fonts.php
kirki / customizer / packages / modules / webfonts / src / Webfonts Last commit date
Async.php 2 months ago Downloader.php 5 months ago Embed.php 2 months ago Fonts.php 5 months ago Google.php 2 months ago
Fonts.php
220 lines
1 <?php
2 /**
3 * A simple object containing properties for fonts.
4 *
5 * @package kirki-framework/module-webfonts
6 * @author Themeum
7 * @copyright Copyright (c) 2023, Themeum
8 * @license https://opensource.org/licenses/MIT
9 * @since 1.0.0
10 */
11
12 namespace Kirki\Module\Webfonts;
13
14 use Kirki\GoogleFonts;
15
16 /**
17 * The Fonts object.
18 */
19 final class Fonts {
20
21 /**
22 * The mode we'll be using to add google fonts.
23 * This is a todo item, not yet functional.
24 *
25 * @static
26 * @todo
27 * @access public
28 * @var string
29 */
30 public static $mode = 'link';
31
32 /**
33 * Holds a single instance of this object.
34 *
35 * @static
36 * @access private
37 * @var null|object
38 */
39 private static $instance = null;
40
41 /**
42 * An array of our google fonts.
43 *
44 * @static
45 * @access public
46 * @var array
47 */
48 public static $google_fonts = null;
49
50 /**
51 * The class constructor.
52 */
53 private function __construct() {}
54
55 /**
56 * Get the one, true instance of this class.
57 * Prevents performance issues since this is only loaded once.
58 *
59 * @return object Fonts
60 */
61 public static function get_instance() {
62 if ( null === self::$instance ) {
63 self::$instance = new self();
64 }
65 return self::$instance;
66 }
67
68 /**
69 * Compile font options from different sources.
70 *
71 * @return array All available fonts.
72 */
73 public static function get_all_fonts() {
74 $standard_fonts = self::get_standard_fonts();
75 $google_fonts = self::get_google_fonts();
76 return apply_filters( 'kirki_fonts_all', array_merge( $standard_fonts, $google_fonts ) );
77 }
78
79 /**
80 * Return an array of standard websafe fonts.
81 *
82 * @return array Standard websafe fonts.
83 */
84 public static function get_standard_fonts() {
85 $standard_fonts = [
86 'serif' => [
87 'label' => 'Serif',
88 'stack' => 'Georgia,Times,"Times New Roman",serif',
89 ],
90 'sans-serif' => [
91 'label' => 'Sans Serif',
92 'stack' => '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif',
93 ],
94 'monospace' => [
95 'label' => 'Monospace',
96 'stack' => 'Monaco,"Lucida Sans Typewriter","Lucida Typewriter","Courier New",Courier,monospace',
97 ],
98 ];
99
100 return apply_filters( 'kirki_fonts_standard_fonts', $standard_fonts );
101 }
102
103 /**
104 * Return an array of all available Google Fonts.
105 *
106 * @return array All Google Fonts.
107 */
108 public static function get_google_fonts() {
109 if ( ! self::$google_fonts ) {
110 $googlefonts = new GoogleFonts();
111 self::$google_fonts = $googlefonts->get_google_fonts();
112 }
113 return self::$google_fonts;
114 }
115
116 /**
117 * Returns an array of all available subsets.
118 *
119 * @static
120 * @access public
121 * @return array
122 */
123 public static function get_google_font_subsets() {
124 return [
125 'cyrillic' => 'Cyrillic',
126 'cyrillic-ext' => 'Cyrillic Extended',
127 'devanagari' => 'Devanagari',
128 'greek' => 'Greek',
129 'greek-ext' => 'Greek Extended',
130 'khmer' => 'Khmer',
131 'latin' => 'Latin',
132 'latin-ext' => 'Latin Extended',
133 'vietnamese' => 'Vietnamese',
134 'hebrew' => 'Hebrew',
135 'arabic' => 'Arabic',
136 'bengali' => 'Bengali',
137 'gujarati' => 'Gujarati',
138 'tamil' => 'Tamil',
139 'telugu' => 'Telugu',
140 'thai' => 'Thai',
141 ];
142 }
143
144 /**
145 * Dummy function to avoid issues with backwards-compatibility.
146 * This is not functional, but it will prevent PHP Fatal errors.
147 *
148 * @static
149 * @access public
150 */
151 public static function get_google_font_uri() {}
152
153 /**
154 * Returns an array of all available variants.
155 *
156 * @static
157 * @access public
158 * @return array
159 */
160 public static function get_all_variants() {
161 return [
162 '100' => esc_html__( 'Ultra-Light 100', 'kirki' ),
163 '100light' => esc_html__( 'Ultra-Light 100', 'kirki' ),
164 '100italic' => esc_html__( 'Ultra-Light 100 Italic', 'kirki' ),
165 '200' => esc_html__( 'Light 200', 'kirki' ),
166 '200italic' => esc_html__( 'Light 200 Italic', 'kirki' ),
167 '300' => esc_html__( 'Book 300', 'kirki' ),
168 '300italic' => esc_html__( 'Book 300 Italic', 'kirki' ),
169 '400' => esc_html__( 'Normal 400', 'kirki' ),
170 'regular' => esc_html__( 'Normal 400', 'kirki' ),
171 'italic' => esc_html__( 'Normal 400 Italic', 'kirki' ),
172 '500' => esc_html__( 'Medium 500', 'kirki' ),
173 '500italic' => esc_html__( 'Medium 500 Italic', 'kirki' ),
174 '600' => esc_html__( 'Semi-Bold 600', 'kirki' ),
175 '600bold' => esc_html__( 'Semi-Bold 600', 'kirki' ),
176 '600italic' => esc_html__( 'Semi-Bold 600 Italic', 'kirki' ),
177 '700' => esc_html__( 'Bold 700', 'kirki' ),
178 '700italic' => esc_html__( 'Bold 700 Italic', 'kirki' ),
179 '800' => esc_html__( 'Extra-Bold 800', 'kirki' ),
180 '800bold' => esc_html__( 'Extra-Bold 800', 'kirki' ),
181 '800italic' => esc_html__( 'Extra-Bold 800 Italic', 'kirki' ),
182 '900' => esc_html__( 'Ultra-Bold 900', 'kirki' ),
183 '900bold' => esc_html__( 'Ultra-Bold 900', 'kirki' ),
184 '900italic' => esc_html__( 'Ultra-Bold 900 Italic', 'kirki' ),
185 ];
186 }
187
188 /**
189 * Determine if a font-name is a valid google font or not.
190 *
191 * @static
192 * @access public
193 * @param string $fontname The name of the font we want to check.
194 * @return bool
195 */
196 public static function is_google_font( $fontname ) {
197 if ( is_string( $fontname ) ) {
198 $fonts = self::get_google_fonts();
199 return isset( $fonts[ $fontname ] );
200 }
201 return false;
202 }
203
204 /**
205 * Gets available options for a font.
206 *
207 * @static
208 * @access public
209 * @return array
210 */
211 public static function get_font_choices() {
212
213 $fonts = self::get_all_fonts();
214 $keys = array_keys( $fonts );
215
216
217 return array_combine( $keys, $keys );
218 }
219 }
220