rest_validate_null_value_from_schema

函式
rest_validate_null_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_number_value_from_schemarest_validate_string_value_from_schemarest_validate_array_value_from_schemarest_validate_boolean_value_from_schema
引入
5.7.0
棄用
-

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

根據schema驗證一個空值。

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

	return true;
}

常見問題

FAQs
檢視更多 >