| 1 |
<?php |
| 2 |
/** |
| 3 |
* Load google fonts. |
| 4 |
*/ |
| 5 |
|
| 6 |
// Exit if accessed directly. |
| 7 |
if (!defined('ABSPATH')) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
class Toggle_Font_Loader |
| 12 |
{ |
| 13 |
|
| 14 |
private static $instance; |
| 15 |
|
| 16 |
/** |
| 17 |
* Registers the plugin. |
| 18 |
*/ |
| 19 |
public static function register() |
| 20 |
{ |
| 21 |
if (null === self::$instance) { |
| 22 |
self::$instance = new self; |
| 23 |
} |
| 24 |
return self::$instance; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* The Constructor. |
| 29 |
*/ |
| 30 |
public function __construct() |
| 31 |
{ |
| 32 |
|
| 33 |
add_action('wp_enqueue_scripts', array($this, 'fonts_loader')); |
| 34 |
add_action('admin_enqueue_scripts', array($this, 'fonts_loader')); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Load fonts. |
| 39 |
* |
| 40 |
* @access public |
| 41 |
*/ |
| 42 |
public function fonts_loader() |
| 43 |
{ |
| 44 |
global $post; |
| 45 |
|
| 46 |
if ($post && isset($post->ID)) { |
| 47 |
|
| 48 |
$fonts = get_post_meta($post->ID, '_eb_attr', true); |
| 49 |
|
| 50 |
if (!empty($fonts)) { |
| 51 |
|
| 52 |
$fonts = array_unique(explode(',', $fonts)); |
| 53 |
|
| 54 |
$system = array( |
| 55 |
'Arial', |
| 56 |
'Tahoma', |
| 57 |
'Verdana', |
| 58 |
'Helvetica', |
| 59 |
'Times New Roman', |
| 60 |
'Trebuchet MS', |
| 61 |
'Georgia', |
| 62 |
); |
| 63 |
|
| 64 |
$gfonts = ''; |
| 65 |
|
| 66 |
$gfonts_attr = ':100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic'; |
| 67 |
|
| 68 |
foreach ($fonts as $font) { |
| 69 |
if (!in_array($font, $system, true) && !empty($font)) { |
| 70 |
$gfonts .= str_replace(' ', '+', trim($font)) . $gfonts_attr . '|'; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
if (!empty($gfonts)) { |
| 75 |
$query_args = array( |
| 76 |
'family' => $gfonts, |
| 77 |
); |
| 78 |
|
| 79 |
wp_register_style( |
| 80 |
'eb-block-fonts', |
| 81 |
add_query_arg($query_args, '//fonts.googleapis.com/css'), |
| 82 |
array() |
| 83 |
); |
| 84 |
|
| 85 |
wp_enqueue_style('eb-block-fonts'); |
| 86 |
} |
| 87 |
|
| 88 |
// Reset. |
| 89 |
$gfonts = ''; |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
Toggle_Font_Loader::register(); |
| 95 |
|