{"action":"opened","issue":{"url":"https://api.github.com/repos/WP-API/WP-API/issues/2514","repository_url":"https://api.github.com/repos/WP-API/WP-API","labels_url":"https://api.github.com/repos/WP-API/WP-API/issues/2514/labels{/name}","comments_url":"https://api.github.com/repos/WP-API/WP-API/issues/2514/comments","events_url":"https://api.github.com/repos/WP-API/WP-API/issues/2514/events","html_url":"https://github.com/WP-API/WP-API/issues/2514","id":156949735,"number":2514,"title":"Wrong rest_url when home_url contains parameters","user":{"login":"eteubert","id":235918,"avatar_url":"https://avatars.githubusercontent.com/u/235918?v=3","gravatar_id":"","url":"https://api.github.com/users/eteubert","html_url":"https://github.com/eteubert","followers_url":"https://api.github.com/users/eteubert/followers","following_url":"https://api.github.com/users/eteubert/following{/other_user}","gists_url":"https://api.github.com/users/eteubert/gists{/gist_id}","starred_url":"https://api.github.com/users/eteubert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eteubert/subscriptions","organizations_url":"https://api.github.com/users/eteubert/orgs","repos_url":"https://api.github.com/users/eteubert/repos","events_url":"https://api.github.com/users/eteubert/events{/privacy}","received_events_url":"https://api.github.com/users/eteubert/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-26T10:10:41Z","updated_at":"2016-05-26T10:10:41Z","closed_at":null,"body":"The issue is in the implementation of [WP-API/api-core function get_rest_url](https://github.com/WP-API/api-core/blob/fba8637a3e56b82c8684ce8f1f11031bf39e1afe/wp-includes/rest-api.php#L210). The repository documentation says that I should not create issues/PR here, so I will outline the problem and solution here.\r\n\r\n--- \r\n\r\n**Problem**\r\n\r\nWhen the WordPress `home_url` contains a parameter, the URL returned by `get_rest_url()` is wrong.\r\n\r\nExample home_url: \"http://example.com/?lang=en\"\r\nExpected rest url: \"http://example.com/wp-json/wp/v2/posts?lang=en\"\r\nActual rest url: \"http://example.com/wp-json?lang=en/wp/v2/posts\"\r\n\r\n**Solution**\r\n\r\nThe path has to be passed to `get_home_url` in its full form, not extended afterwards.\r\n\r\nIn `get_rest_url()`:\r\n\r\n```php\r\n$url = get_home_url( $blog_id, rest_get_url_prefix(), $scheme );\r\n$url .= '/' . ltrim( $path, '/' );\r\n```\r\n\r\nhas to be replaced with:\r\n\r\n```php\r\n$path = rtrim( rest_get_url_prefix(), '/' ) . '/' . ltrim( $path, '/' );\r\n$url = get_home_url( $blog_id, $path, $scheme );\r\n```"}}
{"actor":{"display_login":"eteubert"}}