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

Commit

Permalink
If pretty permalinks are disabled, use query URL
Browse files Browse the repository at this point in the history
  • Loading branch information
rmccue committed Apr 15, 2014
1 parent 36f3f13 commit faf4754
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,24 @@ function json_output_link_header() {
* @return string Full URL to the endpoint
*/
function get_json_url( $blog_id = null, $path = '', $scheme = 'json' ) {
$url = get_home_url( $blog_id, 'wp-json', $scheme );
if ( get_option( 'permalink_structure' ) ) {
$url = get_home_url( $blog_id, 'wp-json', $scheme );

if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
$url .= '/' . ltrim( $path, '/' );
if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
$url .= '/' . ltrim( $path, '/' );
}
else {
$url = trailingslashit( get_home_url( $blog_id, '', $scheme ) );

if ( empty( $path ) ) {
$path = '/';
}
else {
$path = '/' . ltrim( $path, '/' );
}

$url = add_query_arg( 'json_route', $path, $url );
}

return apply_filters( 'json_url', $url, $path, $blog_id );
}
Expand Down

1 comment on commit faf4754

@rachelbaker
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rmccue During testing this patch still did not allow the JSON routes to respond without pretty permalinks enabled. This needs more debugging/testing.

Please sign in to comment.