$prepared['instance'
]['encoded'
] =
base64_encode( $serialized_instance );
$prepared['instance'
]['hash'
] =
wp_hash( $serialized_instance );
if ( !
empty( $widget_object->widget_options
['show_instance_in_rest'
] ) ) { // Use new stdClass so that JSON result is {} and not [].
$prepared['instance'
]['raw'
] =
empty( $instance ) ?
new stdClass() :
$instance;
} } } $context = !
empty( $request['context'
] ) ?
$request['context'
] : 'view';
$prepared =
$this->
add_additional_fields_to_object( $prepared,
$request );
$prepared =
$this->
filter_response_by_context( $prepared,
$context );
$response =
rest_ensure_response( $prepared );
if ( rest_is_field_included( '_links',
$fields ) ||
rest_is_field_included( '_embedded',
$fields ) ) { $response->
add_links( $this->
prepare_links( $prepared ) );
} /**
* Filters the REST API response for a widget.
*
* @since 5.8.0
*
* @param WP_REST_Response|WP_Error $response The response object, or WP_Error object on failure.
* @param array $widget The registered widget data.
* @param WP_REST_Request $request Request used to generate the response.
*/