Make WordPress Core

Opened 14 months ago

Last modified 4 months ago

#44825 new defect (bug)

get_rest_url does not respect query args added to get_home_url

Reported by: distinct Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: REST API Keywords: reporter-feedback
Focuses: Cc:
PR Number:



This line appends the rest $path to the result of get_home_url, which can be modified by any plugin to have query arguments.

An easy way to fix it is to just append the $path to the parameter to get_home_url itself

//line 315 and further
if ( $wp_rewrite->using_index_permalinks() ) {
  $url = get_home_url( $blog_id, $wp_rewrite->index . '/' . rest_get_url_prefix() . $path, $scheme );
} else {
  $url = get_home_url( $blog_id, rest_get_url_prefix() . $path, $scheme );

Hope this helps.

Change History (4)

#1 @SergeyBiryukov
14 months ago

  • Component changed from General to REST API

#2 @pento
9 months ago

  • Version trunk deleted

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.

4 months ago

#4 @TimothyBlynJacobs
4 months ago

  • Keywords reporter-feedback added

@distinct could you expand a bit more on your use case? Does your home URL always have query parameters in order for your website to load at all?

My initial thoughts are that particular query params on the home URL shouldn't be added to the REST API as well. There is also a high chance of conflicting with the various REST API collection params.

Note: See TracTickets for help on using tickets.