Skip to content

Commit

Permalink
Update block-filters.md (#64959)
Browse files Browse the repository at this point in the history
* Update block-filters.md

Added description for `blocks.getBlockAttributes` filter

* Modified example and provided additional info

* modified example and provided additional info

Explained the parameters accepted by the filter callback function.

* modified example and provided additional info

Fixed parameter names.

* Update docs/reference-guides/filters/block-filters.md

Thanks

Co-authored-by: Sunil Prajapati <[email protected]>

* Update docs/reference-guides/filters/block-filters.md

thanks for fix

Co-authored-by: Sunil Prajapati <[email protected]>

* Update docs/reference-guides/filters/block-filters.md

thanks for fix

Co-authored-by: Sunil Prajapati <[email protected]>

* Update docs/reference-guides/filters/block-filters.md

thanks for fix

Co-authored-by: Sunil Prajapati <[email protected]>

* Update docs/reference-guides/filters/block-filters.md

thanks for fix

Co-authored-by: Sunil Prajapati <[email protected]>

* Update docs/reference-guides/filters/block-filters.md

Thanks for the suggestion.
Not aware of the format since it's my first time.

Co-authored-by: Sunil Prajapati <[email protected]>

---------

Co-authored-by: davy440 <[email protected]>
Co-authored-by: akasunil <[email protected]>
  • Loading branch information
3 people authored and getdave committed Oct 1, 2024
1 parent 76c4173 commit 2e837db
Showing 1 changed file with 25 additions and 0 deletions.
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`): All block attributes.
- `blockType` (`Object`): The block type.
- `innerHTML` (`string`): Raw block content.
- `attributes` (`object`): Known block attributes (from delimiters).

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, innerHTML, attributes ) {
if('core/paragraph' === blockType.name) {
blockAttributes['lock'] = {move: true}
}
return blockAttributes;
}

// Add the filter
wp.hooks.addFilter(
'blocks.getBlockAttributes',
'my-plugin/lock-paragraphs',
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

0 comments on commit 2e837db

Please sign in to comment.