Skip to content

Commit

Permalink
Use permalink template filter only for wp version < 5.0.0.
Browse files Browse the repository at this point in the history
Note: This is to use Gutenberg for WordPress nightly builds and trunk once core trac WordPress#45017 patch merge in it.
ref: WordPress#10400
  • Loading branch information
rahulsprajapati committed Oct 8, 2018
1 parent 96ce333 commit 65b0268
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,18 @@ function gutenberg_add_target_schema_to_links( $response, $post, $request ) {
* @return string That same post type.
*/
function gutenberg_register_post_prepare_functions( $post_type ) {
add_filter( "rest_prepare_{$post_type}", 'gutenberg_add_permalink_template_to_posts', 10, 3 );

// Get unmodified $wp_version.
include ABSPATH . WPINC . '/version.php';

// Strip '-src' from the version string. Messes up version_compare().
$version = str_replace( '-src', '', $wp_version );

// Apply filter to older versions of WordPress.
if ( version_compare( $version, '5.0.0', '<' ) ) {
add_filter( "rest_prepare_{$post_type}", 'gutenberg_add_permalink_template_to_posts', 10, 3 );
}

add_filter( "rest_prepare_{$post_type}", 'gutenberg_add_block_format_to_post_content', 10, 3 );
add_filter( "rest_prepare_{$post_type}", 'gutenberg_add_target_schema_to_links', 10, 3 );
add_filter( "rest_{$post_type}_collection_params", 'gutenberg_filter_post_collection_parameters', 10, 2 );
Expand Down

0 comments on commit 65b0268

Please sign in to comment.