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

Update block-filters.md #64959

Merged
merged 11 commits into from
Oct 1, 2024
25 changes: 25 additions & 0 deletions docs/reference-guides/filters/block-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,31 @@ Used to filter an individual transform result from block transformation. All of

Called immediately after the default parsing of a block's attributes and before validation to allow a plugin to manipulate attribute values in time for validation and/or the initial values rendering of the block in the editor.

The callback function for this filter accepts 4 parameters:
- `blockAttributes` (`Object`): The attributes of the block node given its type.
- `blockType` (`Object`): A block-type definition object.
- `innerHTML` (`string`): Inner HTML content of the block.
- `attributea` (`object`): Known attributes of the block.
davy440 marked this conversation as resolved.
Show resolved Hide resolved

In the example below, we use the `blocks.getBlockAttributes` filter to lock the position of all paragraph blocks on a page.

```js
// Our filter function
function lockParagraphs( blockAttributes, blockType, innterHTML, attributes ) {
davy440 marked this conversation as resolved.
Show resolved Hide resolved
if(blockType['name'] === 'core/paragraph') {
davy440 marked this conversation as resolved.
Show resolved Hide resolved
blockAttributes['lock'] = {move: true}
}
return blockAttributes;
}

// Call the filter
davy440 marked this conversation as resolved.
Show resolved Hide resolved
wp.hooks.addFilter(
'blocks.getBlockAttributes',
'it-residence/lock-paragraphs',
davy440 marked this conversation as resolved.
Show resolved Hide resolved
lockParagraphs
);
```

### `editor.BlockEdit`

Used to modify the block's `edit` component. It receives the original block `BlockEdit` component and returns a new wrapped component.
Expand Down
Loading