WordPress.org

Make WordPress Core

Opened 7 weeks ago

Closed 10 days ago

Last modified 8 days ago

#51293 closed feature request (fixed)

Add $option Parameter to wp_send_json, wp_send_json_success and wp_send_json_error

Reported by: eroraghav Owned by: SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version: 5.5.1
Component: General Keywords: has-patch commit needs-dev-note
Focuses: Cc:

Description

I mostly use wp_send_json function(s) as they work perfectly with wp.ajax.post and wp.ajax.send functions. But there was one problem that i was not able to use JSON Constants (FLAGS ) https://www.php.net/manual/en/json.constants.php
So i made an edit to add this option parameter that will be used to add JSON Constant.

$option is Optional. Options to be passed to json_encode(). Default 0.

Attachments (2)

51293.diff (2.1 KB) - added by Hareesh Pillai 2 weeks ago.
Refreshed the patch against trunk. Also, changed the $option parameter in the PR to $options to maintain consistency with wp_json_encode.
51293.2.diff (2.1 KB) - added by garrett-eclipse 13 days ago.
Refresh to address CS alignment of @param descriptions.

Download all attachments as: .zip

Change History (10)

This ticket was mentioned in PR #528 on WordPress/wordpress-develop by Ero-Raghav.


7 weeks ago

  • Keywords has-patch added; needs-refresh removed

I mostly use wp_send_json function(s) as they work perfectly with wp.ajax.post and wp.ajax.send functions. But there was one problem that i was not able to use [JSON Constants (FLAGS )] (https://www.php.net/manual/en/json.constants.php).
So i made an edit to add this option parameter that will be used to add JSON Constant.

$option is Optional. Options to be passed to json_encode(). Default 0.

[Ticket] (https://core.trac.wordpress.org/ticket/51293)

This ticket was mentioned in Slack in #accessibility by afercia. View the logs.


6 weeks ago

#3 @afercia
6 weeks ago

  • Focuses accessibility removed

Removing the accessibility focus as this issue doesn't seem related to web content accessibility.

#4 @SergeyBiryukov
5 weeks ago

  • Keywords 2nd-opinion removed
  • Milestone changed from Awaiting Review to 5.6
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

Hi there, welcome to WordPress Trac! Thanks for the ticket and the PR.

Since wp_json_encode() already has the $options parameter, I agree that being able to utilize it in these functions seems like a useful addition.

@Hareesh Pillai
2 weeks ago

Refreshed the patch against trunk. Also, changed the $option parameter in the PR to $options to maintain consistency with wp_json_encode.

@garrett-eclipse
13 days ago

Refresh to address CS alignment of @param descriptions.

#5 @garrett-eclipse
13 days ago

  • Keywords commit added

Thanks for the ticket & patch @eroraghav, and refresh @hareesh-pillai. Testing it looks good to me, applies clean and all existing tests run nicely. I did make one minor change in 51293.2.diff to fix the CS issue with the @param descriptions as they should all aligned off of the longest param.

@SergeyBiryukov would you care to give it a review/test, I wasn't sure if the change warranted unit tests?

#6 @SergeyBiryukov
10 days ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 49235:

General: Add $options parameter to JSON response functions:

  • wp_send_json()
  • wp_send_json_success()
  • wp_send_json_error()

This allows for customizing the options passed to json_encode().

Props eroraghav, hareesh-pillai, garrett-eclipse.
Fixes #51293.

#7 @davidbaumwald
10 days ago

  • Keywords needs-dev-note added

Marking for a small call-out on the Misc Dev Note for the new parameter added in 5.6.

Last edited 10 days ago by davidbaumwald (previous) (diff)
Note: See TracTickets for help on using tickets.