Skip to content
This repository has been archived by the owner on Sep 24, 2018. It is now read-only.

Commit

Permalink
Allow customization of the API resources prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericandrewlewis committed May 29, 2014
1 parent 4c90e3b commit ea482a8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions plugin.php
Expand Up @@ -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' );
}

/**
Expand Down Expand Up @@ -352,6 +352,15 @@ function json_cookie_collect_status() {
add_action( 'auth_cookie_bad_hash', '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
*
Expand All @@ -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, '/' );
Expand Down

0 comments on commit ea482a8

Please sign in to comment.