Recursive sanitize a given values.

@param  mixed  $values    The values.
@param  string $sanitizer The sanitizer callback.
@return mixed
770743
public static function sanitize_recursive( $values, $sanitizer ) {
		if ( ! is_array( $values ) ) {
			return is_scalar( $values ) ? $sanitizer( $values ) : $values;
		}

		foreach ( $values as $key => $value ) {
			if ( is_array( $value ) ) {
				$values[ $key ] = static::sanitize_recursive( $value, $sanitizer );
			} else {
				$values[ $key ] = is_scalar( $value ) ? $sanitizer( $value ) : $value;
			}
		}

		return $values;
	}
513520
public function sanitize($value)
    {
        if ($value instanceof Traversable) {
            return $this->sanitize(iterator_to_array($value));
        } elseif (is_array($value)) {
            return array_map([$this, 'sanitize'], $value);
        } elseif (is_object($value)) {
            return $this->sanitizeObject($value);
        } elseif (is_resource($value)) {
            return get_resource_type($value);
        }

        return $value;
    }
823011
protected function sanitizeValue($input, Sanitize $sanitize = null)
    {
        if (!isset($sanitize)) {
            $sanitize = $this->sanitize ?: Sanitize::removeTags()->trim()->toType();
        }

        if (is_array($input)) {
            $rawRule = $sanitize->getRawRules();
            $rawRule = current($rawRule);
            if ($rawRule instanceof Attributes) {
                return $sanitize->sanitize($input);
            }
            return Sanitize::attributes($sanitize)->sanitize($input);
        }

        return $sanitize->sanitize($input);
    }
872609
protected function sanitizeMoney($value, $key = null)
    {
        $value = $this->checkValue($value, $key);

        return $value == null ? $value : number_format($value, 2, '.', '');
    }
1060720
public function sanitize_callback() {
		return function( $value ) {
			if ( ! is_array( $value ) ) {
				$value = explode( ',', $value );
			}

			$sanitized_values = [];

			foreach ( $value as $v ) {
				if ( ! array_key_exists( $v, $this->args['choices'] ) ) {
					continue;
				}
				$sanitized_values[] = $v;
			}

			$sanitized_values = array_map( 'sanitize_text_field', $sanitized_values );
			return implode( ',', $sanitized_values );
		};
	}
102479
protected function apply_sanitize_callback( $output, $value ) {
		if ( isset( $output['sanitize_callback'] ) && null !== $output['sanitize_callback'] ) {

			// If the sanitize_callback is invalid, return the value.
			if ( ! is_callable( $output['sanitize_callback'] ) ) {
				return $value;
			}
			return call_user_func( $output['sanitize_callback'], $this->value );
		}
		return $value;
	}
493324
protected function _sanitize($value)
    {
        $value = (string) $value;

        // Filter var for XSS and other 'bad' code etc.
        if (!empty($value)) {
            $value = $this->_remove($this->_decode($value));
        }

        return $value;
    }
300235
public function sanitizeQuery($queries)
    {
        $cleanQueries = array();

        if ( ! is_array($queries)) {
            return $cleanQueries;
        }

        foreach ($queries as $key => $query) {
            if ('relation' === $key) {
                $relation = $query;

            } elseif ( ! is_array($query)) {
                continue;

                // First-order clause.
            } elseif ($this->isFirstOrderClause($query)) {
                if (isset($query[ 'value' ]) && array() === $query[ 'value' ]) {
                    unset($query[ 'value' ]);
                }

                $cleanQueries[ $key ] = $query;

                // Otherwise, it's a nested query, so we recurse.
            } else {
                $cleanedQuery = $this->sanitizeQuery($query);

                if ( ! empty($cleanedQuery)) {
                    $cleanQueries[ $key ] = $cleanedQuery;
                }
            }
        }

        if (empty($cleanQueries)) {
            return $cleanQueries;
        }

        // Sanitize the 'relation' key provided in the query.
        if (isset($relation) && 'OR' === strtoupper($relation)) {
            $cleanQueries[ 'relation' ] = 'OR';

            // Default to AND.
        } else {
            $cleanQueries[ 'relation' ] = 'AND';
        }

        return $cleanQueries;
    }
