← All changes
|
Libs/adminify-framework/classes/taxonomy-options.class.php
+189
-228
4.2.11
→
3.2.4.1
View file →
| @@ -1,5 +1,6 @@ | ||
| 1 | -<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. | |
| 1 | +<?php if ( ! defined( 'ABSPATH' ) ) { | |
| 2 | + die; } // Cannot access directly. | |
| 2 | 3 | /** |
| 3 | 4 | * |
| 4 | 5 | * Taxonomy Options Class |
| 5 | 6 | * |
| @@ -4,275 +5,235 @@ | ||
| 4 | 5 | * Taxonomy Options Class |
| 5 | 6 | * |
| 6 | 7 | * @since 1.0.0 |
| 7 | 8 | * @version 1.0.0 |
| 8 | - * | |
| 9 | 9 | */ |
| 10 | 10 | if ( ! class_exists( 'ADMINIFY_Taxonomy_Options' ) ) { |
| 11 | - class ADMINIFY_Taxonomy_Options extends ADMINIFY_Abstract{ | |
| 11 | + class ADMINIFY_Taxonomy_Options extends ADMINIFY_Abstract { | |
| 12 | 12 | |
| 13 | - // constans | |
| 14 | - public $unique = ''; | |
| 15 | - public $taxonomy = ''; | |
| 16 | - public $abstract = 'taxonomy'; | |
| 17 | - public $sections = array(); | |
| 18 | - public $pre_fields = array(); | |
| 19 | - public $taxonomies = array(); | |
| 20 | - public $args = array( | |
| 21 | - 'taxonomy' => 'category', | |
| 22 | - 'data_type' => 'serialize', | |
| 23 | - 'class' => '', | |
| 24 | - 'enqueue_webfont' => true, | |
| 25 | - 'async_webfont' => false, | |
| 26 | - 'output_css' => true, | |
| 27 | - 'defaults' => array(), | |
| 28 | - ); | |
| 13 | + // constans | |
| 14 | + public $unique = ''; | |
| 15 | + public $taxonomy = ''; | |
| 16 | + public $abstract = 'taxonomy'; | |
| 17 | + public $pre_fields = []; | |
| 18 | + public $sections = []; | |
| 19 | + public $taxonomies = []; | |
| 20 | + public $args = [ | |
| 21 | + 'taxonomy' => 'category', | |
| 22 | + 'data_type' => 'serialize', | |
| 23 | + 'class' => '', | |
| 24 | + 'enqueue_webfont' => true, | |
| 25 | + 'async_webfont' => false, | |
| 26 | + 'output_css' => true, | |
| 27 | + 'defaults' => [], | |
| 28 | + ]; | |
| 29 | 29 | |
| 30 | - // run taxonomy construct | |
| 31 | - public function __construct( $key, $params ) { | |
| 30 | + // run taxonomy construct | |
| 31 | + public function __construct( $key, $params ) { | |
| 32 | + $this->unique = $key; | |
| 33 | + $this->args = apply_filters( "adminify_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this ); | |
| 34 | + $this->sections = apply_filters( "adminify_{$this->unique}_sections", $params['sections'], $this ); | |
| 35 | + $this->taxonomies = ( is_array( $this->args['taxonomy'] ) ) ? $this->args['taxonomy'] : array_filter( (array) $this->args['taxonomy'] ); | |
| 36 | + $this->taxonomy = ( ! empty( $_REQUEST['taxonomy'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['taxonomy'] ) ) : ''; | |
| 37 | + $this->pre_fields = $this->pre_fields( $this->sections ); | |
| 32 | 38 | |
| 33 | - $this->unique = $key; | |
| 34 | - $this->args = apply_filters( "adminify_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this ); | |
| 35 | - $this->sections = apply_filters( "adminify_{$this->unique}_sections", $params['sections'], $this ); | |
| 36 | - $this->taxonomies = ( is_array( $this->args['taxonomy'] ) ) ? $this->args['taxonomy'] : array_filter( (array) $this->args['taxonomy'] ); | |
| 37 | - $this->taxonomy = ( ! empty( $_REQUEST[ 'taxonomy' ] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST[ 'taxonomy' ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check, no state change. | |
| 38 | - $this->pre_fields = $this->pre_fields( $this->sections ); | |
| 39 | + if ( ! empty( $this->taxonomies ) && in_array( $this->taxonomy, $this->taxonomies ) ) { | |
| 40 | + add_action( 'admin_init', [ $this, 'add_taxonomy_options' ] ); | |
| 41 | + } | |
| 39 | 42 | |
| 40 | - if ( ! empty( $this->taxonomies ) && in_array( $this->taxonomy, $this->taxonomies ) ) { | |
| 41 | - add_action( 'admin_init', array( $this, 'add_taxonomy_options' ) ); | |
| 42 | - } | |
| 43 | + // wp enqeueu for typography and output css | |
| 44 | + parent::__construct(); | |
| 45 | + } | |
| 43 | 46 | |
| 44 | - // wp enqeueu for typography and output css | |
| 45 | - parent::__construct(); | |
| 47 | + // instance | |
| 48 | + public static function instance( $key, $params ) { | |
| 49 | + return new self( $key, $params ); | |
| 50 | + } | |
| 46 | 51 | |
| 47 | - } | |
| 52 | + public function pre_fields( $sections ) { | |
| 53 | + $result = []; | |
| 48 | 54 | |
| 49 | - // instance | |
| 50 | - public static function instance( $key, $params ) { | |
| 51 | - return new self( $key, $params ); | |
| 52 | - } | |
| 55 | + foreach ( $sections as $key => $section ) { | |
| 56 | + if ( ! empty( $section['fields'] ) ) { | |
| 57 | + foreach ( $section['fields'] as $field ) { | |
| 58 | + $result[] = $field; | |
| 59 | + } | |
| 60 | + } | |
| 61 | + } | |
| 53 | 62 | |
| 54 | - // add taxonomy add/edit fields | |
| 55 | - public function add_taxonomy_options() { | |
| 63 | + return $result; | |
| 64 | + } | |
| 56 | 65 | |
| 57 | - add_action( $this->taxonomy .'_add_form_fields', array( $this, 'render_taxonomy_form_fields' ) ); | |
| 58 | - add_action( $this->taxonomy .'_edit_form', array( $this, 'render_taxonomy_form_fields' ) ); | |
| 66 | + // add taxonomy add/edit fields | |
| 67 | + public function add_taxonomy_options() { | |
| 68 | + add_action( $this->taxonomy . '_add_form_fields', [ $this, 'render_taxonomy_form_fields' ] ); | |
| 69 | + add_action( $this->taxonomy . '_edit_form', [ $this, 'render_taxonomy_form_fields' ] ); | |
| 59 | 70 | |
| 60 | - add_action( 'created_'. $this->taxonomy, array( $this, 'save_taxonomy' ) ); | |
| 61 | - add_action( 'edited_'. $this->taxonomy, array( $this, 'save_taxonomy' ) ); | |
| 71 | + add_action( 'created_' . $this->taxonomy, [ $this, 'save_taxonomy' ] ); | |
| 72 | + add_action( 'edited_' . $this->taxonomy, [ $this, 'save_taxonomy' ] ); | |
| 73 | + } | |
| 62 | 74 | |
| 63 | - } | |
| 75 | + // get default value | |
| 76 | + public function get_default( $field ) { | |
| 77 | + $default = ( isset( $field['default'] ) ) ? $field['default'] : ''; | |
| 78 | + $default = ( isset( $this->args['defaults'][ $field['id'] ] ) ) ? $this->args['defaults'][ $field['id'] ] : $default; | |
| 64 | 79 | |
| 65 | - // get default value | |
| 66 | - public function get_default( $field ) { | |
| 80 | + return $default; | |
| 81 | + } | |
| 67 | 82 | |
| 68 | - $default = ( isset( $field['default'] ) ) ? $field['default'] : ''; | |
| 69 | - $default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default; | |
| 83 | + // get meta value | |
| 84 | + public function get_meta_value( $field, $term_id = null ) { | |
| 85 | + $value = null; | |
| 70 | 86 | |
| 71 | - return $default; | |
| 87 | + $term_id = ( ! isset( $term_id ) ) ? get_queried_object_id() : $term_id; | |
| 72 | 88 | |
| 73 | - } | |
| 89 | + if ( ! empty( $term_id ) && ! empty( $field['id'] ) ) { | |
| 90 | + if ( $this->args['data_type'] !== 'serialize' ) { | |
| 91 | + $meta = get_term_meta( $term_id, $field['id'] ); | |
| 92 | + $value = ( isset( $meta[0] ) ) ? $meta[0] : null; | |
| 93 | + } else { | |
| 94 | + $meta = get_term_meta( $term_id, $this->unique, true ); | |
| 95 | + $value = ( isset( $meta[ $field['id'] ] ) ) ? $meta[ $field['id'] ] : null; | |
| 96 | + } | |
| 97 | + } | |
| 74 | 98 | |
| 75 | - // get meta value | |
| 76 | - public function get_meta_value( $field, $term_id = null ) { | |
| 99 | + $default = ( isset( $field['id'] ) ) ? $this->get_default( $field ) : ''; | |
| 100 | + $value = ( isset( $value ) ) ? $value : $default; | |
| 77 | 101 | |
| 78 | - $value = null; | |
| 102 | + return $value; | |
| 103 | + } | |
| 79 | 104 | |
| 80 | - $term_id = ( ! isset( $term_id ) ) ? get_queried_object_id() : $term_id; | |
| 105 | + // render taxonomy add/edit form fields | |
| 106 | + public function render_taxonomy_form_fields( $term ) { | |
| 107 | + $is_term = ( is_object( $term ) && isset( $term->taxonomy ) ) ? true : false; | |
| 108 | + $term_id = ( $is_term ) ? $term->term_id : 0; | |
| 109 | + $taxonomy = ( $is_term ) ? $term->taxonomy : $term; | |
| 110 | + $classname = ( $is_term ) ? 'edit' : 'add'; | |
| 111 | + $errors = ( ! empty( $term_id ) ) ? get_term_meta( $term_id, '_adminify_errors_' . $this->unique, true ) : []; | |
| 112 | + $errors = ( ! empty( $errors ) ) ? $errors : []; | |
| 113 | + $class = ( $this->args['class'] ) ? ' ' . $this->args['class'] : ''; | |
| 81 | 114 | |
| 82 | - if ( ! empty( $term_id ) && ! empty( $field['id'] ) ) { | |
| 115 | + if ( ! empty( $errors ) ) { | |
| 116 | + delete_term_meta( $term_id, '_adminify_errors_' . $this->unique ); | |
| 117 | + } | |
| 83 | 118 | |
| 84 | - if ( $this->args['data_type'] !== 'serialize' ) { | |
| 85 | - $meta = get_term_meta( $term_id, $field['id'] ); | |
| 86 | - $value = ( isset( $meta[0] ) ) ? $meta[0] : null; | |
| 87 | - } else { | |
| 88 | - $meta = get_term_meta( $term_id, $this->unique, true ); | |
| 89 | - $value = ( isset( $meta[$field['id']] ) ) ? $meta[$field['id']] : null; | |
| 90 | - } | |
| 119 | + wp_nonce_field( 'adminify_taxonomy_nonce', 'adminify_taxonomy_nonce' . $this->unique ); | |
| 91 | 120 | |
| 92 | - } | |
| 121 | + echo '<div class="adminify adminify-taxonomy adminify-show-all adminify-onload adminify-taxonomy-' . esc_attr( $classname ) . '-fields ' . esc_attr( $class ) . '">'; | |
| 93 | 122 | |
| 94 | - $default = ( isset( $field['id'] ) ) ? $this->get_default( $field ) : ''; | |
| 95 | - $value = ( isset( $value ) ) ? $value : $default; | |
| 123 | + foreach ( $this->sections as $section ) { | |
| 124 | + if ( $taxonomy === $this->taxonomy ) { | |
| 125 | + $section_icon = ( ! empty( $section['icon'] ) ) ? '<i class="adminify-section-icon ' . wp_kses_post( $section['icon'] ) . '"></i>' : ''; | |
| 126 | + $section_title = ( ! empty( $section['title'] ) ) ? $section['title'] : ''; | |
| 96 | 127 | |
| 97 | - return $value; | |
| 128 | + echo ( $section_title || $section_icon ) ? '<div class="adminify-section-title"><h3>' . wp_kses_post( $section_icon . $section_title ) . '</h3></div>' : ''; | |
| 129 | + echo ( ! empty( $section['description'] ) ) ? '<div class="adminify-field adminify-section-description">' . wp_kses_post( $section['description'] ) . '</div>' : ''; | |
| 98 | 130 | |
| 99 | - } | |
| 131 | + if ( ! empty( $section['fields'] ) ) { | |
| 132 | + foreach ( $section['fields'] as $field ) { | |
| 133 | + if ( ! empty( $field['id'] ) && ! empty( $errors['fields'][ $field['id'] ] ) ) { | |
| 134 | + $field['_error'] = $errors['fields'][ $field['id'] ]; | |
| 135 | + } | |
| 100 | 136 | |
| 101 | - // render taxonomy add/edit form fields | |
| 102 | - public function render_taxonomy_form_fields( $term ) { | |
| 137 | + if ( ! empty( $field['id'] ) ) { | |
| 138 | + $field['default'] = $this->get_default( $field ); | |
| 139 | + } | |
| 103 | 140 | |
| 104 | - $is_term = ( is_object( $term ) && isset( $term->taxonomy ) ) ? true : false; | |
| 105 | - $term_id = ( $is_term ) ? $term->term_id : 0; | |
| 106 | - $taxonomy = ( $is_term ) ? $term->taxonomy : $term; | |
| 107 | - $classname = ( $is_term ) ? 'edit' : 'add'; | |
| 108 | - $errors = ( ! empty( $term_id ) ) ? get_term_meta( $term_id, '_adminify_errors_'. $this->unique, true ) : array(); | |
| 109 | - $errors = ( ! empty( $errors ) ) ? $errors : array(); | |
| 110 | - $class = ( $this->args['class'] ) ? ' '. $this->args['class'] : ''; | |
| 141 | + ADMINIFY::field( $field, $this->get_meta_value( $field, $term_id ), $this->unique, 'taxonomy' ); | |
| 142 | + } | |
| 143 | + } | |
| 144 | + } | |
| 145 | + } | |
| 111 | 146 | |
| 112 | - if ( ! empty( $errors ) ) { | |
| 113 | - delete_term_meta( $term_id, '_adminify_errors_'. $this->unique ); | |
| 114 | - } | |
| 147 | + echo '</div>'; | |
| 148 | + } | |
| 115 | 149 | |
| 116 | - wp_nonce_field( 'adminify_taxonomy_nonce', 'adminify_taxonomy_nonce'. $this->unique ); | |
| 150 | + // save taxonomy form fields | |
| 151 | + public function save_taxonomy( $term_id ) { | |
| 152 | + $count = 1; | |
| 153 | + $data = []; | |
| 154 | + $errors = []; | |
| 155 | + $noncekey = 'adminify_taxonomy_nonce' . $this->unique; | |
| 156 | + $nonce = ( ! empty( $_POST[ $noncekey ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ $noncekey ] ) ) : ''; | |
| 157 | + $taxonomy = ( ! empty( $_POST['taxonomy'] ) ) ? sanitize_text_field( wp_unslash( $_POST['taxonomy'] ) ) : ''; | |
| 117 | 158 | |
| 118 | - echo '<div class="adminify adminify-taxonomy adminify-show-all adminify-onload adminify-taxonomy-'. esc_attr( $classname ) .'-fields '. esc_attr( $class ) .'">'; | |
| 159 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! wp_verify_nonce( $nonce, 'adminify_taxonomy_nonce' ) ) { | |
| 160 | + return $term_id; | |
| 161 | + } | |
| 119 | 162 | |
| 120 | - foreach ( $this->sections as $section ) { | |
| 163 | + if ( ! empty( $_POST[ $this->unique ] ) ) { | |
| 164 | + $request = sanitize_text_field( wp_unslash( $_POST[ $this->unique ] ) ); | |
| 165 | + } else { | |
| 166 | + $request = []; | |
| 167 | + } | |
| 121 | 168 | |
| 122 | - if ( $taxonomy === $this->taxonomy ) { | |
| 169 | + if ( ! empty( $request ) ) { | |
| 170 | + foreach ( $this->sections as $section ) { | |
| 171 | + if ( ! empty( $section['fields'] ) ) { | |
| 172 | + foreach ( $section['fields'] as $field ) { | |
| 173 | + if ( ! empty( $field['id'] ) ) { | |
| 174 | + $field_id = $field['id']; | |
| 175 | + $field_value = isset( $request[ $field_id ] ) ? $request[ $field_id ] : ''; | |
| 123 | 176 | |
| 124 | - $section_icon = ( ! empty( $section['icon'] ) ) ? '<i class="adminify-section-icon '. esc_attr( $section['icon'] ) .'"></i>' : ''; | |
| 125 | - $section_title = ( ! empty( $section['title'] ) ) ? $section['title'] : ''; | |
| 177 | + // Sanitize "post" request of field. | |
| 178 | + if ( ! isset( $field['sanitize'] ) ) { | |
| 179 | + if ( is_array( $field_value ) ) { | |
| 180 | + $data[ $field_id ] = wp_kses_post_deep( $field_value ); | |
| 181 | + } else { | |
| 182 | + $data[ $field_id ] = wp_kses_post( $field_value ); | |
| 183 | + } | |
| 184 | + } elseif ( isset( $field['sanitize'] ) && is_callable( $field['sanitize'] ) ) { | |
| 185 | + $data[ $field_id ] = call_user_func( $field['sanitize'], $field_value ); | |
| 186 | + } else { | |
| 187 | + $data[ $field_id ] = $field_value; | |
| 188 | + } | |
| 126 | 189 | |
| 127 | - echo ( $section_title || $section_icon ) ? '<div class="adminify-section-title"><h3>'. wp_kses_post( $section_icon ) . esc_html( $section_title ) .'</h3></div>' : ''; | |
| 128 | - echo ( ! empty( $section['description'] ) ) ? '<div class="adminify-field adminify-section-description">'. wp_kses_post( $section['description'] ) .'</div>' : ''; | |
| 190 | + // Validate "post" request of field. | |
| 191 | + if ( isset( $field['validate'] ) && is_callable( $field['validate'] ) ) { | |
| 192 | + $has_validated = call_user_func( $field['validate'], $field_value ); | |
| 129 | 193 | |
| 130 | - if ( ! empty( $section['fields'] ) ) { | |
| 131 | - foreach ( $section['fields'] as $field ) { | |
| 194 | + if ( ! empty( $has_validated ) ) { | |
| 195 | + $errors['sections'][ $count ] = true; | |
| 196 | + $errors['fields'][ $field_id ] = $has_validated; | |
| 197 | + $data[ $field_id ] = $this->get_meta_value( $field, $term_id ); | |
| 198 | + } | |
| 199 | + } | |
| 200 | + } | |
| 201 | + } | |
| 202 | + } | |
| 132 | 203 | |
| 133 | - if ( ! empty( $field['id'] ) && ! empty( $errors['fields'][$field['id']] ) ) { | |
| 134 | - $field['_error'] = $errors['fields'][$field['id']]; | |
| 135 | - } | |
| 204 | + $count++; | |
| 205 | + } | |
| 206 | + } | |
| 136 | 207 | |
| 137 | - if ( ! empty( $field['id'] ) ) { | |
| 138 | - $field['default'] = $this->get_default( $field ); | |
| 139 | - } | |
| 208 | + $data = apply_filters( "adminify_{$this->unique}_save", $data, $term_id, $this ); | |
| 140 | 209 | |
| 141 | - ADMINIFY::field( $field, $this->get_meta_value( $field, $term_id ), $this->unique, 'taxonomy' ); | |
| 210 | + do_action( "adminify_{$this->unique}_save_before", $data, $term_id, $this ); | |
| 142 | 211 | |
| 143 | - } | |
| 144 | - } | |
| 145 | - } | |
| 212 | + if ( empty( $data ) ) { | |
| 213 | + if ( $this->args['data_type'] !== 'serialize' ) { | |
| 214 | + foreach ( $data as $key => $value ) { | |
| 215 | + delete_term_meta( $term_id, $key ); | |
| 216 | + } | |
| 217 | + } else { | |
| 218 | + delete_term_meta( $term_id, $this->unique ); | |
| 219 | + } | |
| 220 | + } else { | |
| 221 | + if ( $this->args['data_type'] !== 'serialize' ) { | |
| 222 | + foreach ( $data as $key => $value ) { | |
| 223 | + update_term_meta( $term_id, $key, $value ); | |
| 224 | + } | |
| 225 | + } else { | |
| 226 | + update_term_meta( $term_id, $this->unique, $data ); | |
| 227 | + } | |
| 146 | 228 | |
| 147 | - } | |
| 229 | + if ( ! empty( $errors ) ) { | |
| 230 | + update_term_meta( $term_id, '_adminify_errors_' . $this->unique, $errors ); | |
| 231 | + } | |
| 232 | + } | |
| 148 | 233 | |
| 149 | - echo '</div>'; | |
| 234 | + do_action( "adminify_{$this->unique}_saved", $data, $term_id, $this ); | |
| 150 | 235 | |
| 151 | - } | |
| 152 | - | |
| 153 | - // save taxonomy form fields | |
| 154 | - public function save_taxonomy( $term_id ) { | |
| 155 | - | |
| 156 | - $count = 1; | |
| 157 | - $data = array(); | |
| 158 | - $errors = array(); | |
| 159 | - $noncekey = 'adminify_taxonomy_nonce'. $this->unique; | |
| 160 | - $nonce = ( ! empty( $_POST[ $noncekey ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ $noncekey ] ) ) : ''; | |
| 161 | - $taxonomy = ( ! empty( $_POST[ 'taxonomy' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'taxonomy' ] ) ) : ''; | |
| 162 | - | |
| 163 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! wp_verify_nonce( $nonce, 'adminify_taxonomy_nonce' ) ) { | |
| 164 | - return $term_id; | |
| 165 | - } | |
| 166 | - | |
| 167 | - // Authorization: a valid nonce proves intent, not permission. | |
| 168 | - if ( ! current_user_can( 'edit_term', $term_id ) ) { | |
| 169 | - return $term_id; | |
| 170 | - } | |
| 171 | - | |
| 172 | - // XSS ok. | |
| 173 | - // No worries, This "POST" requests is sanitizing in the below foreach. | |
| 174 | - $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. | |
| 175 | - | |
| 176 | - if ( ! empty( $request ) ) { | |
| 177 | - | |
| 178 | - foreach ( $this->sections as $section ) { | |
| 179 | - | |
| 180 | - if ( ! empty( $section['fields'] ) ) { | |
| 181 | - | |
| 182 | - foreach ( $section['fields'] as $field ) { | |
| 183 | - | |
| 184 | - if ( ! empty( $field['id'] ) ) { | |
| 185 | - | |
| 186 | - $field_id = $field['id']; | |
| 187 | - $field_value = isset( $request[$field_id] ) ? $request[$field_id] : ''; | |
| 188 | - | |
| 189 | - // Sanitize "post" request of field. | |
| 190 | - if ( ! isset( $field['sanitize'] ) ) { | |
| 191 | - | |
| 192 | - if( is_array( $field_value ) ) { | |
| 193 | - $data[$field_id] = wp_kses_post_deep( $field_value ); | |
| 194 | - } else { | |
| 195 | - $data[$field_id] = wp_kses_post( $field_value ); | |
| 196 | - } | |
| 197 | - | |
| 198 | - } else if( isset( $field['sanitize'] ) && is_callable( $field['sanitize'] ) ) { | |
| 199 | - | |
| 200 | - $data[$field_id] = call_user_func( $field['sanitize'], $field_value ); | |
| 201 | - | |
| 202 | - } else { | |
| 203 | - | |
| 204 | - // A sanitize callback was declared but is not callable; never store raw input. | |
| 205 | - if ( is_array( $field_value ) ) { | |
| 206 | - $data[$field_id] = wp_kses_post_deep( $field_value ); | |
| 207 | - } else { | |
| 208 | - $data[$field_id] = wp_kses_post( $field_value ); | |
| 209 | - } | |
| 210 | - | |
| 211 | - } | |
| 212 | - | |
| 213 | - // Validate "post" request of field. | |
| 214 | - if ( isset( $field['validate'] ) && is_callable( $field['validate'] ) ) { | |
| 215 | - | |
| 216 | - $has_validated = call_user_func( $field['validate'], $field_value ); | |
| 217 | - | |
| 218 | - if ( ! empty( $has_validated ) ) { | |
| 219 | - | |
| 220 | - $errors['sections'][$count] = true; | |
| 221 | - $errors['fields'][$field_id] = $has_validated; | |
| 222 | - $data[$field_id] = $this->get_meta_value( $field, $term_id ); | |
| 223 | - | |
| 224 | - } | |
| 225 | - | |
| 226 | - } | |
| 227 | - | |
| 228 | - } | |
| 229 | - | |
| 230 | - } | |
| 231 | - | |
| 232 | - } | |
| 233 | - | |
| 234 | - $count++; | |
| 235 | - | |
| 236 | - } | |
| 237 | - | |
| 238 | - } | |
| 239 | - | |
| 240 | - $data = apply_filters( "adminify_{$this->unique}_save", $data, $term_id, $this ); | |
| 241 | - | |
| 242 | - do_action( "adminify_{$this->unique}_save_before", $data, $term_id, $this ); | |
| 243 | - | |
| 244 | - if ( empty( $data ) ) { | |
| 245 | - | |
| 246 | - if ( $this->args['data_type'] !== 'serialize' ) { | |
| 247 | - foreach ( $this->pre_fields as $field ) { | |
| 248 | - if ( ! empty( $field['id'] ) ) { | |
| 249 | - delete_term_meta( $term_id, $field['id'] ); | |
| 250 | - } | |
| 251 | - } | |
| 252 | - } else { | |
| 253 | - delete_term_meta( $term_id, $this->unique ); | |
| 254 | - } | |
| 255 | - | |
| 256 | - } else { | |
| 257 | - | |
| 258 | - if ( $this->args['data_type'] !== 'serialize' ) { | |
| 259 | - foreach ( $data as $key => $value ) { | |
| 260 | - update_term_meta( $term_id, $key, $value ); | |
| 261 | - } | |
| 262 | - } else { | |
| 263 | - update_term_meta( $term_id, $this->unique, $data ); | |
| 264 | - } | |
| 265 | - | |
| 266 | - if ( ! empty( $errors ) ) { | |
| 267 | - update_term_meta( $term_id, '_adminify_errors_'. $this->unique, $errors ); | |
| 268 | - } | |
| 269 | - | |
| 270 | - } | |
| 271 | - | |
| 272 | - do_action( "adminify_{$this->unique}_saved", $data, $term_id, $this ); | |
| 273 | - | |
| 274 | - do_action( "adminify_{$this->unique}_save_after", $data, $term_id, $this ); | |
| 275 | - | |
| 276 | - } | |
| 277 | - } | |
| 236 | + do_action( "adminify_{$this->unique}_save_after", $data, $term_id, $this ); | |
| 237 | + } | |
| 238 | + } | |
| 278 | 239 | } |