REST API: Support sites with index-style permalinks in get_rest_url().

Support the index-style permalinks (http://example.com/index.php/postName) when registering the REST API rewrite rules and within the `get_rest_url()` function. This allows sites that do not have mod_rewrite support to have almost pretty urls and have access to their REST API endpoints.

Props kraftbj.
Fixes #38182.

git-svn-id: https://develop.svn.wordpress.org/trunk@38790 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Rachel Baker
2016-10-14 19:29:08 +00:00
parent 6b8d8c90a5
commit a94f468051
2 changed files with 20 additions and 3 deletions

View File

@@ -275,11 +275,15 @@ class Tests_REST_API extends WP_UnitTestCase {
*/
public function test_rest_url_generation() {
// In pretty permalinks case, we expect a path of wp-json/ with no query.
update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
$this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/wp-json/', get_rest_url() );
update_option( 'permalink_structure', '' );
// In index permalinks case, we expect a path of index.php/wp-json/ with no query.
$this->set_permalink_structure( '/index.php/%year%/%monthnum%/%day%/%postname%/' );
$this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/index.php/wp-json/', get_rest_url() );
// In non-pretty case, we get a query string to invoke the rest router.
$this->set_permalink_structure( '' );
$this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/?rest_route=/', get_rest_url() );
}