[wp-trac] [WordPress Trac] #34399: WP API 1.2 endpoints don't work with latest WP core master
WordPress Trac
noreply at wordpress.org
Fri Oct 23 02:17:24 UTC 2015
#34399: WP API 1.2 endpoints don't work with latest WP core master
--------------------------+------------------------------
Reporter: mnelson4 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by mnelson4):
Adding this chunk of code to the WP API 1.2 also resolved the issue
(basically if the rest api in core doesn't handle the request, it lets WP
API 1.2 take a stab at it. It's pretty hacky):
{{{
add_filter( 'rest_pre_serve_request', 'serve_request_instead_of_core_api',
10, 4 );
function serve_request_instead_of_core_api( $handled, WP_HTTP_Response
$rest_response, WP_REST_Request $request, WP_REST_Server $rest_server ) {
if( $rest_response->get_status() == 404 ) {
/**
* Whether this is a XML-RPC Request.
*
* @var bool
* @todo Remove me in favour of JSON_REQUEST
*/
define( 'XMLRPC_REQUEST', true );
/**
* Whether this is a JSON Request.
*
* @var bool
*/
define( 'JSON_REQUEST', true );
global $wp_json_server;
// Allow for a plugin to insert a different class to
handle requests.
$wp_json_server_class = apply_filters(
'wp_json_server_class', 'WP_JSON_Server' );
$wp_json_server = new $wp_json_server_class;
/**
* Fires when preparing to serve an API request.
*
* Endpoint objects should be created and register their
hooks on this
* action rather than another action to ensure they're
only loaded when
* needed.
*
* @param WP_JSON_ResponseHandler $wp_json_server Response
handler object.
*/
do_action( 'wp_json_server_before_serve', $wp_json_server
);
// Fire off the request.
$wp_json_server->serve_request(
$GLOBALS['wp']->query_vars['rest_route'] );
return true;
} else {
return false;
}
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34399#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list