-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.php
executable file
·50 lines (40 loc) · 1.19 KB
/
helper.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
<?php
/**
* FT Customizer Controls Helper
*
* @version 1.0.0
* @package WordPress
* @subpackage Customizer
*/
namespace FTCustomizerControls\Helper;
if ( ! defined( 'ABSPATH' ) ) {
exit( 'Not allowed' );
}
function enqueue_google_fonts( $theme_option_name = '' ) {
$fonts = trim( get_theme_mod( $theme_option_name, '' ) );
if ( 0 === strlen( $fonts ) ) {
return;
}
$fonts_array = array();
$lines = explode( "\n", $fonts );
foreach ( $lines as $line ) {
$font_name = get_string_between( $line, 'family=', '&display=swap' );
if ( 0 !== strpos( $font_name, ':wght@' ) ) {
$font_name = substr( $font_name, 0, strpos( $font_name, ':wght@' ) );
}
$font_name = str_replace( ' ', '-', strtolower( urldecode( $font_name ) ) );
$font_url = str_replace( 'https://', '//', $line );
$font_url = str_replace( 'http://', '//', $font_url );
wp_enqueue_style( $font_name, $font_url, array(), NULL );
}
}
function get_string_between( $string, $start, $end ){
$string = ' ' . $string;
$ini = strpos( $string, $start );
if ( $ini == 0 ) {
return '';
}
$ini += strlen( $start );
$len = strpos( $string, $end, $ini ) - $ini;
return substr( $string, $ini, $len );
}