babble icon indicating copy to clipboard operation
babble copied to clipboard

Add WP REST API support

Open markoheijnen opened this issue 10 years ago • 1 comments

It would be awesome to build in support for the upcoming API in WordPress. The fix of PR #182 is a start of it.

markoheijnen avatar Aug 10 '14 16:08 markoheijnen

I recently resolved this with the following:

/**
 * Prevent Babble from interfering with REST API requests
 */
function babble_wp_json_compat( $rules ) {
	global $wp_rewrite;

	// From rest_api_register_rewrites()
	$rest_rules = array(
		'^' . rest_get_url_prefix() . '/?$',
		'^' . rest_get_url_prefix() . '/(.*)?',
		'^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/?$',
		'^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/(.*)?',
	);

	return array_merge( $rules, $rest_rules );
}
add_filter( 'bbl_non_translated_queries', 'babble_wp_json_compat' );

It assumes that translated REST routes aren't needed, but it's sufficient for my need (for the moment).

ethitter avatar Apr 19 '17 20:04 ethitter