-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcustom-fonts.php
133 lines (95 loc) · 2.66 KB
/
custom-fonts.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
<?php
/**
* @author: VLThemes
* @version: 1.0
*/
if ( ! class_exists( 'VLThemesAddCustomFonts' ) ) {
class VLThemesAddCustomFonts {
/**
* The single class instance.
* @var $_instance
*/
private static $_instance = null;
/**
* Main Instance
* Ensures only one instance of this class exists in memory at any one time.
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
self::$_instance->init_hooks();
}
return self::$_instance;
}
public function __construct() {
// We do nothing here!
}
/**
* Init hooks
*/
public function init_hooks() {
add_action( 'init', [ $this, 'prepare_custom_fonts' ] );
add_filter( 'vlthemes_fonts_list', [ $this, 'custom_fonts' ], 20 );
add_filter( 'vlthemes_fonts_list', [ $this, 'typekit_fonts' ], 20 );
}
/**
* Prepare Custom fonts
*/
public function prepare_custom_fonts() {
if ( class_exists( 'Bsf_Custom_Fonts_Render' ) ) {
$fonts = Bsf_Custom_Fonts_Render::get_instance()->get_existing_font_posts();
$custom_fonts = array();
if ( ! empty( $fonts ) ) {
foreach ( $fonts as $key => $post_id ) {
$font_family_name = get_the_title( $post_id );
$custom_fonts[ $font_family_name ] = $font_family_name;
}
}
update_option( 'vlthemes-custom-fonts', $custom_fonts );
}
return;
}
/**
* Custom fonts
*/
public function custom_fonts( $fonts ) {
$custom_fonts = get_option( 'vlthemes-custom-fonts' );
if ( ! empty( $custom_fonts ) ) {
$fonts[ 'families' ][ 'custom_fonts' ] = array(
'text' => esc_html__( 'Custom Fonts', 'vlthemes' ),
'children' => []
);
foreach( $custom_fonts as $font => $key ) {
$fonts[ 'families' ][ 'custom_fonts' ][ 'children' ][] = [
'id' => $font,
'text' => $font
];
$fonts[ 'variants' ][ $font ] = [ '100', '200', '300', '400', '500', '600', '700', '800', '900' ];
}
}
return $fonts;
}
/**
* Typekit fonts
*/
public function typekit_fonts( $fonts ) {
$typekit_fonts = get_option( 'custom-typekit-fonts' )[ 'custom-typekit-font-details' ];
if ( ! empty( $typekit_fonts ) ) {
$fonts[ 'families' ][ 'typekit_fonts' ] = array(
'text' => esc_html__( 'TypeKit Fonts', 'vlthemes' ),
'children' => []
);
foreach( $typekit_fonts as $font ) {
$id = $font[ 'slug' ];
$fonts[ 'families' ][ 'typekit_fonts' ][ 'children' ][] = [
'id' => $font[ 'slug' ],
'text' => $font[ 'family' ]
];
$fonts[ 'variants' ][ $id ] = $font[ 'weights' ];
}
}
return $fonts;
}
}
return VLThemesAddCustomFonts::instance();
}