rest_validate_boolean_value_from_schema

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

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

根據模式驗證一個布林值。

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

	return true;
}

常見問題

FAQs
檢視更多 >