You appear to be a bot. Output may be restricted
Description
Usage
WPCOM_JSON_API::filter_fields( $response );
Parameters
- $response
- ( mixed ) required –
Returns
void
Source
File name: jetpack/class.json-api.php
Lines:
1 to 63 of 63
function filter_fields( $response ) { if ( empty( $this->query['fields'] ) || ( is_array( $response ) && ! empty( $response['error'] ) ) || ! empty( $this->endpoint->custom_fields_filtering ) ) { return $response; } $fields = array_map( 'trim', explode( ',', $this->query['fields'] ) ); if ( is_object( $response ) ) { $response = (array) $response; } $has_filtered = false; if ( is_array( $response ) && empty( $response['ID'] ) ) { $keys_to_filter = array( 'categories', 'comments', 'connections', 'domains', 'groups', 'likes', 'media', 'notes', 'posts', 'services', 'sites', 'suggestions', 'tags', 'themes', 'topics', 'users', ); foreach ( $keys_to_filter as $key_to_filter ) { if ( ! isset( $response[ $key_to_filter ] ) || $has_filtered ) { continue; } foreach ( $response[ $key_to_filter ] as $key => $values ) { if ( is_object( $values ) ) { if ( is_object( $response[ $key_to_filter ] ) ) { $response[ $key_to_filter ]->$key = (object) array_intersect_key( ( (array) $values ), array_flip( $fields ) ); } elseif ( is_array( $response[ $key_to_filter ] ) ) { $response[ $key_to_filter ][ $key ] = (object) array_intersect_key( ( (array) $values ), array_flip( $fields ) ); } } elseif ( is_array( $values ) ) { $response[ $key_to_filter ][ $key ] = array_intersect_key( $values, array_flip( $fields ) ); } } $has_filtered = true; } } if ( ! $has_filtered ) { if ( is_object( $response ) ) { $response = (object) array_intersect_key( (array) $response, array_flip( $fields ) ); } elseif ( is_array( $response ) ) { $response = array_intersect_key( $response, array_flip( $fields ) ); } } return $response; }