PluginProbe
StreamCast – bring live radio to your site with a sleek player / 2.4.0
StreamCast – bring live radio to your site with a sleek player v2.4.0
2.4.5 2.4.4 trunk 1.0 1.1 2.0.0 2.1.10 2.1.2 2.1.4 2.1.5 2.1.8 2.2.1 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 All 29 releases
← All changes | frameworks/codestar-framework/classes/metabox-options.class.php +411 -413 2.3.42.4.0 View file →
@@ -1,413 +1,411 @@
1 -<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
2 -/**
3 - *
4 - * Metabox Class
5 - *
6 - * @since 1.0.0
7 - * @version 1.0.0
8 - *
9 - */
10 -if ( ! class_exists( 'CSF_Metabox' ) ) {
11 - class CSF_Metabox extends CSF_Abstract{
12 -
13 - // constans
14 - public $unique = '';
15 - public $abstract = 'metabox';
16 - public $sections = array();
17 - public $pre_fields = array();
18 - public $post_type = array();
19 - public $post_formats = array();
20 - public $page_templates = array();
21 - public $args = array(
22 - 'title' => '',
23 - 'post_type' => 'post',
24 - 'data_type' => 'serialize',
25 - 'context' => 'advanced',
26 - 'priority' => 'default',
27 - 'exclude_post_types' => array(),
28 - 'page_templates' => '',
29 - 'post_formats' => '',
30 - 'show_reset' => false,
31 - 'show_restore' => false,
32 - 'enqueue_webfont' => true,
33 - 'async_webfont' => false,
34 - 'output_css' => true,
35 - 'nav' => 'normal',
36 - 'theme' => 'dark',
37 - 'class' => '',
38 - 'defaults' => array(),
39 - );
40 -
41 - // run metabox construct
42 - public function __construct( $key, $params = array() ) {
43 -
44 - $this->unique = $key;
45 - $this->args = apply_filters( "csf_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this );
46 - $this->sections = apply_filters( "csf_{$this->unique}_sections", $params['sections'], $this );
47 - $this->post_type = ( is_array( $this->args['post_type'] ) ) ? $this->args['post_type'] : array_filter( (array) $this->args['post_type'] );
48 - $this->post_formats = ( is_array( $this->args['post_formats'] ) ) ? $this->args['post_formats'] : array_filter( (array) $this->args['post_formats'] );
49 - $this->page_templates = ( is_array( $this->args['page_templates'] ) ) ? $this->args['page_templates'] : array_filter( (array) $this->args['page_templates'] );
50 - $this->pre_fields = $this->pre_fields( $this->sections );
51 -
52 - add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
53 - add_action( 'save_post', array( $this, 'save_meta_box' ) );
54 - add_action( 'edit_attachment', array( $this, 'save_meta_box' ) );
55 -
56 - if ( ! empty( $this->page_templates ) || ! empty( $this->post_formats ) || ! empty( $this->args['class'] ) ) {
57 - foreach ( $this->post_type as $post_type ) {
58 - add_filter( 'postbox_classes_'. $post_type .'_'. $this->unique, array( $this, 'add_metabox_classes' ) );
59 - }
60 - }
61 -
62 - // wp enqeueu for typography and output css
63 - parent::__construct();
64 -
65 - }
66 -
67 - // instance
68 - public static function instance( $key, $params = array() ) {
69 - return new self( $key, $params );
70 - }
71 -
72 - public function add_metabox_classes( $classes ) {
73 -
74 - global $post;
75 -
76 - if ( ! empty( $this->post_formats ) ) {
77 -
78 - $saved_post_format = ( is_object( $post ) ) ? get_post_format( $post ) : false;
79 - $saved_post_format = ( ! empty( $saved_post_format ) ) ? $saved_post_format : 'default';
80 -
81 - $classes[] = 'csf-post-formats';
82 -
83 - // Sanitize post format for standard to default
84 - if ( ( $key = array_search( 'standard', $this->post_formats ) ) !== false ) {
85 - $this->post_formats[$key] = 'default';
86 - }
87 -
88 - foreach ( $this->post_formats as $format ) {
89 - $classes[] = 'csf-post-format-'. $format;
90 - }
91 -
92 - if ( ! in_array( $saved_post_format, $this->post_formats ) ) {
93 - $classes[] = 'csf-metabox-hide';
94 - } else {
95 - $classes[] = 'csf-metabox-show';
96 - }
97 -
98 - }
99 -
100 - if ( ! empty( $this->page_templates ) ) {
101 -
102 - $saved_template = ( is_object( $post ) && ! empty( $post->page_template ) ) ? $post->page_template : 'default';
103 -
104 - $classes[] = 'csf-page-templates';
105 -
106 - foreach ( $this->page_templates as $template ) {
107 - $classes[] = 'csf-page-'. preg_replace( '/[^a-zA-Z0-9]+/', '-', strtolower( $template ) );
108 - }
109 -
110 - if ( ! in_array( $saved_template, $this->page_templates ) ) {
111 - $classes[] = 'csf-metabox-hide';
112 - } else {
113 - $classes[] = 'csf-metabox-show';
114 - }
115 -
116 - }
117 -
118 - if ( ! empty( $this->args['class'] ) ) {
119 - $classes[] = $this->args['class'];
120 - }
121 -
122 - return $classes;
123 -
124 - }
125 -
126 - // add metabox
127 - public function add_meta_box( $post_type ) {
128 -
129 - if ( ! in_array( $post_type, $this->args['exclude_post_types'] ) ) {
130 - add_meta_box( $this->unique, $this->args['title'], array( $this, 'add_meta_box_content' ), $this->post_type, $this->args['context'], $this->args['priority'], $this->args );
131 - }
132 -
133 - }
134 -
135 - // get default value
136 - public function get_default( $field ) {
137 -
138 - $default = ( isset( $field['default'] ) ) ? $field['default'] : '';
139 - $default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default;
140 -
141 - return $default;
142 -
143 - }
144 -
145 - // get meta value
146 - public function get_meta_value( $field ) {
147 -
148 - global $post;
149 -
150 - $value = null;
151 -
152 - if ( is_object( $post ) && ! empty( $field['id'] ) ) {
153 -
154 - if ( $this->args['data_type'] !== 'serialize' ) {
155 - $meta = get_post_meta( $post->ID, $field['id'] );
156 - $value = ( isset( $meta[0] ) ) ? $meta[0] : null;
157 - } else {
158 - $meta = get_post_meta( $post->ID, $this->unique, true );
159 - $value = ( isset( $meta[$field['id']] ) ) ? $meta[$field['id']] : null;
160 - }
161 -
162 - }
163 -
164 - $default = ( isset( $field['id'] ) ) ? $this->get_default( $field ) : '';
165 - $value = ( isset( $value ) ) ? $value : $default;
166 -
167 - return $value;
168 -
169 - }
170 -
171 - // add metabox content
172 - public function add_meta_box_content( $post, $callback ) {
173 -
174 - global $post;
175 -
176 - $has_nav = ( count( $this->sections ) > 1 && $this->args['context'] !== 'side' ) ? true : false;
177 - $show_all = ( ! $has_nav ) ? ' csf-show-all' : '';
178 - $post_type = ( is_object ( $post ) ) ? $post->post_type : '';
179 - $errors = ( is_object ( $post ) ) ? get_post_meta( $post->ID, '_csf_errors_'. $this->unique, true ) : array();
180 - $errors = ( ! empty( $errors ) ) ? $errors : array();
181 - $theme = ( $this->args['theme'] ) ? ' csf-theme-'. $this->args['theme'] : '';
182 - $nav_type = ( $this->args['nav'] === 'inline' ) ? 'inline' : 'normal';
183 -
184 - if ( is_object ( $post ) && ! empty( $errors ) ) {
185 - delete_post_meta( $post->ID, '_csf_errors_'. $this->unique );
186 - }
187 -
188 - wp_nonce_field( 'csf_metabox_nonce', 'csf_metabox_nonce'. $this->unique );
189 -
190 - echo '<div class="csf csf-metabox'. esc_attr( $theme ) .'">';
191 -
192 - echo '<div class="csf-wrapper'. esc_attr( $show_all ) .'">';
193 -
194 - if ( $has_nav ) {
195 -
196 - echo '<div class="csf-nav csf-nav-'. esc_attr( $nav_type ) .' csf-nav-metabox">';
197 -
198 - echo '<ul>';
199 -
200 - $tab_key = 0;
201 -
202 - foreach ( $this->sections as $section ) {
203 -
204 - if ( ! empty( $section['post_type'] ) && ! in_array( $post_type, array_filter( (array) $section['post_type'] ) ) ) {
205 - continue;
206 - }
207 -
208 - $tab_error = ( ! empty( $errors['sections'][$tab_key] ) ) ? '<i class="csf-label-error csf-error">!</i>' : '';
209 - $tab_icon = ( ! empty( $section['icon'] ) ) ? '<i class="csf-tab-icon '. esc_attr( $section['icon'] ) .'"></i>' : '';
210 -
211 - echo '<li><a href="#">'. $tab_icon . $section['title'] . $tab_error .'</a></li>';
212 -
213 - $tab_key++;
214 -
215 - }
216 -
217 - echo '</ul>';
218 -
219 - echo '</div>';
220 -
221 - }
222 -
223 - echo '<div class="csf-content">';
224 -
225 - echo '<div class="csf-sections">';
226 -
227 - $section_key = 0;
228 -
229 - foreach ( $this->sections as $section ) {
230 -
231 - if ( ! empty( $section['post_type'] ) && ! in_array( $post_type, array_filter( (array) $section['post_type'] ) ) ) {
232 - continue;
233 - }
234 -
235 - $section_onload = ( ! $has_nav ) ? ' csf-onload' : '';
236 - $section_class = ( ! empty( $section['class'] ) ) ? ' '. $section['class'] : '';
237 - $section_title = ( ! empty( $section['title'] ) ) ? $section['title'] : '';
238 - $section_icon = ( ! empty( $section['icon'] ) ) ? '<i class="csf-section-icon '. esc_attr( $section['icon'] ) .'"></i>' : '';
239 -
240 - echo '<div class="csf-section hidden'. esc_attr( $section_onload . $section_class ) .'">';
241 -
242 - echo ( $section_title || $section_icon ) ? '<div class="csf-section-title"><h3>'. $section_icon . $section_title .'</h3></div>' : '';
243 - echo ( ! empty( $section['description'] ) ) ? '<div class="csf-field csf-section-description">'. $section['description'] .'</div>' : '';
244 -
245 - if ( ! empty( $section['fields'] ) ) {
246 -
247 - foreach ( $section['fields'] as $field ) {
248 -
249 - if ( ! empty( $field['id'] ) && ! empty( $errors['fields'][$field['id']] ) ) {
250 - $field['_error'] = $errors['fields'][$field['id']];
251 - }
252 -
253 - if ( ! empty( $field['id'] ) ) {
254 - $field['default'] = $this->get_default( $field );
255 - }
256 -
257 - CSF::field( $field, $this->get_meta_value( $field ), $this->unique, 'metabox' );
258 -
259 - }
260 -
261 - } else {
262 -
263 - echo '<div class="csf-no-option">'. esc_html__( 'No data available.', 'csf' ) .'</div>';
264 -
265 - }
266 -
267 - echo '</div>';
268 -
269 - $section_key++;
270 -
271 - }
272 -
273 - echo '</div>';
274 -
275 - if ( ! empty( $this->args['show_restore'] ) || ! empty( $this->args['show_reset'] ) ) {
276 -
277 - echo '<div class="csf-sections-reset">';
278 - echo '<label>';
279 - echo '<input type="checkbox" name="'. esc_attr( $this->unique ) .'[_reset]" />';
280 - echo '<span class="button csf-button-reset">'. esc_html__( 'Reset', 'csf' ) .'</span>';
281 - echo '<span class="button csf-button-cancel">'. sprintf( '<small>( %s )</small> %s', esc_html__( 'update post', 'csf' ), esc_html__( 'Cancel', 'csf' ) ) .'</span>';
282 - echo '</label>';
283 - echo '</div>';
284 -
285 - }
286 -
287 - echo '</div>';
288 -
289 - echo ( $has_nav && $nav_type === 'normal' ) ? '<div class="csf-nav-background"></div>' : '';
290 -
291 - echo '<div class="clear"></div>';
292 -
293 - echo '</div>';
294 -
295 - echo '</div>';
296 -
297 - }
298 -
299 - // save metabox
300 - public function save_meta_box( $post_id ) {
301 -
302 - $count = 1;
303 - $data = array();
304 - $errors = array();
305 - $noncekey = 'csf_metabox_nonce'. $this->unique;
306 - $nonce = ( ! empty( $_POST[ $noncekey ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ $noncekey ] ) ) : '';
307 -
308 - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! wp_verify_nonce( $nonce, 'csf_metabox_nonce' ) ) {
309 - return $post_id;
310 - }
311 -
312 - // XSS ok.
313 - // No worries, This "POST" requests is sanitizing in the below foreach.
314 - $request = ( ! empty( $_POST[ $this->unique ] ) ) ? $_POST[ $this->unique ] : array();
315 -
316 - if ( ! empty( $request ) ) {
317 -
318 - foreach ( $this->sections as $section ) {
319 -
320 - if ( ! empty( $section['fields'] ) ) {
321 -
322 - foreach ( $section['fields'] as $field ) {
323 -
324 - if ( ! empty( $field['id'] ) ) {
325 -
326 - $field_id = $field['id'];
327 - $field_value = isset( $request[$field_id] ) ? $request[$field_id] : '';
328 -
329 - // Sanitize "post" request of field.
330 - if ( ! isset( $field['sanitize'] ) ) {
331 -
332 - if( is_array( $field_value ) ) {
333 - $data[$field_id] = wp_kses_post_deep( $field_value );
334 - } else {
335 - $data[$field_id] = wp_kses_post( $field_value );
336 - }
337 -
338 - } else if( isset( $field['sanitize'] ) && is_callable( $field['sanitize'] ) ) {
339 -
340 - $data[$field_id] = call_user_func( $field['sanitize'], $field_value );
341 -
342 - } else {
343 -
344 - $data[$field_id] = $field_value;
345 -
346 - }
347 -
348 - // Validate "post" request of field.
349 - if ( isset( $field['validate'] ) && is_callable( $field['validate'] ) ) {
350 -
351 - $has_validated = call_user_func( $field['validate'], $field_value );
352 -
353 - if ( ! empty( $has_validated ) ) {
354 -
355 - $errors['sections'][$count] = true;
356 - $errors['fields'][$field_id] = $has_validated;
357 - $data[$field_id] = $this->get_meta_value( $field );
358 -
359 - }
360 -
361 - }
362 -
363 - }
364 -
365 - }
366 -
367 - }
368 -
369 - $count++;
370 -
371 - }
372 -
373 - }
374 -
375 - $data = apply_filters( "csf_{$this->unique}_save", $data, $post_id, $this );
376 -
377 - do_action( "csf_{$this->unique}_save_before", $data, $post_id, $this );
378 -
379 - if ( empty( $data ) || ! empty( $request['_reset'] ) ) {
380 -
381 - if ( $this->args['data_type'] !== 'serialize' ) {
382 - foreach ( $this->pre_fields as $field ) {
383 - if ( ! empty( $field['id'] ) ) {
384 - delete_post_meta( $post_id, $field['id'] );
385 - }
386 - }
387 - } else {
388 - delete_post_meta( $post_id, $this->unique );
389 - }
390 -
391 - } else {
392 -
393 - if ( $this->args['data_type'] !== 'serialize' ) {
394 - foreach ( $data as $key => $value ) {
395 - update_post_meta( $post_id, $key, $value );
396 - }
397 - } else {
398 - update_post_meta( $post_id, $this->unique, $data );
399 - }
400 -
401 - if ( ! empty( $errors ) ) {
402 - update_post_meta( $post_id, '_csf_errors_'. $this->unique, $errors );
403 - }
404 -
405 - }
406 -
407 - do_action( "csf_{$this->unique}_saved", $data, $post_id, $this );
408 -
409 - do_action( "csf_{$this->unique}_save_after", $data, $post_id, $this );
410 -
411 - }
412 - }
413 -}
1 +<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
2 +/**
3 + *
4 + * Metabox Class
5 + *
6 + * @since 1.0.0
7 + * @version 1.0.0
8 + *
9 + */
10 +if ( ! class_exists( 'CSF_Metabox' ) ) {
11 + class CSF_Metabox extends CSF_Abstract{
12 +
13 + // constans
14 + public $unique = '';
15 + public $abstract = 'metabox';
16 + public $sections = array();
17 + public $pre_fields = array();
18 + public $post_type = array();
19 + public $args = array(
20 + 'title' => '',
21 + 'post_type' => 'post',
22 + 'data_type' => 'serialize',
23 + 'context' => 'advanced',
24 + 'priority' => 'default',
25 + 'exclude_post_types' => array(),
26 + 'page_templates' => '',
27 + 'post_formats' => '',
28 + 'show_reset' => false,
29 + 'show_restore' => false,
30 + 'enqueue_webfont' => true,
31 + 'async_webfont' => false,
32 + 'output_css' => true,
33 + 'nav' => 'normal',
34 + 'theme' => 'dark',
35 + 'class' => '',
36 + 'defaults' => array(),
37 + );
38 +
39 + // run metabox construct
40 + public function __construct( $key, $params = array() ) {
41 +
42 + $this->unique = $key;
43 + $this->args = apply_filters( "csf_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this );
44 + $this->sections = apply_filters( "csf_{$this->unique}_sections", $params['sections'], $this );
45 + $this->post_type = ( is_array( $this->args['post_type'] ) ) ? $this->args['post_type'] : array_filter( (array) $this->args['post_type'] );
46 + $this->post_formats = ( is_array( $this->args['post_formats'] ) ) ? $this->args['post_formats'] : array_filter( (array) $this->args['post_formats'] );
47 + $this->page_templates = ( is_array( $this->args['page_templates'] ) ) ? $this->args['page_templates'] : array_filter( (array) $this->args['page_templates'] );
48 + $this->pre_fields = $this->pre_fields( $this->sections );
49 +
50 + add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
51 + add_action( 'save_post', array( $this, 'save_meta_box' ) );
52 + add_action( 'edit_attachment', array( $this, 'save_meta_box' ) );
53 +
54 + if ( ! empty( $this->page_templates ) || ! empty( $this->post_formats ) || ! empty( $this->args['class'] ) ) {
55 + foreach ( $this->post_type as $post_type ) {
56 + add_filter( 'postbox_classes_'. $post_type .'_'. $this->unique, array( $this, 'add_metabox_classes' ) );
57 + }
58 + }
59 +
60 + // wp enqeueu for typography and output css
61 + parent::__construct();
62 +
63 + }
64 +
65 + // instance
66 + public static function instance( $key, $params = array() ) {
67 + return new self( $key, $params );
68 + }
69 +
70 + public function add_metabox_classes( $classes ) {
71 +
72 + global $post;
73 +
74 + if ( ! empty( $this->post_formats ) ) {
75 +
76 + $saved_post_format = ( is_object( $post ) ) ? get_post_format( $post ) : false;
77 + $saved_post_format = ( ! empty( $saved_post_format ) ) ? $saved_post_format : 'default';
78 +
79 + $classes[] = 'csf-post-formats';
80 +
81 + // Sanitize post format for standard to default
82 + if ( ( $key = array_search( 'standard', $this->post_formats ) ) !== false ) {
83 + $this->post_formats[$key] = 'default';
84 + }
85 +
86 + foreach ( $this->post_formats as $format ) {
87 + $classes[] = 'csf-post-format-'. $format;
88 + }
89 +
90 + if ( ! in_array( $saved_post_format, $this->post_formats ) ) {
91 + $classes[] = 'csf-metabox-hide';
92 + } else {
93 + $classes[] = 'csf-metabox-show';
94 + }
95 +
96 + }
97 +
98 + if ( ! empty( $this->page_templates ) ) {
99 +
100 + $saved_template = ( is_object( $post ) && ! empty( $post->page_template ) ) ? $post->page_template : 'default';
101 +
102 + $classes[] = 'csf-page-templates';
103 +
104 + foreach ( $this->page_templates as $template ) {
105 + $classes[] = 'csf-page-'. preg_replace( '/[^a-zA-Z0-9]+/', '-', strtolower( $template ) );
106 + }
107 +
108 + if ( ! in_array( $saved_template, $this->page_templates ) ) {
109 + $classes[] = 'csf-metabox-hide';
110 + } else {
111 + $classes[] = 'csf-metabox-show';
112 + }
113 +
114 + }
115 +
116 + if ( ! empty( $this->args['class'] ) ) {
117 + $classes[] = $this->args['class'];
118 + }
119 +
120 + return $classes;
121 +
122 + }
123 +
124 + // add metabox
125 + public function add_meta_box( $post_type ) {
126 +
127 + if ( ! in_array( $post_type, $this->args['exclude_post_types'] ) ) {
128 + add_meta_box( $this->unique, $this->args['title'], array( $this, 'add_meta_box_content' ), $this->post_type, $this->args['context'], $this->args['priority'], $this->args );
129 + }
130 +
131 + }
132 +
133 + // get default value
134 + public function get_default( $field ) {
135 +
136 + $default = ( isset( $field['default'] ) ) ? $field['default'] : '';
137 + $default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default;
138 +
139 + return $default;
140 +
141 + }
142 +
143 + // get meta value
144 + public function get_meta_value( $field ) {
145 +
146 + global $post;
147 +
148 + $value = null;
149 +
150 + if ( is_object( $post ) && ! empty( $field['id'] ) ) {
151 +
152 + if ( $this->args['data_type'] !== 'serialize' ) {
153 + $meta = get_post_meta( $post->ID, $field['id'] );
154 + $value = ( isset( $meta[0] ) ) ? $meta[0] : null;
155 + } else {
156 + $meta = get_post_meta( $post->ID, $this->unique, true );
157 + $value = ( isset( $meta[$field['id']] ) ) ? $meta[$field['id']] : null;
158 + }
159 +
160 + }
161 +
162 + $default = ( isset( $field['id'] ) ) ? $this->get_default( $field ) : '';
163 + $value = ( isset( $value ) ) ? $value : $default;
164 +
165 + return $value;
166 +
167 + }
168 +
169 + // add metabox content
170 + public function add_meta_box_content( $post, $callback ) {
171 +
172 + global $post;
173 +
174 + $has_nav = ( count( $this->sections ) > 1 && $this->args['context'] !== 'side' ) ? true : false;
175 + $show_all = ( ! $has_nav ) ? ' csf-show-all' : '';
176 + $post_type = ( is_object ( $post ) ) ? $post->post_type : '';
177 + $errors = ( is_object ( $post ) ) ? get_post_meta( $post->ID, '_csf_errors_'. $this->unique, true ) : array();
178 + $errors = ( ! empty( $errors ) ) ? $errors : array();
179 + $theme = ( $this->args['theme'] ) ? ' csf-theme-'. $this->args['theme'] : '';
180 + $nav_type = ( $this->args['nav'] === 'inline' ) ? 'inline' : 'normal';
181 +
182 + if ( is_object ( $post ) && ! empty( $errors ) ) {
183 + delete_post_meta( $post->ID, '_csf_errors_'. $this->unique );
184 + }
185 +
186 + wp_nonce_field( 'csf_metabox_nonce', 'csf_metabox_nonce'. $this->unique );
187 +
188 + echo '<div class="csf csf-metabox'. esc_attr( $theme ) .'">';
189 +
190 + echo '<div class="csf-wrapper'. esc_attr( $show_all ) .'">';
191 +
192 + if ( $has_nav ) {
193 +
194 + echo '<div class="csf-nav csf-nav-'. esc_attr( $nav_type ) .' csf-nav-metabox">';
195 +
196 + echo '<ul>';
197 +
198 + $tab_key = 0;
199 +
200 + foreach ( $this->sections as $section ) {
201 +
202 + if ( ! empty( $section['post_type'] ) && ! in_array( $post_type, array_filter( (array) $section['post_type'] ) ) ) {
203 + continue;
204 + }
205 +
206 + $tab_error = ( ! empty( $errors['sections'][$tab_key] ) ) ? '<i class="csf-label-error csf-error">!</i>' : '';
207 + $tab_icon = ( ! empty( $section['icon'] ) ) ? '<i class="csf-tab-icon '. esc_attr( $section['icon'] ) .'"></i>' : '';
208 +
209 + echo '<li><a href="#">'. wp_kses_post( $tab_icon ) . wp_kses_post( $section['title'] ) . wp_kses_post( $tab_error ) .'</a></li>';
210 +
211 + $tab_key++;
212 +
213 + }
214 +
215 + echo '</ul>';
216 +
217 + echo '</div>';
218 +
219 + }
220 +
221 + echo '<div class="csf-content">';
222 +
223 + echo '<div class="csf-sections">';
224 +
225 + $section_key = 0;
226 +
227 + foreach ( $this->sections as $section ) {
228 +
229 + if ( ! empty( $section['post_type'] ) && ! in_array( $post_type, array_filter( (array) $section['post_type'] ) ) ) {
230 + continue;
231 + }
232 +
233 + $section_onload = ( ! $has_nav ) ? ' csf-onload' : '';
234 + $section_class = ( ! empty( $section['class'] ) ) ? ' '. $section['class'] : '';
235 + $section_title = ( ! empty( $section['title'] ) ) ? $section['title'] : '';
236 + $section_icon = ( ! empty( $section['icon'] ) ) ? '<i class="csf-section-icon '. esc_attr( $section['icon'] ) .'"></i>' : '';
237 +
238 + echo '<div class="csf-section hidden'. esc_attr( $section_onload . $section_class ) .'">';
239 +
240 + echo ( $section_title || $section_icon ) ? '<div class="csf-section-title"><h3>'. wp_kses_post( $section_icon ) . wp_kses_post( $section_title ) .'</h3></div>' : '';
241 + echo ( ! empty( $section['description'] ) ) ? '<div class="csf-field csf-section-description">'. wp_kses_post( $section['description'] ) .'</div>' : '';
242 +
243 + if ( ! empty( $section['fields'] ) ) {
244 +
245 + foreach ( $section['fields'] as $field ) {
246 +
247 + if ( ! empty( $field['id'] ) && ! empty( $errors['fields'][$field['id']] ) ) {
248 + $field['_error'] = $errors['fields'][$field['id']];
249 + }
250 +
251 + if ( ! empty( $field['id'] ) ) {
252 + $field['default'] = $this->get_default( $field );
253 + }
254 +
255 + CSF::field( $field, $this->get_meta_value( $field ), $this->unique, 'metabox' );
256 +
257 + }
258 +
259 + } else {
260 +
261 + echo '<div class="csf-no-option">'. esc_html__( 'No data available.', 'streamcast' ) .'</div>';
262 +
263 + }
264 +
265 + echo '</div>';
266 +
267 + $section_key++;
268 +
269 + }
270 +
271 + echo '</div>';
272 +
273 + if ( ! empty( $this->args['show_restore'] ) || ! empty( $this->args['show_reset'] ) ) {
274 +
275 + echo '<div class="csf-sections-reset">';
276 + echo '<label>';
277 + echo '<input type="checkbox" name="'. esc_attr( $this->unique ) .'[_reset]" />';
278 + echo '<span class="button csf-button-reset">'. esc_html__( 'Reset', 'streamcast' ) .'</span>';
279 + echo '<span class="button csf-button-cancel">'. sprintf( '<small>( %s )</small> %s', esc_html__( 'update post', 'streamcast' ), esc_html__( 'Cancel', 'streamcast' ) ) .'</span>';
280 + echo '</label>';
281 + echo '</div>';
282 +
283 + }
284 +
285 + echo '</div>';
286 +
287 + echo ( $has_nav && $nav_type === 'normal' ) ? '<div class="csf-nav-background"></div>' : '';
288 +
289 + echo '<div class="clear"></div>';
290 +
291 + echo '</div>';
292 +
293 + echo '</div>';
294 +
295 + }
296 +
297 + // save metabox
298 + public function save_meta_box( $post_id ) {
299 +
300 + $count = 1;
301 + $data = array();
302 + $errors = array();
303 + $noncekey = 'csf_metabox_nonce'. $this->unique;
304 + $nonce = ( ! empty( $_POST[ $noncekey ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ $noncekey ] ) ) : '';
305 +
306 + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! wp_verify_nonce( $nonce, 'csf_metabox_nonce' ) ) {
307 + return $post_id;
308 + }
309 +
310 + // XSS ok.
311 + // No worries, This "POST" requests is sanitizing in the below foreach.
312 + $request = ( ! empty( $_POST[ $this->unique ] ) ) ? wp_unslash( $_POST[ $this->unique ] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
313 +
314 + if ( ! empty( $request ) ) {
315 +
316 + foreach ( $this->sections as $section ) {
317 +
318 + if ( ! empty( $section['fields'] ) ) {
319 +
320 + foreach ( $section['fields'] as $field ) {
321 +
322 + if ( ! empty( $field['id'] ) ) {
323 +
324 + $field_id = $field['id'];
325 + $field_value = isset( $request[$field_id] ) ? $request[$field_id] : '';
326 +
327 + // Sanitize "post" request of field.
328 + if ( ! isset( $field['sanitize'] ) ) {
329 +
330 + if( is_array( $field_value ) ) {
331 + $data[$field_id] = wp_kses_post_deep( $field_value );
332 + } else {
333 + $data[$field_id] = wp_kses_post( $field_value );
334 + }
335 +
336 + } else if( isset( $field['sanitize'] ) && is_callable( $field['sanitize'] ) ) {
337 +
338 + $data[$field_id] = call_user_func( $field['sanitize'], $field_value );
339 +
340 + } else {
341 +
342 + $data[$field_id] = $field_value;
343 +
344 + }
345 +
346 + // Validate "post" request of field.
347 + if ( isset( $field['validate'] ) && is_callable( $field['validate'] ) ) {
348 +
349 + $has_validated = call_user_func( $field['validate'], $field_value );
350 +
351 + if ( ! empty( $has_validated ) ) {
352 +
353 + $errors['sections'][$count] = true;
354 + $errors['fields'][$field_id] = $has_validated;
355 + $data[$field_id] = $this->get_meta_value( $field );
356 +
357 + }
358 +
359 + }
360 +
361 + }
362 +
363 + }
364 +
365 + }
366 +
367 + $count++;
368 +
369 + }
370 +
371 + }
372 +
373 + $data = apply_filters( "csf_{$this->unique}_save", $data, $post_id, $this );
374 +
375 + do_action( "csf_{$this->unique}_save_before", $data, $post_id, $this );
376 +
377 + if ( empty( $data ) || ! empty( $request['_reset'] ) ) {
378 +
379 + if ( $this->args['data_type'] !== 'serialize' ) {
380 + foreach ( $this->pre_fields as $field ) {
381 + if ( ! empty( $field['id'] ) ) {
382 + delete_post_meta( $post_id, $field['id'] );
383 + }
384 + }
385 + } else {
386 + delete_post_meta( $post_id, $this->unique );
387 + }
388 +
389 + } else {
390 +
391 + if ( $this->args['data_type'] !== 'serialize' ) {
392 + foreach ( $data as $key => $value ) {
393 + update_post_meta( $post_id, $key, $value );
394 + }
395 + } else {
396 + update_post_meta( $post_id, $this->unique, $data );
397 + }
398 +
399 + if ( ! empty( $errors ) ) {
400 + update_post_meta( $post_id, '_csf_errors_'. $this->unique, $errors );
401 + }
402 +
403 + }
404 +
405 + do_action( "csf_{$this->unique}_saved", $data, $post_id, $this );
406 +
407 + do_action( "csf_{$this->unique}_save_after", $data, $post_id, $this );
408 +
409 + }
410 + }
411 +}