se { return is_array( $default ) ? $default : array(); } $selected = array(); foreach ( $raw as $v ) { $k = trim( (string) $v ); if ( $k !== '' ) { $selected[] = $k; } } $selected = array_values( array_unique( $selected ) ); if ( $allowed ) { $allowed_set = array_fill_keys( array_map( 'strval', $allowed ), true ); $out = array(); foreach ( $allowed as $k ) { $k = (string) $k; if ( isset( $allowed_set[ $k ] ) && in_array( $k, $selected, true ) ) { $out[] = $k; } } $selected = $out; } if ( $multiple > 0 && count( $selected ) > $multiple ) { $selected = array_slice( $selected, 0, $multiple ); } return $selected; } $value = (string) $value; if ( is_array( $choices ) && array_key_exists( $value, $choices ) ) { return $value; } return is_string( $default ) ? $default : ''; } if ( $type === 'radio-buttonset' || $type === 'radio-image' ) { $choices = $field['choices'] ?? array(); $value = (string) $value; if ( is_array( $choices ) && array_key_exists( $value, $choices ) ) { return $value; } return is_string( $default ) ? $default : ''; } if ( $type === 'multicheck' ) { $choices = $field['choices'] ?? array(); $allowed = is_array( $choices ) ? array_keys( $choices ) : array(); $raw = array(); if ( is_array( $value ) ) { $raw = $value; } elseif ( is_string( $value ) ) { $raw = array_filter( array_map( 'trim', explode( ',', $value ) ) ); } else { return is_array( $default ) ? $default : array(); } $selected = array(); foreach ( $raw as $v ) { $k = sanitize_key( (string) $v ); if ( $k !== '' ) { $selected[] = $k; } } $selected = array_values( array_unique( $selected ) ); if ( $allowed ) { $set = array_fill_keys( $selected, true ); $out = array(); foreach ( $allowed as $k ) { $k = sanitize_key( (string) $k ); if ( isset( $set[ $k ] ) ) { $out[] = $k; } } return $out; } return $selected; } if ( $type === 'color' ) { $value = trim( (string) $value ); if ( $value === '' ) { return ''; } if ( sanitize_hex_color( $value ) ) { return $value; } if ( preg_match( '/^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(,\s*(0|1|0?\.\d+)\s*)?\)$/', $value ) ) { return $value; } return is_string( $default ) ? $default : ''; } if ( $type === 'image' ) { if ( $value === '' || $value === null ) { return ''; } if ( is_array( $value ) ) { return array( 'id' => isset( $value['id'] ) ? absint( $value['id'] ) : 0, 'url' => isset( $value['url'] ) ? esc_url_raw( (string) $value['url'] ) : '', ); } return esc_url_raw( (string) $value ); } if ( $type === 'upload' ) { if ( $value === '' || $value === null ) { return ''; } if ( is_array( $value ) ) { return isset( $value['url'] ) ? esc_url_raw( (string) $value['url'] ) : ''; } return esc_url_raw( (string) $value ); } if ( $type === 'textarea' || $type === 'etheme-textarea' ) { return sanitize_textarea_field( (string) $value ); } if ( $type === 'editor' ) { return wp_kses_post( (string) $value ); } if ( $type === 'code' ) { return wp_strip_all_tags( (string) $value ); } if ( $type === 'background' ) { if ( ! is_array( $value ) ) { return is_array( $default ) ? $default : array(); } return array( 'background-color' => isset( $value['background-color'] ) ? sanitize_text_field( (string) $value['background-color'] ) : '', 'background-image' => isset( $value['background-image'] ) ? esc_url_raw( (string) $value['background-image'] ) : '', 'background-repeat' => isset( $value['background-repeat'] ) ? sanitize_text_field( (string) $value['background-repeat'] ) : '', 'background-position' => isset( $value['background-position'] ) ? sanitize_text_field( (string) $value['background-position'] ) : '', 'background-size' => isset( $value['background-size'] ) ? sanitize_text_field( (string) $value['background-size'] ) : '', 'background-attachment' => isset( $value['background-attachment'] ) ? sanitize_text_field( (string) $value['background-attachment'] ) : '', ); } if ( $type === 'typography' && class_exists( 'Kirki_Field_Typography' ) && method_exists( 'Kirki_Field_Typography', 'sanitize' ) ) { $out = Kirki_Field_Typography::sanitize( $value ); if ( is_array( $out ) && array_key_exists( 'letter-spacing', $out ) ) { $ls = $out['letter-spacing']; if ( is_string( $ls ) ) { $ls = trim( $ls ); } if ( is_numeric( $ls ) && (float) $ls !== 0.0 ) { $out['letter-spacing'] = (string) $ls . 'px'; } } return $out; } if ( $type === 'dimensions' || $type === 'multicolor' || $type === 'typography' ) { if ( ! is_array( $value ) ) { return is_array( $default ) ? $default : array(); } $out = array(); foreach ( $value as $k => $v ) { $k = sanitize_key( (string) $k ); if ( is_string( $v ) ) { $out[ $k ] = sanitize_text_field( $v ); } else { $out[ $k ] = $v; } } return $out; } if ( $type === 'sortable' ) { $choices = $field['choices'] ?? array(); if ( ! is_array( $value ) ) { return is_array( $default ) ? $default : array(); } $out = array(); foreach ( $value as $v ) { $v = sanitize_key( (string) $v ); if ( is_array( $choices ) && ! array_key_exists( $v, $choices ) ) { continue; } $out[] = $v; } return array_values( array_unique( $out ) ); } if ( $type === 'repeater' ) { if ( ! is_array( $value ) ) { return is_array( $default ) ? $default : array(); } $out = array(); foreach ( $value as $row ) { if ( ! is_array( $row ) ) { continue; } $clean = array(); foreach ( $row as $k => $v ) { $k = sanitize_key( (string) $k ); if ( is_string( $v ) ) { $clean[ $k ] = sanitize_text_field( $v ); } elseif ( is_bool( $v ) ) { $clean[ $k ] = $v; } elseif ( is_numeric( $v ) ) { $clean[ $k ] = 0 + $v; } else { $clean[ $k ] = $v; } } $out[] = $clean; } return $out; } if ( is_array( $value ) ) { $sanitize = static function ( $v ) use ( &$sanitize ) { if ( is_array( $v ) ) { $out = array(); foreach ( $v as $k => $vv ) { $out[ $k ] = $sanitize( $vv ); } return $out; } if ( is_string( $v ) ) { return sanitize_text_field( $v ); } if ( is_bool( $v ) ) { return $v; } if ( is_numeric( $v ) ) { return 0 + $v; } return $v; }; return $sanitize( $value ); } return sanitize_text_field( (string) $value ); } } XStore_Options_Admin::init();