@@ -17,6 +17,22 @@ private function wrap_var($v) {
17
17
if ($ v ) return true ;
18
18
return false ;
19
19
}
20
+
21
+ private function hex2rgb ($ hex ) {
22
+ $ hex = str_replace ("# " , "" , $ hex );
23
+
24
+ if (strlen ($ hex ) == 3 ) {
25
+ $ r = hexdec (substr ($ hex ,0 ,1 ).substr ($ hex ,0 ,1 ));
26
+ $ g = hexdec (substr ($ hex ,1 ,1 ).substr ($ hex ,1 ,1 ));
27
+ $ b = hexdec (substr ($ hex ,2 ,1 ).substr ($ hex ,2 ,1 ));
28
+ } else {
29
+ $ r = hexdec (substr ($ hex ,0 ,2 ));
30
+ $ g = hexdec (substr ($ hex ,2 ,2 ));
31
+ $ b = hexdec (substr ($ hex ,4 ,2 ));
32
+ }
33
+ return array ($ r , $ g , $ b );
34
+ }
35
+
20
36
public function add_canvas_nest () {
21
37
//判断当前页面是否开启
22
38
//is_home 、 is_archive 、 is_singular 、 is_search 、 is_404
@@ -43,6 +59,11 @@ public function add_canvas_nest() {
43
59
if ($ setting_count === false ) $ setting_count = '99 ' ;
44
60
$ setting_zindex = get_option ('cn_setting_zindex ' );
45
61
if ($ setting_zindex === false ) $ setting_zindex = '-1 ' ;
62
+
63
+ if (strpos ($ setting_color , '# ' ) === 0 ) {
64
+ $ setting_color = $ this ->hex2rgb ($ setting_color );
65
+ $ setting_color = join (', ' , $ setting_color );
66
+ }
46
67
echo "<script type='text/javascript' color=' $ setting_color' zIndex=' $ setting_zindex' opacity=' $ setting_opacity' count=' $ setting_count' src='//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js'></script> " ;
47
68
}
48
69
}
@@ -73,7 +94,8 @@ public function admin_init() {
73
94
'WP_Canvas_Nest-section ' ,
74
95
array (
75
96
'field ' => 'cn_setting_color ' ,
76
- 'value ' => '0,0,0 '
97
+ 'value ' => '0,0,0 ' ,
98
+ 'type ' => 'color '
77
99
)
78
100
);
79
101
add_settings_field (
@@ -84,7 +106,8 @@ public function admin_init() {
84
106
'WP_Canvas_Nest-section ' ,
85
107
array (
86
108
'field ' => 'cn_setting_opacity ' ,
87
- 'value ' => '0.5 '
109
+ 'value ' => '0.5 ' ,
110
+ 'type ' => 'text '
88
111
)
89
112
);
90
113
add_settings_field (
@@ -95,7 +118,8 @@ public function admin_init() {
95
118
'WP_Canvas_Nest-section ' ,
96
119
array (
97
120
'field ' => 'cn_setting_count ' ,
98
- 'value ' => '99 '
121
+ 'value ' => '99 ' ,
122
+ 'type ' => 'number '
99
123
)
100
124
);
101
125
add_settings_field (
@@ -106,7 +130,8 @@ public function admin_init() {
106
130
'WP_Canvas_Nest-section ' ,
107
131
array (
108
132
'field ' => 'cn_setting_zindex ' ,
109
- 'value ' => '-1 '
133
+ 'value ' => '-1 ' ,
134
+ 'type ' => 'number '
110
135
)
111
136
);
112
137
@@ -203,11 +228,12 @@ public function settings_field_checkbox($args) {
203
228
*/
204
229
public function settings_field_input_text ($ args ) {
205
230
$ field = $ args ['field ' ];
231
+ $ type = $ args ['type ' ];
206
232
$ value = get_option ($ field );
207
233
if ($ value === false ) {
208
234
$ value = $ args ['value ' ];
209
235
}
210
- echo sprintf ('<input type="text " name="%s" id="%s" value="%s" /> ' , $ field , $ field , $ value );
236
+ echo sprintf ('<input type="%s " name="%s" id="%s" value="%s" /> ' , $ type , $ field , $ field , $ value );
211
237
}
212
238
213
239
/**
0 commit comments