Make WordPress Core


Ignore:
Timestamp:
10/14/2016 07:29:08 PM (8 years ago)
Author:
rachelbaker
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api.php

    r38771 r38790  
    276276    public function test_rest_url_generation() {
    277277        // In pretty permalinks case, we expect a path of wp-json/ with no query.
    278         update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
     278        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    279279        $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/wp-json/', get_rest_url() );
    280280
    281         update_option( 'permalink_structure', '' );
     281        // In index permalinks case, we expect a path of index.php/wp-json/ with no query.
     282        $this->set_permalink_structure( '/index.php/%year%/%monthnum%/%day%/%postname%/' );
     283        $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/index.php/wp-json/', get_rest_url() );
     284
    282285        // In non-pretty case, we get a query string to invoke the rest router.
     286        $this->set_permalink_structure( '' );
    283287        $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/?rest_route=/', get_rest_url() );
    284288
Note: See TracChangeset for help on using the changeset viewer.