Changeset 55104 for trunk/src/wp-includes/rest-api.php
- Timestamp:
- 01/20/2023 12:19:09 AM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r54997 r55104 2935 2935 * Support the "anyOf" and "oneOf" keywords. 2936 2936 * 2937 * @param array|object $ dataThe response data to modify.2938 * @param array $schema The schema for the endpoint used to filter the response.2939 * @param string $context The requested context.2937 * @param array|object $response_data The response data to modify. 2938 * @param array $schema The schema for the endpoint used to filter the response. 2939 * @param string $context The requested context. 2940 2940 * @return array|object The filtered response data. 2941 2941 */ 2942 function rest_filter_response_by_context( $ data, $schema, $context ) {2942 function rest_filter_response_by_context( $response_data, $schema, $context ) { 2943 2943 if ( isset( $schema['anyOf'] ) ) { 2944 $matching_schema = rest_find_any_matching_schema( $ data, $schema, '' );2944 $matching_schema = rest_find_any_matching_schema( $response_data, $schema, '' ); 2945 2945 if ( ! is_wp_error( $matching_schema ) ) { 2946 2946 if ( ! isset( $schema['type'] ) ) { … … 2948 2948 } 2949 2949 2950 $ data = rest_filter_response_by_context( $data, $matching_schema, $context );2950 $response_data = rest_filter_response_by_context( $response_data, $matching_schema, $context ); 2951 2951 } 2952 2952 } 2953 2953 2954 2954 if ( isset( $schema['oneOf'] ) ) { 2955 $matching_schema = rest_find_one_matching_schema( $ data, $schema, '', true );2955 $matching_schema = rest_find_one_matching_schema( $response_data, $schema, '', true ); 2956 2956 if ( ! is_wp_error( $matching_schema ) ) { 2957 2957 if ( ! isset( $schema['type'] ) ) { … … 2959 2959 } 2960 2960 2961 $ data = rest_filter_response_by_context( $data, $matching_schema, $context );2962 } 2963 } 2964 2965 if ( ! is_array( $ data ) && ! is_object( $data ) ) {2966 return $ data;2961 $response_data = rest_filter_response_by_context( $response_data, $matching_schema, $context ); 2962 } 2963 } 2964 2965 if ( ! is_array( $response_data ) && ! is_object( $response_data ) ) { 2966 return $response_data; 2967 2967 } 2968 2968 … … 2972 2972 $type = 'object'; // Back compat if a developer accidentally omitted the type. 2973 2973 } else { 2974 return $ data;2974 return $response_data; 2975 2975 } 2976 2976 … … 2979 2979 2980 2980 if ( $is_array_type && $is_object_type ) { 2981 if ( rest_is_array( $ data ) ) {2981 if ( rest_is_array( $response_data ) ) { 2982 2982 $is_object_type = false; 2983 2983 } else { … … 2988 2988 $has_additional_properties = $is_object_type && isset( $schema['additionalProperties'] ) && is_array( $schema['additionalProperties'] ); 2989 2989 2990 foreach ( $ data as $key => $value ) {2990 foreach ( $response_data as $key => $value ) { 2991 2991 $check = array(); 2992 2992 … … 3013 3013 if ( $is_array_type ) { 3014 3014 // All array items share schema, so there's no need to check each one. 3015 $ data = array();3015 $response_data = array(); 3016 3016 break; 3017 3017 } 3018 3018 3019 if ( is_object( $ data ) ) {3020 unset( $ data->$key );3019 if ( is_object( $response_data ) ) { 3020 unset( $response_data->$key ); 3021 3021 } else { 3022 unset( $ data[ $key ] );3022 unset( $response_data[ $key ] ); 3023 3023 } 3024 3024 } elseif ( is_array( $value ) || is_object( $value ) ) { 3025 3025 $new_value = rest_filter_response_by_context( $value, $check, $context ); 3026 3026 3027 if ( is_object( $ data ) ) {3028 $ data->$key = $new_value;3027 if ( is_object( $response_data ) ) { 3028 $response_data->$key = $new_value; 3029 3029 } else { 3030 $ data[ $key ] = $new_value;3031 } 3032 } 3033 } 3034 3035 return $ data;3030 $response_data[ $key ] = $new_value; 3031 } 3032 } 3033 } 3034 3035 return $response_data; 3036 3036 } 3037 3037
Note: See TracChangeset
for help on using the changeset viewer.