WordPress.org

Make WordPress Core

Ticket #38182: 38182.diff

File 38182.diff, 1.3 KB (added by kraftbj, 4 years ago)

functional but ugly way to have rest_url() work with index permalinks

  • src/wp-includes/rest-api.php

     
    9393 * @see add_rewrite_rule()
    9494 */
    9595function rest_api_register_rewrites() {
     96        global $wp_rewrite;
    9697        add_rewrite_rule( '^' . rest_get_url_prefix() . '/?$','index.php?rest_route=/','top' );
    9798        add_rewrite_rule( '^' . rest_get_url_prefix() . '/(.*)?','index.php?rest_route=/$matches[1]','top' );
     99        add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/?$','index.php?rest_route=/','top' );
     100        add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/(.*)?','index.php?rest_route=/$matches[1]','top' );
    98101}
    99102
    100103/**
     
    188191        }
    189192
    190193        if ( is_multisite() && get_blog_option( $blog_id, 'permalink_structure' ) || get_option( 'permalink_structure' ) ) {
    191                 $url = get_home_url( $blog_id, rest_get_url_prefix(), $scheme );
     194                global $wp_rewrite;
     195                if ( $wp_rewrite->using_index_permalinks() ) {
     196                        $url = get_home_url( $blog_id, $wp_rewrite->index . '/' . rest_get_url_prefix(), $scheme );
     197                } else {
     198                        $url = get_home_url( $blog_id, rest_get_url_prefix(), $scheme );
     199                }
    192200                $url .= '/' . ltrim( $path, '/' );
    193201        } else {
    194202                $url = trailingslashit( get_home_url( $blog_id, '', $scheme ) );