-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add pre- and post- content filter #60
Conversation
@smithjw1 Could I please have a review from you on this, especially on the README documentation for the new filters? Thank you! |
README.md
Outdated
|
||
### `vip_block_data_api__before_parse_post_content` | ||
|
||
Modify raw post content before it's parsed by the Block Data API. |
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.
Like you do with the other filter, I might mention that this is the very first thing called so that you are getting exactly what is in the WP database.
I also like the example in the other one, so we could add one here. The example helps people understand why they might use it.
We should also add a warning that manipulating the content directly can cause block parsing errors, and they should be careful with this filter. Here's the language I would use:
Block Markup is sensitive to changes, even changes in whitespace. We've added this filter to make the plugin flexible, but any changes to the
post_content
should be done with extreme care. Strongly consider adding tests to any filter.
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.
Great notes, especially the warning. Will add!
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.
@smithjw1 Added an before_parse example along with a warning as you described above. Thank you!
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.
I've made a few comments on the Readme. I think we should have someone else review the code, it looks good to me, but I didn't dig too much into the tests.
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.
Wonderfully done @alecgeatches
I'm going to merge this as the code changes are low-risk filter additions and also include tests. |
Description
Add a new filter for modifying post content before it is parsed, and another for after content is parsed:
vip_block_data_api__before_parse_post_content
Modify raw post content before it's parsed by the Block Data API.
vip_block_data_api__after_parse_blocks
Modify the Block Data API REST endpoint response.
Steps to Test
Tests have been added both of the new filters in
tests/parser/test-parser-filters.php
. To test: