rest_validate_integer_value_from_schema

函式
rest_validate_integer_value_from_schema ( $value, $args, $param )
引數
  • (mixed) $value The value to validate.
    Required:
  • (array) $args Schema array to use for validation.
    Required:
  • (string) $param The parameter name, used in error messages.
    Required:
返回值
  • (true|WP_Error)
定義位置
相關方法
rest_validate_string_value_from_schemarest_validate_number_value_from_schemarest_validate_value_from_schemarest_validate_null_value_from_schemarest_validate_array_value_from_schema
引入
5.7.0
棄用
-

rest_validate_integer_value_from_schema: 這是一個WordPress函式,用於驗證一個整數值是否與模式相匹配: 該函式接受一個整數引數和一個模式引數,如果整數值與模式不匹配,則返回一個錯誤資訊。

根據模式驗證一個整數值。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function rest_validate_integer_value_from_schema( $value, $args, $param ) {
$is_valid_number = rest_validate_number_value_from_schema( $value, $args, $param );
if ( is_wp_error( $is_valid_number ) ) {
return $is_valid_number;
}
if ( ! rest_is_integer( $value ) ) {
return new WP_Error(
'rest_invalid_type',
/* translators: 1: Parameter, 2: Type name. */
sprintf( __( '%1$s is not of type %2$s.' ), $param, 'integer' ),
array( 'param' => $param )
);
}
return true;
}
function rest_validate_integer_value_from_schema( $value, $args, $param ) { $is_valid_number = rest_validate_number_value_from_schema( $value, $args, $param ); if ( is_wp_error( $is_valid_number ) ) { return $is_valid_number; } if ( ! rest_is_integer( $value ) ) { return new WP_Error( 'rest_invalid_type', /* translators: 1: Parameter, 2: Type name. */ sprintf( __( '%1$s is not of type %2$s.' ), $param, 'integer' ), array( 'param' => $param ) ); } return true; }
function rest_validate_integer_value_from_schema( $value, $args, $param ) {
	$is_valid_number = rest_validate_number_value_from_schema( $value, $args, $param );
	if ( is_wp_error( $is_valid_number ) ) {
		return $is_valid_number;
	}

	if ( ! rest_is_integer( $value ) ) {
		return new WP_Error(
			'rest_invalid_type',
			/* translators: 1: Parameter, 2: Type name. */
			sprintf( __( '%1$s is not of type %2$s.' ), $param, 'integer' ),
			array( 'param' => $param )
		);
	}

	return true;
}

常見問題

FAQs
檢視更多 >