Automattic / babble

Multilingual WordPress done right.
https://wordpress.org/plugins/babble/
245 stars 50 forks source link

Add WP REST API support #184

Open markoheijnen opened 9 years ago

markoheijnen commented 9 years ago

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

ethitter commented 7 years ago

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).