1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | namespace EventPost; |
11: | |
12: | class Icons{ |
13: | public $icons; |
14: | public $icons_html_entities; |
15: | public $transient_name; |
16: | public $transient_name_html_entities; |
17: | |
18: | function __construct(){ |
19: | $this->icons = []; |
20: | $this->icons_html_entities = []; |
21: | $this->transient_name = "dashicons_list"; |
22: | $this->transient_name_html_entities = "dashicons_list_html_entities"; |
23: | add_action('init', array(&$this,'init_icons')); |
24: | } |
25: | function init_icons() { |
26: | if(get_transient($this->transient_name) && get_transient($this->transient_name_html_entities)){ |
27: | $this->icons = get_transient($this->transient_name); |
28: | $this->icons_html_entities = get_transient($this->transient_name_html_entities); |
29: | }else{ |
30: | $css_file = file_get_contents(ABSPATH. 'wp-includes/css/dashicons.css'); |
31: | $css_array = explode('}',$css_file); |
32: | foreach ($css_array as $rule) { |
33: | $matches = []; |
34: | if(preg_match( "/\.dashicons-((?:\w+-?)+\w+):before {\s*content:\s*[\"\']\\\(\w+)[\"\'];/m", |
35: | $rule, |
36: | $matches)) |
37: | { |
38: | if(isset($matches[1]) && isset($matches[2])){ |
39: | $this->icons[$matches[1]] = $matches[2]; |
40: | $this->icons_html_entities[$matches[1]] = '&#x'.$matches[2].'; '.$matches[1]; |
41: | } |
42: | } |
43: | } |
44: | set_transient($this->transient_name , $this->icons, MONTH_IN_SECONDS ); |
45: | set_transient($this->transient_name_html_entities , $this->icons_html_entities, MONTH_IN_SECONDS ); |
46: | } |
47: | } |
48: | |
49: | } |
50: | |