Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow customization of the API resources prefix. #244

Closed
wants to merge 1 commit into from

3 participants

@rachelbaker
Owner

Related to #104.

@rmccue #reviewmerge

@rachelbaker rachelbaker added this to the 1.1 milestone
@rmccue rmccue was assigned by rachelbaker
plugin.php
@@ -353,6 +353,14 @@ function json_cookie_collect_status() {
add_action( 'auth_cookie_valid', 'json_cookie_collect_status' );
/**
+ * Get the URL prefix for any API resource.
+ *
+ * @return string Prefix.
+ */
+function get_json_url_prefix() {
@rmccue Owner
rmccue added a note

This should be json_get_url_prefix instead, please :)

Sure thing, changed in ea482a8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rmccue rmccue added the Enhancement label
@rmccue
Owner

In future, please don't force-push or rebase/squash; history is important! :)

Thanks for this, will test locally and merge.

@rmccue rmccue added Review and removed Has Patch labels
@rachelbaker rachelbaker closed this in #278
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 3 deletions.
  1. +12 −3 plugin.php
View
15 plugin.php
@@ -46,8 +46,8 @@ function json_api_init() {
add_action( 'init', 'json_api_init' );
function json_api_register_rewrites() {
- add_rewrite_rule( '^wp-json/?$','index.php?json_route=/','top' );
- add_rewrite_rule( '^wp-json(.*)?','index.php?json_route=$matches[1]','top' );
+ add_rewrite_rule( '^' . json_get_url_prefix() . '/?$','index.php?json_route=/','top' );
+ add_rewrite_rule( '^' . json_get_url_prefix() . '(.*)?','index.php?json_route=$matches[1]','top' );
}
/**
@@ -353,6 +353,15 @@ function json_cookie_collect_status() {
add_action( 'auth_cookie_valid', 'json_cookie_collect_status' );
/**
+ * Get the URL prefix for any API resource.
+ *
+ * @return string Prefix.
+ */
+function json_get_url_prefix() {
+ return apply_filters( 'json_url_prefix', 'wp-json' );
+}
+
+/**
* Get URL to a JSON endpoint on a site
*
* @todo Check if this is even necessary
@@ -363,7 +372,7 @@ function json_cookie_collect_status() {
*/
function get_json_url( $blog_id = null, $path = '', $scheme = 'json' ) {
if ( get_option( 'permalink_structure' ) ) {
- $url = get_home_url( $blog_id, 'wp-json', $scheme );
+ $url = get_home_url( $blog_id, json_get_url_prefix(), $scheme );
if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
$url .= '/' . ltrim( $path, '/' );
Something went wrong with that request. Please try again.