Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST API: Add support for pretty printing REST API responses. #3229

Closed
wants to merge 5 commits into from

Conversation

TimothyBJacobs
Copy link
Member

Trac ticket: https://core.trac.wordpress.org/ticket/41998


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

* @return int The JSON encode options.
*/
protected function get_json_encode_options( WP_REST_Request $request ) {
$options = defined( 'REST_JSON_ENCODE_OPTIONS' ) ? REST_JSON_ENCODE_OPTIONS : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimothyBJacobs What are your thoughts on the advantages of this over the WP_DEBUG_REST_API constant proposed in the original trac ticket?

If I am following this, to define that I want my site to JSON pretty print, I'd use this, correct?:

define( 'REST_JSON_ENCODE_OPTIONS', JSON_PRETTY_PRINT );

I don't know that I have a strong opinion on this, and admit that WP_DEBUG_REST_API achieves a little developer-facing consistency but also possibly over-implies what you're getting in exchange for setting the constant. I'd almost expect that if I say "I'm debugging the REST API" that I'd start getting telemetry or something along with my request response, which would definitely not be the case here.

Naming things is hard. I'd love a second opinion :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am following this, to define that I want my site to JSON pretty print, I'd use this, correct?:

Yep, that's correct!

Yeah, I think "debug" implies more features than we have, and isn't as clear that it is enabling "pretty print". But this let's us be very clear in what the constant supports and leaves us open to future expansion.

@kadamwhite
Copy link
Contributor

Committed in bb20a18

@kadamwhite kadamwhite closed this Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants