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

Remove permalink_template and generated_slug attributes from rest_prepare_{$post_type} hook. - Moved it to core. #10400

Closed
rahulsprajapati opened this issue Oct 8, 2018 · 6 comments
Labels
Core REST API Task Task for Core REST API efforts REST API Interaction Related to REST API [Type] Task Issues or PRs that have been broken down into an individual action to take

Comments

@rahulsprajapati
Copy link
Contributor

We have moved permalink_template and generated_slug attributes to Posts controller in Core.
ref: https://core.trac.wordpress.org/ticket/45017 ( ready to commit and test )

Once this is merge to core we won't be needing this filter.

add_filter( "rest_prepare_{$post_type}", 'gutenberg_add_permalink_template_to_posts', 10, 3 );

gutenberg/lib/rest-api.php

Lines 191 to 217 in 3e53873

/**
* Add a permalink template to posts in the post REST API response.
*
* @see https://core.trac.wordpress.org/ticket/45017
*
* @param WP_REST_Response $response WP REST API response of a post.
* @param WP_Post $post The post being returned.
* @param WP_REST_Request $request WP REST API request.
* @return WP_REST_Response Response containing the permalink_template.
*/
function gutenberg_add_permalink_template_to_posts( $response, $post, $request ) {
if ( 'edit' !== $request['context'] ) {
return $response;
}
if ( ! function_exists( 'get_sample_permalink' ) ) {
require_once ABSPATH . '/wp-admin/includes/post.php';
}
$sample_permalink = get_sample_permalink( $post->ID, $post->post_title, '' );
$response->data['permalink_template'] = $sample_permalink[0];
$response->data['generated_slug'] = $sample_permalink[1];
return $response;
}

@Soean
Copy link
Member

Soean commented Oct 8, 2018

We can remove this filter, if Gutenberg requires WordPress >= 5.0. Maybe we should add a milestone?

@rahulsprajapati
Copy link
Contributor Author

We can remove this filters if Gutenberg requires WordPress >= 5.0. Maybe we should add a milestone?

sure, it just the core ticket is tagged to 5.0 Milestone.

@danielbachhuber
Copy link
Member

Before WordPress 5.0 ships, lib/rest-api.php will be removed entirely, so this issue will be taken care of with that.

However, once the patch in https://core.trac.wordpress.org/ticket/45017 lands, I'd like to update the filter in lib/rest-api.php to only fire on older versions of WordPress, such that Gutenberg uses the code in core for WordPress nightly builds and trunk.

rahulsprajapati added a commit to rahulsprajapati/gutenberg that referenced this issue Oct 8, 2018
Note: This is to use Gutenberg for WordPress nightly builds and trunk once core trac WordPress#45017 patch merge in it.
ref: WordPress#10400
@rahulsprajapati
Copy link
Contributor Author

Raise this PR #10408 to test the code in the core for WordPress nightly builds and trunk.

@danielbachhuber
Copy link
Member

test the code in the core for WordPress nightly builds and trunk.

Holding off on this for a few weeks: #10408 (comment)

@designsimply designsimply added [Type] Task Issues or PRs that have been broken down into an individual action to take Core REST API Task Task for Core REST API efforts REST API Interaction Related to REST API labels Oct 15, 2018
@danielbachhuber
Copy link
Member

Closing in favor of #10656

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core REST API Task Task for Core REST API efforts REST API Interaction Related to REST API [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants