Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin Page: Fix REST API URL for index permalinks #5345

Merged
merged 2 commits into from Nov 9, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions jetpack.php
Expand Up @@ -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() ){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If my reasoning is correct, then this should be < instead of >=. Here's my reasoning:
We only need this for versions of WordPress that have not yet fixed that problem, so the version should actually be less than 4.7-alpha-38790. This expression returns true if it's later than 4.7-alpha-38790. Please let me know if I'm wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this!

$prefix = $wp_rewrite->index . '/' . $prefix;
}

return $prefix;
}

/**
* Returns the location of Jetpack's lib directory. This filter is applied
* in require_lib().
Expand Down