Opened 8 years ago
Closed 8 years ago
#37177 closed defect (bug) (wontfix)
Incorrect rest_url when home_url contains parameters
Reported by: | danielbachhuber | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | REST API | Keywords: | |
Focuses: | Cc: |
Description
Problem
When the WordPress home_url
contains a parameter, the URL returned by get_rest_url()
is wrong.
Example home_url: "http://example.com/?lang=en"
Expected rest url: "http://example.com/wp-json/wp/v2/posts?lang=en"
Actual rest url: "http://example.com/wp-json?lang=en/wp/v2/posts"
Solution
The path has to be passed to get_home_url
in its full form, not extended afterwards.
In get_rest_url()
:
$url = get_home_url( $blog_id, rest_get_url_prefix(), $scheme ); $url .= '/' . ltrim( $path, '/' );
has to be replaced with:
$path = rtrim( rest_get_url_prefix(), '/' ) . '/' . ltrim( $path, '/' ); $url = get_home_url( $blog_id, $path, $scheme );
Change History (1)
Note: See
TracTickets for help on using
tickets.
Actually, this appears to be a problem generally with
get_home_url()
since r12598:Specifically:
I think supporting query parameters in
home
opens a huge can of worms, and shouldn't be supported by WordPress. There are other ways of accomplishing the same effect.