425455
public function multiple($value)
    {
        $value = $this->sanitise($value);

        switch (substr($value, -1)) {
            case '*':
            case '+':
                break;
            default:
                $value .= '+';
        }

        return $this->add($value);
    }
835204
protected function buildRow(array $columns, $sanitize = true)
    {
        if ($sanitize) {
            $columns = $this->sanitizeColumns($columns);
        }

        $row = join($this->delimiter, $columns) . $this->newline;

        $row = $this->convertEncoding($row);

        return $row;
    }
828143
private function sanitizeOptions(array $options)
    {
        $resolver = new OptionsResolver();
        $resolver->setDefault('axis', 'x');
        $resolver->setAllowedValues('axis', ['x', 'horizontal', 'y', 'vertical']);
        $resolver->setNormalizer('axis', function (Options $options, $value) {
            return 'horizontal' === $value ? 'x' : ('vertical' === $value ? 'y' : $value);
        });

        try {
            return $resolver->resolve($options);
        } catch (ExceptionInterface $e) {
            throw new InvalidArgumentException('The "axis" option must be set to "x", "horizontal", "y", or "vertical".');
        }
    }
130425
public function sanitize($data)
    {
        if ($this->hasGlobals()) {
            if (! is_array($data)) {
                return $this->sanitizeValueFor(static::GLOBAL_KEY, $data);
            }

            foreach ($data as $key => $value) {
                $data[$key] = $this->sanitizeValueFor(static::GLOBAL_KEY, $value);
            }
        }

        foreach ($data as $key => $value) {
            if (! $this->shouldSanitize($key)) {
                continue;
            }

            $data[$key] = $this->sanitizeValueFor($key, $value);
        }

        return $data;
    }
915134
public function sanitize()
    {
        if (!$this->_sanitized) {
            foreach (array_keys($this->_vars) as $key) {
                $this->$key = $this->filter($key);
            }
            $this->_sanitized = true;
        }
    }
346795
protected function _sanitize($value)
    {
        $value      = trim(strtolower($value));
        $pattern    = '/[^a-f0-9]*/';
        return substr(preg_replace($pattern, '', $value), 0, 32);
    }
712785
public static function sanitize( $value ) {

		// Sanitize each sub-value separately.
		foreach ( $value as $key => $sub_value ) {
			$value[ $key ] = sanitize_text_field( $sub_value );
		}
		return $value;
	}
367287
public function sanitizeSetting($value)
    {
        $keys = $this->repository()->getSettings()->collapse()->map(function ($setting) {
            /** @var FieldTypeInterface $setting */
            return $setting->getName();
        });

        $settingName = $keys->slice($this->offset, 1)->first();
        $lastSetting = $this->repository()->getSettings()->collapse()->last();
        $data = collect($_POST);

        if ($this->offset > $keys->count() - 1) {
            if (empty($value)) {
                return '';
            }

            // Sanitize is called one more time with a valid value.
            // Let's get the $settingName based on the given value
            // as we can't rely anymore on the offset.
            $settingName = $data->search($value, true);

            if (! $settingName) {
                return '';
            }

            // Let's add a "fake" error to avoid duplicate success messages.
            $this->errors++;
        }

        $setting = $this->repository()->getSettingByName($settingName);

        $validator = $this->validator->make(
            $data->all(),
            [$setting->getName() => $setting->getOption('rules')],
            $this->getSettingMessages($setting),
            $this->getSettingPlaceholder($setting)
        );

        // Update setting offset.
        $this->offset++;

        /** @var Validator $validator */
        if ($validator->fails()) {
            $this->errors++;

            add_settings_error(
                $this->getSlug(),
                $setting->getName(),
                $validator->getMessageBag()->first($setting->getName()),
                'error'
            );

            return '';
        }

        if ($settingName === $lastSetting->getName() && ! $this->errors) {
            add_settings_error(
                $this->getSlug(),
                'settings_updated',
                __('Settings saved.'),
                'updated'
            );
        }

        return $value;
    }
985683
protected function _sanitize($value)
    {
        $string = htmlentities(utf8_decode($value));
        $string = preg_replace(
            array('/&szlig;/','/&(..)lig;/', '/&([aouAOU])uml;/','/&(.)[^;]*;/'),
            array('ss',"$1","$1".'e',"$1"),
            $string
        );

        return $string;
    }