[wp-trac] [WordPress Trac] #28523: wp_send_json to allow for JSONP
WordPress Trac
noreply at wordpress.org
Fri Jun 13 03:20:53 UTC 2014
#28523: wp_send_json to allow for JSONP
-------------------------+------------------------------
Reporter: sc0ttkclark | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 3.5
Severity: normal | Resolution:
Keywords: | Focuses:
-------------------------+------------------------------
Comment (by rmccue):
Replying to [comment:2 sc0ttkclark]:
> So it seems to me, that as the new WP API is on track for eventual merge
into core, this would help simplify at least a small fraction of it's
inclusion.
FWIW, since `wp_send_json` also exits (that is, calls `exit`/`die`), it's
not suitable for use in the API. The API is explicitly designed to be re-
entrant, and as such, there's only a single use of `exit` in the plugin.
The use of `exit` is also separated from the JSON handling, so we couldn't
do a simple refactor to change this.
That said, a common function to check callbacks would be nice. Here's the
code we have at the moment:
{{{
$jsonp_enabled = apply_filters( 'json_jsonp_enabled', true );
if ( isset( $_GET['_jsonp'] ) ) {
if ( ! $jsonp_enabled ) {
echo $this->json_error( 'json_callback_disabled', __(
'JSONP support is disabled on this site.' ), 400 );
return false;
}
// Check for invalid characters (only alphanumeric allowed)
if ( preg_match( '/\W/', $_GET['_jsonp'] ) ) {
echo $this->json_error( 'json_callback_invalid', __( 'The
JSONP callback function is invalid.' ), 400 );
return false;
}
}
// ...
if ( isset( $_GET['_jsonp'] ) ) {
echo $_GET['_jsonp'] . '(' . $result . ')';
} else {
echo $result;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28523#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list