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