settings.class.php
6.23 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
if ( ! empty( $_SERVER['SCRIPT_FILENAME'] ) && basename( __FILE__ ) == basename( $_SERVER['SCRIPT_FILENAME'] ) ) {
die ( 'Please do not load this screen directly. Thanks!' );
}
/**
* WooDojo - Custom Code Settings
*
* Settings for the WooDojo - Custom Code feature.
*
* @package WordPress
* @subpackage WooDojo
* @category Bundled
* @author WooThemes
* @since 1.0.0
*
* TABLE OF CONTENTS
*
* - __construct()
* - init_sections()
* - init_fields()
* - validate_field_css()
* - validate_field_html()
* - get_allowed_html_tags()
*/
class WooDojo_CustomCode_Settings extends WooDojo_Settings_API {
/**
* __construct function.
*
* @access public
* @since 1.0.0
* @return void
*/
public function __construct () {
global $woodojo;
parent::__construct(); // Required in extended classes.
} // End __construct()
/**
* init_sections function.
*
* @access public
* @since 1.0.0
* @return void
*/
public function init_sections () {
$sections = array();
$sections['custom-css'] = array(
'name' => __( 'Custom CSS', 'woodojo' ),
'description' => __( 'Add custom CSS code to your website.', 'woodojo' )
);
if ( current_user_can( 'unfiltered_html' ) ) {
$sections['custom-html'] = array(
'name' => __( 'Custom HTML', 'woodojo' ),
'description' => __( 'Add custom HTML code to the <head> section or before the closing </body> tag on your website.', 'woodojo' )
);
}
$this->sections = $sections;
} // End init_sections()
/**
* init_fields function.
*
* @access public
* @since 1.0.0
* @return void
*/
public function init_fields () {
$fields = array();
$fields['custom-css-enable'] = array(
'name' => __( 'Enable Custom CSS', 'woodojo' ),
'description' => __( 'Output the custom CSS code on your website.', 'woodojo' ),
'type' => 'checkbox',
'default' => '',
'section' => 'custom-css',
'required' => 0
);
$fields['custom-css-code'] = array(
'name' => __( 'Custom CSS Code', 'woodojo' ),
'description' => __( 'Output this custom CSS code on your website.', 'woodojo' ),
'type' => 'css',
'default' => '',
'section' => 'custom-css',
'required' => 0,
'form' => 'form_field_textarea',
'validate' => 'validate_field_css'
);
if ( current_user_can( 'unfiltered_html' ) ) {
$fields['custom-html-enable'] = array(
'name' => __( 'Enable Custom HTML', 'woodojo' ),
'description' => __( 'Output the custom HTML code on your website.', 'woodojo' ),
'type' => 'checkbox',
'default' => '',
'section' => 'custom-html',
'required' => 0
);
$fields['custom-html-code-head'] = array(
'name' => __( 'Inside the <head> Tags', 'woodojo' ),
'description' => __( 'Output custom HTML code inside the <head> tags of your website (JavaScript is not permitted).', 'woodojo' ),
'type' => 'html',
'default' => '',
'section' => 'custom-html',
'required' => 0,
'form' => 'form_field_textarea',
'validate' => 'validate_field_html'
);
$fields['custom-html-code-footer'] = array(
'name' => __( 'Before the closing </body> Tag', 'woodojo' ),
'description' => __( 'Output custom HTML code before the closing </body> tag of your website (JavaScript is not permitted).', 'woodojo' ),
'type' => 'html',
'default' => '',
'section' => 'custom-html',
'required' => 0,
'form' => 'form_field_textarea',
'validate' => 'validate_field_html'
);
}
$this->fields = $fields;
} // End init_fields()
/**
* form_field_textarea function.
*
* @access public
* @since 1.0.0
* @param array $args
* @return void
*/
public function form_field_textarea ( $args ) {
if ( ! current_user_can( 'unfiltered_html' ) ) { return; }
$options = $this->get_settings();
echo '<textarea id="' . esc_attr( $args['key'] ) . '" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']" cols="42" rows="5">' . stripslashes( $options[ esc_attr( $args['key'] ) ] ) . '</textarea>' . "\n";
if ( isset( $args['data']['description'] ) ) {
echo '<p><span class="description">' . esc_attr( $args['data']['description'] ) . '</span></p>' . "\n";
}
} // End form_field_textarea()
/**
* validate_field_css function.
*
* @access public
* @param string $input
* @since 1.0.0
* @return void
*/
public function validate_field_css ( $input ) {
$input = wp_filter_nohtml_kses( strip_tags( $input ) );
return $input;
} // End validate_field_css()
/**
* validate_field_html function.
*
* @access public
* @param string $input
* @since 1.0.0
* @return void
*/
public function validate_field_html ( $input ) {
if ( ! current_user_can( 'unfiltered_html' ) ) {
$input = wp_strip_all_tags( $input );
}
$input = wp_kses( $input, $this->get_allowed_html_tags() );
$input = esc_textarea( $input );
return $input;
} // End validate_field_html()
/**
* Return an array of HTML tags allowed in the "Custom HTML" fields.
* @since 1.0.2
* @return array The allowed HTML tags.
*/
private function get_allowed_html_tags () {
return array(
'p' => array(
'class' => array(),
'align' => array(),
'dir' => array(),
'lang' => array(),
'style' => array(),
'xml:lang' => array()),
'a' => array(
'href' => array (),
'title' => array ()),
'abbr' => array(
'title' => array ()),
'acronym' => array(
'title' => array ()),
'b' => array(),
'blockquote' => array(
'cite' => array ()),
'cite' => array (),
'code' => array(),
'del' => array(
'datetime' => array ()),
'em' => array (), 'i' => array (),
'q' => array(
'cite' => array ()),
'strike' => array(),
'strong' => array(),
'meta' => array( 'name' => array(), 'content' => array() ),
'div' => array( 'class' => array(), 'id' => array(), 'style' => array() )
);
} // End get_allowed_html_tags()
} // End Class
?>