You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+93Lines changed: 93 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1218,6 +1218,99 @@ Direct block HTML can be accessed through `$block['innerHTML']`. This may be use
1218
1218
1219
1219
For another example of how this filter can be used to extend block data, we have implemented a default image block filter in [`src/parser/block-additions/core-image.php`][repo-core-image-block-addition]. This filter is automatically called on `core/image` blocks to add `width` and `height` to image attributes.
Modify raw post content before it's parsed by the Block Data API. The `$post_content` provided by this filter is directly what is stored in the post database before any processing occurs.
1226
+
1227
+
```php
1228
+
/**
1229
+
* Filters content before parsing blocks in a post.
1230
+
*
1231
+
* @paramstring $post_content The content of the post being parsed.
1232
+
* @paramint $post_id Post ID associated with the content.
For example, this could be used to modify a block's type before parsing. The code below replaces instances of `test/invalid-block` blocks with `core/paragraph`:
Be careful with content modification before parsing. In the example above, if a block contained the text "wp:test/invalid-block" outside of a block header, this would also be changed to "wp:paragraph". This is likely not the intent of the code.
1269
+
1270
+
All block markup is sensitive to changes, even changes in whitespace. We've added this filter to make the plugin flexible, but any transforms to `post_content` should be done with extreme care. Strongly consider adding tests to any usage of this filter.
1271
+
1272
+
---
1273
+
1274
+
### `vip_block_data_api__after_parse_blocks`
1275
+
1276
+
Modify the Block Data API REST endpoint response.
1277
+
1278
+
```php
1279
+
/**
1280
+
* Filters the API result before returning parsed blocks in a post.
1281
+
*
1282
+
* @paramstring $result The successful API result, contains 'blocks' key with an array
1283
+
* of block data, and optionally 'warnings' and 'debug' keys.
1284
+
* @paramint $post_id Post ID associated with the content.
This filter is called directly before returning a result in the REST API. Use this filter to add additional metadata or debug information to the API output.
0 commit comments