WP_REST_Server::get_json_encode_options( WP_REST_Request $request ): int

Gets the encoding options passed to wp_json_encode.

Parameters

$requestWP_REST_Requestrequired
The current request object.

Return

int The JSON encode options.

Source

protected function get_json_encode_options( WP_REST_Request $request ) {
	$options = 0;

	if ( $request->has_param( '_pretty' ) ) {
		$options |= JSON_PRETTY_PRINT;
	}

	/**
	 * Filters the JSON encoding options used to send the REST API response.
	 *
	 * @since 6.1.0
	 *
	 * @param int $options             JSON encoding options json_encode().
	 * @param WP_REST_Request $request Current request object.
	 */
	return apply_filters( 'rest_json_encode_options', $options, $request );
}

Hooks

apply_filters( ‘rest_json_encode_options’, int $options, WP_REST_Request $request )

Filters the JSON encoding options used to send the REST API response.

Changelog

VersionDescription
6.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.