GC_Customize_Setting::validate()

最后更新于:2021-11-27 08:46:07

GC_Customize_Setting::validate( mixed$value)

Validates an input.

参数

$value

(mixed) (Required) Value to validate.

响应

(true|GC_Error) True if the input was validated, otherwise GC_Error.

源文件

文件: gc-includes/class-gc-customize-setting.php

	public function validate( $value ) {
		if ( is_gc_error( $value ) ) {
			return $value;
		}
		if ( is_null( $value ) ) {
			return new GC_Error( 'invalid_value', __( 'Invalid value.' ) );
		}

		$validity = new GC_Error();

		/**
		 * Validates a Customize setting value.
		 *
		 * Plugins should amend the `$validity` object via its `GC_Error::add()` method.
		 *
		 * The dynamic portion of the hook name, `$this->ID`, refers to the setting ID.
		 *
		 * @since 4.6.0
		 *
		 * @param GC_Error             $validity Filtered from `true` to `GC_Error` when invalid.
		 * @param mixed                $value    Value of the setting.
		 * @param GC_Customize_Setting $setting  GC_Customize_Setting instance.
		 */
		$validity = apply_filters( "customize_validate_{$this->id}", $validity, $value, $this );

		if ( is_gc_error( $validity ) && ! $validity->has_errors() ) {
			$validity = true;
		}
		return $validity;
	}