Merge pull request #22204 from woocommerce/fix/22201
Restore empty schema support for register_rest_field
This commit is contained in:
commit
89740f9583
|
@ -203,10 +203,12 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
$_item = new WP_REST_Request( 'DELETE' );
|
||||
$_item->set_query_params( array(
|
||||
'id' => $id,
|
||||
'force' => true,
|
||||
) );
|
||||
$_item->set_query_params(
|
||||
array(
|
||||
'id' => $id,
|
||||
'force' => true,
|
||||
)
|
||||
);
|
||||
$_response = $this->delete_item( $_item );
|
||||
|
||||
if ( is_wp_error( $_response ) ) {
|
||||
|
@ -350,7 +352,8 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function validate_setting_textarea_field( $value, $setting ) {
|
||||
$value = is_null( $value ) ? '' : $value;
|
||||
return wp_kses( trim( stripslashes( $value ) ),
|
||||
return wp_kses(
|
||||
trim( stripslashes( $value ) ),
|
||||
array_merge(
|
||||
array(
|
||||
'iframe' => array(
|
||||
|
@ -436,6 +439,16 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
|
|||
public function get_fields_for_response( $request ) {
|
||||
$schema = $this->get_item_schema();
|
||||
$fields = isset( $schema['properties'] ) ? array_keys( $schema['properties'] ) : array();
|
||||
|
||||
$additional_fields = $this->get_additional_fields();
|
||||
foreach ( $additional_fields as $field_name => $field_options ) {
|
||||
// For back-compat, include any field with an empty schema
|
||||
// because it won't be present in $this->get_item_schema().
|
||||
if ( is_null( $field_options['schema'] ) ) {
|
||||
$fields[] = $field_name;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! isset( $request['_fields'] ) ) {
|
||||
return $fields;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue