-
Notifications
You must be signed in to change notification settings - Fork 1
/
FrontWP.php
109 lines (90 loc) · 2.94 KB
/
FrontWP.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
<?php
class FrontWP
{
public $options;
public $file;
public $path;
public $url;
public $name;
public $ver;
private static $instance;
public static function getInstance()
{
if (static::$instance === null) {
static::$instance = new static();
}
return static::$instance;
}
public function __clone(){}
public function __wakeup(){}
private function __construct()
{
$this->file = RW_FILE;
$this->path = RW_PLUGIN_DIR;
$this->url = RW_PLUGIN_URL;
$this->name = RW_LANG;
$this->ver = '1.1.3';
$this->options = get_option(RW_LANG,'');
$this->add_action();
}
public function add_action(){
add_action( 'wp_head', [$this, 'action_add_meta'], 10, 0 );
add_action( 'wp_head', [$this, 'add_header_js'], 10, 0 );
add_action( 'wp_head', [$this, 'add_header_css'], 10, 0 );
add_action( 'wp_head', [$this, 'rw_header_html'], 10, 0 );
add_action( 'wp_footer', [$this, 'rw_footer_html'], 10, 0 );
// add_action( 'the_post', [$this, 'add_post_code'], 10, 1 );
add_action( 'wp_enqueue_scripts', [$this, 'rw_enqueue_scripts'] );
add_action( 'wp_footer', [__CLASS__, 'add_wp_footer'], 10, 0 );
}
public function action_add_meta()
{
if(empty($this->options)){
return;
}
foreach ($this->options as $option => $value) {
if (is_string($option) && $option === 'meta_tags') {
if(!is_array($value))
continue;
foreach ($value as $val) {
if(!is_array($val))
continue;
foreach ($val as $item) {
if(!is_array($item))
continue;
echo $item;
}
}
}
}
}
public function add_header_js(){
if(!empty($this->options['rw_header_js'])){
echo '<script>' . $this->options['rw_header_js'] . '</script>';
}
}
public function add_header_css(){
if(!empty($this->options['rw_header_css'])){
echo '<style type="text/css">' .
$this->options['rw_header_css'] .
'</style>';
}
}
public function rw_header_html(){
if(!empty($this->options['rw_header_html'])){
echo $this->options['rw_header_html'];
}
}
public function rw_footer_html(){
if(!empty($this->options['rw_footer_html'])){
echo $this->options['rw_footer_html'];
}
}
public function rw_enqueue_scripts(){
wp_enqueue_style( $this->name, $this->url . 'assets/css/min/wp-addon.min.css', false, $this->ver );
do_action( 'rw_enqueue_scripts');
}
public static function add_wp_footer(){
do_action( 'add_front');
}
}