From 4e1000b53d05d9a5042d298652559bb481043850 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sat, 26 Mar 2016 19:31:24 -0500 Subject: [PATCH] Prepare for new WP-API URLs --- index.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 1742808..cc27af5 100644 --- a/index.js +++ b/index.js @@ -25,11 +25,6 @@ var proxyOrigin = 'https://public-api.wordpress.com'; var defaultApiVersion = '1'; -/** - * WP-API Namespaces - */ -var wpApiNamespaces = ['wp']; - /** * Performs an XMLHttpRequest against the WordPress.com REST API. * @@ -59,8 +54,12 @@ function request (params, fn) { var basePath = '/rest/v' + apiVersion; - // if this is a wp-api request, adjust basePath - if ( apiNamespace && wpApiNamespaces.indexOf( apiNamespace ) !== -1 ) { + // If this is a WP-API request, adjust basePath + if ( apiNamespace && /\//.test( apiNamespace ) ) { + // New-style WP-API URL: /wpcom/v2/sites/%s/post-counts + basePath = '/' + apiNamespace; + } else if ( apiNamespace ) { + // Old-style WP-API URL (deprecated): /wp-json/sites/%s/wpcom/v2/post-counts basePath = '/wp-json'; }