-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
REST API: allow overriding excerpt length #5932
REST API: allow overriding excerpt length #5932
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
The code seems okay but I'm still unsure why this has to work in this particular way. Generally this change makes it so sometimes the excerpt length may be overridden with an arbitrary value when doing a REST request. Couple of thoughts about that:
How about instead of adding that non-removable filter callback we add another param like
would become:
where |
How did you get to this conclusion, where did you get this number from? 🤔 The whole issue right now is that Gutenberg offers a way to fully customize the excerpt length in the editor, but that length is not actually honored in the REST API response it receives. This PR is an attempt to solve this in a less hacky way than WordPress/gutenberg#55400
Theoretically, yes. With But plugins can also completely override the excerpt using the
This approach does not prevent a plugin from filtering So in this regard, both approaches have the same problem and I don't think it's solvable. Plugins will always be able to filter the excerpt. |
The initial bug report, here, and the initial patch? :)
May be missing something but how would that slider work if the excerpt was too short? Lets say the user sets the excerpt length to 20, how can they increase it next time they edit the post? Afaik this is the problem here, the editor needs a consistent excerpt length (100?) that can be trimmed on display to allow the user to change it (and actually see it).
Right. But that most likely would be a deliberate change targeting exactly this functionality. I'm thinking more about accidental overrides by plugins that do filters with |
There was no need for a hardcoded excerpt length. That was simply a hacky workaround to provide something to the editor to work with. 100 is the highest number that can be chosen in the editor. No proper solution was implemented which actually returns the actually configured length.
Just like the
The excerpt block is used in places like Query Loop blocks. If you want to increase the excerpt length in places where you used the block, go edit the block. But questions about the excerpt block are better target at someone who built the block :)
What the editor needs is a way to trim the excerpt length to the desired maximum and this change here allows it to do so. At WordPress/gutenberg#55400 (comment) I explained why it's better to do the trimming server-side rather than client-side. |
We also need a Gutenberg PR to use this new param. @azaozz I think this approach is the best since it solves the actual problem: one block wants excerpt to be size X for itself when it renders and when it displays. It should not do this in any way that has any potential to leak the setting to other operations involving excerpt. Having a special param gives the block this option. I also think that the fact that in the end WP can be configured in ways which make this param not work as expected is something to be dealt with at the end of the line - at that implementation: e.g. if your excerpt modifying plugin breaks how you work with the block deal with the plugin. Plugins themselves can also check the request and not override it so it's easy to adapt. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this looks good to me.
I have some minor suggestions.
Co-authored-by: Anton Vlasenko <[email protected]>
Co-authored-by: Mukesh Panchal <[email protected]>
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@azaozz I would appreciate another review If we can merge this now into core there is still time to get the corresponding change into this week's Gutenberg RC so we can finally fix this in 6.5 |
This is a solution that I don't love, but can't think of anything better. The reason I don't love it, is it feels different to how we handle everything else that is variable (like image sizes, avatar sizes, raw vs rendered) where the API spits out multiple choices, and the client chooses the one that is closest to their desired size. I think this is the first time we're giving the client control over a specific API property like that. But that all being said, I can't really think of a better way of handling this. And I think this can be thought of as an extension to things like |
With the latest thumbs up this is definitely ready IMO :) |
Committed in https://core.trac.wordpress.org/changeset/58065 |
Addresses WordPress/gutenberg#53570 on the core side
Related:
Trac ticket: https://core.trac.wordpress.org/ticket/59043
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.