[wp-trac] [WordPress Trac] #37177: Incorrect rest_url when home_url contains parameters

WordPress Trac noreply at wordpress.org
Sun Jun 26 11:10:08 UTC 2016


#37177: Incorrect rest_url when home_url contains parameters
-----------------------------+------------------------------------------
 Reporter:  danielbachhuber  |      Owner:
     Type:  defect (bug)     |     Status:  new
 Priority:  normal           |  Milestone:  4.6
Component:  REST API         |    Version:  4.4
 Severity:  normal           |   Keywords:  needs-patch needs-unit-tests
  Focuses:                   |
-----------------------------+------------------------------------------
 **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 );
 }}}

 Originally https://github.com/WP-API/WP-API/issues/2514

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37177>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list