[wp-trac] [WordPress Trac] #45933: WSODs protection returns incorrect content type for JSON Requests

WordPress Trac noreply at wordpress.org
Thu Jan 17 22:01:52 UTC 2019


#45933: WSODs protection returns incorrect content type for JSON Requests
--------------------------------------------------+------------------------
 Reporter:  spacedmonkey                          |       Owner:  flixos90
     Type:  defect (bug)                          |      Status:  reviewing
 Priority:  normal                                |   Milestone:  5.1
Component:  Bootstrap/Load                        |     Version:  trunk
 Severity:  normal                                |  Resolution:
 Keywords:  servehappy needs-patch needs-testing  |     Focuses:  multisite
--------------------------------------------------+------------------------

Comment (by flixos90):

 I agree it makes sense to output the JSON data in accordance with how the
 REST API does it. However, note that `wp_is_json_request()` is in no way
 actually related to the REST API.

 More importantly though, let's separate preparing the data passed to the
 function from actually outputting them. The individual handlers are
 responsible for the output - `_wp_die_process_input()` should, like its
 name already states, be responsible for processing the input, not
 processing it for output. That function is part of the "`wp_die()` API"
 (if it can be called that), so its behavior should be in line with the
 other related functions, which mean consisting of `$message`, `$title`,
 and `$args`. `$args` should consist of the existing "response",
 "back_link", "link_url", "link_text", plus the new "code". It makes sense
 to just pass through the three `wp_die()` parameters like that for easily
 understanding that this function simply prepares arguments.

 The individual handlers can then use this data in any way they like, for
 example the JSON handler would need to output the following:
 {{{
 list( $message, $title, $args ) = _wp_die_process_input( $message, $title,
 $args );

 wp_json_encode(
     array(
         'code'    => $args['code'],
         'message' => $message,
         'data'    => array(
             'status' => $args['response'],
         ),
     )
 );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45933#comment:32>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list