[wp-trac] [WordPress Trac] #58255: wp_send_json_error should respect error state passed in WP_Error.
WordPress Trac
noreply at wordpress.org
Fri May 19 07:55:28 UTC 2023
#58255: wp_send_json_error should respect error state passed in WP_Error.
----------------------------+------------------------------
Reporter: spacedmonkey | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Administration | Version:
Severity: normal | Resolution:
Keywords: good-first-bug | Focuses:
----------------------------+------------------------------
Comment (by rohitmathur7):
I looked into this and this is my analysis:
Problem:
If we pass WP_Error as an argument in the wp_send_json_error() then the
status code set in the WP_Error is not set as the status code in the
wp_send_json_error().
Approach:
I am using this way to pass the WP_Error in the wp_send_json_error():
{{{
$error_message = 'new error';
$error = new WP_Error( 'error_code', $error_message, array(
'status' => 401 ) );
return wp_send_json_error( $error );
}}}
After applying changes to the code I was able to get this response:
[https://drive.google.com/file/d/13HzEMQufbSzdqlQonLPXCGeultzW8bGy/view?usp=sharing]
If this works I can provide the patch for this.
Please correct me if I am going in the wrong direction with this.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58255#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list