-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Fixing the exerpt length issue with AJAX #55863
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
Conversation
|
I tested the patch provided here, and it solves the issue mentioned. Environment
Before
After
|
alexstine
left a comment
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.
The code looks good but no time at present to test this. Hopefully others can test and review soon.
|
Same concern as with https://github.com/WordPress/gutenberg/pull/55400/files#r1369927043\
Unit tests would be great. |
|
Yeah, how about adding a check like doing_action('edit_post') before adding the 100-length @swissspidy? Will that work in this case? |
|
Test Report Environment Actual Result: Expected Result: Screenshot: Thanks |
|
This PR should probably be closed in favor of WordPress/wordpress-develop#5932, if or when it gets merged. |
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @ZangoFluid, @apeatling. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. Core SVNCore Committers: Use this line as a base for the props when committing in SVN: GitHub Merge commitsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
After https://core.trac.wordpress.org/changeset/58065 this needs a new approach. Closing this for now so a new dedicated PR can be opened. |
What?
This PR addresses inconsistencies in excerpt length when making AJAX requests versus regular HTTP requests and REST API requests.
Fixes #53570.
Why?
In 55400, @anton-vlasenko created a patch, which resolved the issue while making the AJAX call, but then it caused the same problem with the REST API call. So, this PR, it aims to make the excerpt length of both the AJAX call, and REST API call consistent, and that to the defined using the "excerpt_length" hook.
How?
Now it uses the rest_api_init action hook to add the filter only in the REST API context. It checks if REST_REQUEST is defined and set to true, indicating that it's a REST request. If so, it adds the filter for editor_excerpt_length, limiting the excerpt length to 100.
Testing Instructions
You will see the output from both the REST API and AJAX together. You will find the length difference.
If you open up the plugin folder, in the test-ajax.php, on line 7, modify the excerpt length if you wish. Currently, it's set to 20, and the BUG occurs. 🐞
Now, apply the patch, in both the
src/wp-includes/blocks/post-excerpt.php(WordPress Core) andbuild/wp-includes/blocks/post-excerpt.php(Gutenberg). Generate a new build of the Gutenburg, so that the version gets updated.Now, check the output in the console of the page again. You will see the below output. The post-excerpt length in both cases is now 20. The issue is resolved. ✅
Screenshots or screencast
Before:
After: