WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_Customize_Manager::validate_setting_values() WP 4.6.0

Validates setting values.

Validation is skipped for unregistered settings or for values that are already null since they will be skipped anyway. Sanitization is applied to values that pass validation, and values that become null or WP_Error after sanitizing are marked invalid.

Это метод класса: WP_Customize_Manager

Хуки из метода
Возвращает

Массив. Mapping of setting IDs to return value of validate method calls, either true or WP_Error.

Использование

$WP_Customize_Manager = new WP_Customize_Manager();
$var = $WP_Customize_Manager->validate_setting_values( $setting_values, $options );
$setting_values(массив) (обязательный)
Mapping of setting IDs to values to validate and sanitize.
$options(массив)

Options.

  • $validate_existence (true/false)
    Whether a setting's existence will be checked.

  • $validate_capability (true/false)
    Whether the setting capability will be checked.

По умолчанию: array()

Заметки

  • Смотрите: WP_REST_Request::has_valid_params()
  • Смотрите: WP_Customize_Setting::validate()

Список изменений

С версии 4.6.0 Введена.

Код WP Customize Manager::validate setting values: wp-includes/class-wp-customize-manager.php WP 5.3.2

<?php
public function validate_setting_values( $setting_values, $options = array() ) {
	$options = wp_parse_args(
		$options,
		array(
			'validate_capability' => false,
			'validate_existence'  => false,
		)
	);

	$validities = array();
	foreach ( $setting_values as $setting_id => $unsanitized_value ) {
		$setting = $this->get_setting( $setting_id );
		if ( ! $setting ) {
			if ( $options['validate_existence'] ) {
				$validities[ $setting_id ] = new WP_Error( 'unrecognized', __( 'Setting does not exist or is unrecognized.' ) );
			}
			continue;
		}
		if ( $options['validate_capability'] && ! current_user_can( $setting->capability ) ) {
			$validity = new WP_Error( 'unauthorized', __( 'Unauthorized to modify setting due to capability.' ) );
		} else {
			if ( is_null( $unsanitized_value ) ) {
				continue;
			}
			$validity = $setting->validate( $unsanitized_value );
		}
		if ( ! is_wp_error( $validity ) ) {
			/** This filter is documented in wp-includes/class-wp-customize-setting.php */
			$late_validity = apply_filters( "customize_validate_{$setting->id}", new WP_Error(), $unsanitized_value, $setting );
			if ( is_wp_error( $late_validity ) && $late_validity->has_errors() ) {
				$validity = $late_validity;
			}
		}
		if ( ! is_wp_error( $validity ) ) {
			$value = $setting->sanitize( $unsanitized_value );
			if ( is_null( $value ) ) {
				$validity = false;
			} elseif ( is_wp_error( $value ) ) {
				$validity = $value;
			}
		}
		if ( false === $validity ) {
			$validity = new WP_Error( 'invalid_value', __( 'Invalid value.' ) );
		}
		$validities[ $setting_id ] = $validity;
	}
	return $validities;
}