
最常见的WordPress函数
rest_handle_multi_type_schema ( $value, $args, $param = '' )
rest_handle_multi_type_schema: 这个函数用来处理一个允许多种类型的模式。它接受两个参数,第一个是允许多种类型的模式,第二个是代表正在验证的数据类型的字符串。如果根据模式不允许数据类型,它返回一个错误数组。
处理为多类型模式获取最佳类型的问题。
这是{@see}的一个封装器,用于处理使用无效类型的模式的后向兼容性。
function rest_handle_multi_type_schema( $value, $args, $param = '' ) { $allowed_types = array( 'array', 'object', 'string', 'number', 'integer', 'boolean', 'null' ); $invalid_types = array_diff( $args['type'], $allowed_types ); if ( $invalid_types ) { _doing_it_wrong( __FUNCTION__, /* translators: 1: Parameter, 2: List of allowed types. */ wp_sprintf( __( 'The "type" schema keyword for %1$s can only contain the built-in types: %2$l.' ), $param, $allowed_types ), '5.5.0' ); } $best_type = rest_get_best_type_for_value( $value, $args['type'] ); if ( ! $best_type ) { if ( ! $invalid_types ) { return ''; } // Backward compatibility for previous behavior which allowed the value if there was an invalid type used. $best_type = reset( $invalid_types ); } return $best_type; }