WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#29435 closed enhancement (invalid)

wp_send_json() & co. should support json_encode()'s optional arguments

Reported by: Viper007Bond Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9.2
Component: Gallery Keywords: has-patch close
Focuses: Cc:

Description

For debugging, I want my wp_send_json_success() call to output pretty, human readable JSON. You can do this by passing JSON_PRETTY_PRINT as the second parameter to json_encode().

wp_send_json() and the higher level functions that call it should support these optional arguments.

Attachments (4)

29435.patch (2.5 KB) - added by Viper007Bond 6 years ago.
29435.2.patch (2.6 KB) - added by adamsilverstein 6 years ago.
Add 'Optional.' before description in docblock as per doc standards
29435.3.patch (2.6 KB) - added by Viper007Bond 6 years ago.
More doc fixes
29435.4.patch (2.4 KB) - added by adamsilverstein 6 years ago.
refresh against trunk

Download all attachments as: .zip

Change History (14)

@Viper007Bond
6 years ago

#1 @adamsilverstein
6 years ago

This seems like a useful addition, thanks!

@adamsilverstein
6 years ago

Add 'Optional.' before description in docblock as per doc standards

#2 @adamsilverstein
6 years ago

In 29435.2.patch:

Added 'Optional.' before description of new variables in docblocks as per doc standards.

#3 @Viper007Bond
6 years ago

Thanks but oops, I noticed I also had the wrong var ($data) in the docblock for wp_send_json(). I copied them off some other functions.

Fixed patch incoming.

Last edited 6 years ago by Viper007Bond (previous) (diff)

@Viper007Bond
6 years ago

More doc fixes

#4 follow-up: @Viper007Bond
6 years ago

Also added Optional. to the $data descriptions.

#5 in reply to: ↑ 4 @adamsilverstein
6 years ago

Makes sense, just send status without any returned data.

Replying to Viper007Bond:

Also added Optional. to the $data descriptions.

@adamsilverstein
6 years ago

refresh against trunk

#6 @adamsilverstein
6 years ago

  • Keywords dev-feedback added

29435.4.patch refresh against trunk

#7 follow-up: @nacin
6 years ago

  • Keywords close added; dev-feedback removed

To be honest, this doesn't seem like something I find particularly necessary. It adds unnecessary complexity to a dead-simple utility function.

At most, we could pass JSON_PRETTY_PRINT when WP_DEBUG. But I'd be more inclined to just suggest a change in your debugging in such a way that your browser handles this for you — and better than just whitespace. In Chrome, there's a popular extension for turning JSON into a collapsable tree. Viewing an XHR request in the inspector also gives you a full preview that is, again, an expandable tree.

#8 in reply to: ↑ 7 @adamsilverstein
6 years ago

Replying to nacin:

To be honest, this doesn't seem like something I find particularly necessary. It adds unnecessary complexity to a dead-simple utility function.

At most, we could pass JSON_PRETTY_PRINT when WP_DEBUG. But I'd be more inclined to just suggest a change in your debugging in such a way that your browser handles this for you — and better than just whitespace. In Chrome, there's a popular extension for turning JSON into a collapsable tree. Viewing an XHR request in the inspector also gives you a full preview that is, again, an expandable tree.

Makes sense to me, especially for debugging - and agree it adds unnecessary complexity. Wondering if any of the other predefined constants would be useful?

#9 @johnbillion
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

See #30139, #28786, and r30055.

#10 @Viper007Bond
6 years ago

I didn't even think to use a browser addon that prettifies and renders the JSON for me. Works like a charm. Thanks. :)

Note: See TracTickets for help on using tickets.