Skip to content

Commit

Permalink
Add the sample permalink to all post types
Browse files Browse the repository at this point in the history
  • Loading branch information
pento committed Nov 10, 2017
1 parent 7b2d4ee commit 5d3e01b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,23 @@ function gutenberg_add_sample_permalink_to_draft_posts( $response, $post, $reque
return $response;
}

if ( ! function_exists( 'get_sample_permalink' ) ) {
require_once ABSPATH . '/wp-admin/includes/post.php';
}

$response->data['sample_permalink'] = get_sample_permalink( $post );

return $response;
}
add_filter( 'rest_prepare_post', 'gutenberg_add_sample_permalink_to_draft_posts', 10, 3 );

/**
* Whenever a post type is registered, ensure we're hooked into it's WP REST API response.
*
* @param string $post_type The newly registered post type.
* @return string That same post type.
*/
function gutenberg_register_sample_permalink_function( $post_type ) {
add_filter( "rest_prepare_{$post_type}", 'gutenberg_add_sample_permalink_to_draft_posts', 10, 3 );
return $post_type;
}
add_filter( 'registered_post_type', 'gutenberg_register_sample_permalink_function' );

0 comments on commit 5d3e01b

Please sign in to comment.