From adfe79ca9f502c2c5742e1165f41c1e083c51a83 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Fri, 14 Oct 2016 15:24:12 -0500 Subject: [PATCH 1/2] Admin Page: Fix REST API URL for index permalinks if using older version of WP --- jetpack.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/jetpack.php b/jetpack.php index 72a65d6cbc4fc..a2ac014a52630 100644 --- a/jetpack.php +++ b/jetpack.php @@ -27,6 +27,24 @@ defined( 'JETPACK_PROTECT__API_HOST' ) or define( 'JETPACK_PROTECT__API_HOST', 'https://api.bruteprotect.com/' ); defined( 'JETPACK__WPCOM_JSON_API_HOST' ) or define( 'JETPACK__WPCOM_JSON_API_HOST', 'public-api.wordpress.com' ); +add_filter( 'rest_url_prefix', 'jetpack_index_permalinks_rest_api_url', 999 ); +/** + * Fix the REST API URL for sites using index permalinks + * + * @todo Remove when 4.7 is minimum version + * @see https://core.trac.wordpress.org/ticket/38182 + * @see https://github.com/Automattic/jetpack/issues/5216 + * @author kraftbj + **/ +function jetpack_index_permalinks_rest_api_url( $prefix ){ + global $wp_rewrite, $wp_version; + if ( version_compare( $wp_version, '4.7-alpha-38790', '>=' ) && $wp_rewrite->using_index_permalinks() ){ + $prefix = $wp_rewrite->index . '/' . $prefix; + } + + return $prefix; +} + /** * Returns the location of Jetpack's lib directory. This filter is applied * in require_lib(). From ebfcdd848dfb03068f55732e0949e1bcd55f70ff Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 9 Nov 2016 13:24:08 -0600 Subject: [PATCH 2/2] Correct wp_version check --- jetpack.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetpack.php b/jetpack.php index a2ac014a52630..1176ee32c8b7b 100644 --- a/jetpack.php +++ b/jetpack.php @@ -38,7 +38,7 @@ **/ function jetpack_index_permalinks_rest_api_url( $prefix ){ global $wp_rewrite, $wp_version; - if ( version_compare( $wp_version, '4.7-alpha-38790', '>=' ) && $wp_rewrite->using_index_permalinks() ){ + if ( version_compare( $wp_version, '4.7-alpha-38790', '<' ) && $wp_rewrite->using_index_permalinks() ){ $prefix = $wp_rewrite->index . '/' . $prefix; }