/home/techb158/public_html/wp-content/plugins/kirki/libraries/framework
NameSizeModeActions
Collections/-0755rm
Concerns/-0755rm
Console/-0755rm
Constants/-0755rm
Contracts/-0755rm
Database/-0755rm
Discovery/-0755rm
Exceptions/-0755rm
Filesystem/-0755rm
Http/-0755rm
Managers/-0755rm
Middlewares/-0755rm
Polyfill/-0755rm
Routing/-0755rm
Supports/-0755rm
Validation/-0755rm
View/-0755rm
Wordpress/-0755rm
ApiExceptionHandler.php21270644editdlrm
Application.php244380644editdlrm
Container.php128850644editdlrm
CoreServiceProvider.php41020644editdlrm
DTO.php85050644editdlrm
Facade.php28060644editdlrm
helpers.php216790644editdlrm
Listener.php8330644editdlrm
Resource.php68760644editdlrm
Route.php522610644editdlrm
Sanitizer.php102900644editdlrm
ServiceProvider.php10570644editdlrm
SiteExceptionHandler.php20760644editdlrm
Edit: /home/techb158/public_html/wp-content/plugins/kirki/libraries/framework/Sanitizer.php (10290B)
* * @since 1.0.0 */ protected $data; /** * Sanitized data. * * @var array * * @since 1.0.0 */ protected $sanitized_data = []; /** * Sanitization rules. * * @var array * * @since 1.0.0 */ protected $rules; /** * Create a new Sanitizer instance. * * @param array $data The data payload. * @param array $rules The rules. * * @return void * * @since 1.0.0 */ public function __construct(array $data = [], array $rules = []) { $this->data = $data; $this->rules = $rules; $this->run_sanitizer(); } /** * Get the sanitized data. * * @return array * * @since 1.0.0 */ public function get_sanitized_data() { return $this->sanitized_data; } /** * Sanitize the data. * * @param array $data The data payload. * @param array $rules The rules. * * @return static * * @since 1.0.0 */ public static function make(array $data = [], array $rules = []) { return new static($data, $rules); } /** * Run sanitizer * * @return void * * @since 1.0.0 */ protected function run_sanitizer() { foreach ($this->rules as $key => $rule) { $key_segments = \explode('.', $key); $this->traverse_and_sanitize($this->data, $key_segments, [], $rule); } } /** * Recursively traverses the input data structure according to a dot-notated rule key, * handling wildcard segments (e.g., *) to apply sanitization rules at dynamic levels. * * @param mixed $current_data The current level of data being inspected. This is a portion * @param array $key_segments The remaining parts (split by '.') of the rule key that * @param array $traversed_path_stack The stack of key_segments already traversed so far. This is used * @param string $rule A sanitization rule to apply on the current data. * * @return void * * @since 1.0.0 */ protected function traverse_and_sanitize($current_data, $key_segments, $traversed_path_stack, $rule) { // when all segments have been traversed if (empty($key_segments)) { $this->set_sanitized_data($traversed_path_stack, static::apply_rule($current_data, $rule, $this->data)); return; } $segment = \array_shift($key_segments); if ($segment === '*') { if (!\is_array($current_data)) { $this->set_sanitized_data($traversed_path_stack, static::apply_rule($current_data, static::ARRAY, $this->data)); return; } foreach ($current_data as $index => $item) { $this->traverse_and_sanitize($item, $key_segments, \array_merge($traversed_path_stack, [$index]), $rule); } } elseif (\is_array($current_data) && \array_key_exists($segment, $current_data)) { $this->traverse_and_sanitize($current_data[$segment], $key_segments, \array_merge($traversed_path_stack, [$segment]), $rule); } } /** * Set the sanitized data using a series of keys to traverse the nested array structure. * * @param array $keys An array of keys representing the path in the nested array structure. * @param mixed $value The value to set at the specified path in the sanitized data array. * * @return void * * @since 1.0.0 */ protected function set_sanitized_data($keys, $value) { $ref =& $this->sanitized_data; foreach ($keys as $key) { if (!isset($ref[$key])) { $ref[$key] = []; } $ref =& $ref[$key]; } $ref = $value; } /** * Apply sanitization. * * @param mixed $value The value. * @param mixed $type The type. * @param array $data The data payload. * * @return mixed * * @since 1.0.0 */ public static function apply_rule($value, $type, array $data = []) { // For the null values, we don't need to sanitize them. if (\is_null($value)) { return null; } if ($type === null) { return $value; } switch ($type) { case static::ANY: return $value; case static::TRIM: $value = \trim($value); break; case static::TEXT: $value = sanitize_text_field($value); break; case static::RICH_TEXT: $value = wp_kses_post($value); break; case static::TEXTAREA: $value = sanitize_textarea_field($value); break; case static::EMAIL: $value = sanitize_email($value); break; case static::USERNAME: $value = sanitize_user($value); break; case static::URL: $value = sanitize_url($value); break; case static::KEY: $value = sanitize_key($value); break; case static::TITLE: $value = sanitize_title($value); break; case static::FILE_NAME: $value = sanitize_file_name($value); break; case static::MIME_TYPE: $value = sanitize_mime_type($value); break; case static::INT: $value = (int) $value; break; case static::FLOAT: case static::DOUBLE: $value = (float) $value; break; case static::BOOL: $value = rest_sanitize_boolean($value); break; case static::ARRAY: if (\is_array($value)) { break; } if (empty($value)) { return null; } if (is_valid_json($value)) { $value = \json_decode($value, \true); break; } return null; case static::DATE: if (!Date::is_valid_date($value)) { return null; } $value = Date::parse($value)->start_of_day(); break; case static::DATETIME: if (!Date::is_valid_date($value)) { return null; } $value = Date::parse($value); break; case static::SERIALIZED: $value = maybe_serialize($value); break; case static::UNSERIALIZED: if (!is_serialized($value)) { break; } $value = \unserialize(\trim($value), ['allowed_classes' => \false]); break; default: if (\is_callable($type)) { $value = $type($value, $data); } break; } return $value; } }