Making WordPress.org

Ticket #1459: meta-1459.3.patch

File meta-1459.3.patch, 1.0 KB (added by prettyboymp, 9 years ago)

Proposal to automatically whitelist any registered namespaces to wp-api v2

  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/wcorg-json-api.php

     
    346346 * @param WP $request
    347347 */
    348348function wcorg_json_v2_compat( $request ) {
    349         $v2_routes = array(
    350                 '/wp-json/wordcamp-qbo',
    351                 '/wp-json/wordcamp-letsencrypt',
    352         );
    353349
    354         if ( strpos( $_SERVER['REQUEST_URI'], '/wp-json' ) !== 0 ) {
     350        $rest_prefix = rest_get_url_prefix();
     351
     352        if ( strpos( $_SERVER[ 'REQUEST_URI' ], "/$rest_prefix" ) !== 0 ) {
    355353                return;
    356354        }
    357355
    358356        $is_route_v2 = false;
    359         foreach ( $v2_routes as $route ) {
    360                 if ( strpos( $_SERVER['REQUEST_URI'], $route ) === 0 ) {
     357        foreach ( rest_get_server()->get_namespaces() as $namespace ) {
     358                if ( strpos( $_SERVER[ 'REQUEST_URI' ], "/$rest_prefix/$namespace" ) === 0 ) {
    361359                        $is_route_v2 = true;
    362360                        break;
    363361                }