From 3c7f424e62849aef5e6eafd67870f7857d4c70d7 Mon Sep 17 00:00:00 2001 From: davy440 Date: Sat, 31 Aug 2024 13:04:34 -0400 Subject: [PATCH 01/10] Update block-filters.md Added description for `blocks.getBlockAttributes` filter --- .../reference-guides/filters/block-filters.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/reference-guides/filters/block-filters.md b/docs/reference-guides/filters/block-filters.md index 637cecadf1402b..81873962735028 100644 --- a/docs/reference-guides/filters/block-filters.md +++ b/docs/reference-guides/filters/block-filters.md @@ -294,6 +294,32 @@ 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. +It can be used to add a unique ID attribute for every block to maintain references to the block. + +```js +// Importing "js-md5" package +import { md5 } from "js-md5"; + +function addUniqueID( attributes ) { + + // Generating a hash value unique for every block. + // Similar technique used by ACF to add ids to their blocks. + const hash = md5(JSON.stringify(Object.keys(attributes).sort().reduce((acc, currVal) => { + acc[currVal] = attributes[currVal] + return acc; + }, {}))); + const id = `block_${hash}`; + const newAttrs = {blockId, ...attributes}; + return newAttrs; +} + +wp.hooks.addFilter( + 'blocks.getBlockAttributes', + 'my-plugin/add-unique-id', + addUniqueID +); +``` + ### `editor.BlockEdit` Used to modify the block's `edit` component. It receives the original block `BlockEdit` component and returns a new wrapped component. From d6456749b3220a325f3c55fa676cc5931b3eb198 Mon Sep 17 00:00:00 2001 From: davy440 Date: Wed, 11 Sep 2024 00:05:43 -0400 Subject: [PATCH 02/10] Modified example and provided additional info --- .../reference-guides/filters/block-filters.md | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/docs/reference-guides/filters/block-filters.md b/docs/reference-guides/filters/block-filters.md index 81873962735028..637cecadf1402b 100644 --- a/docs/reference-guides/filters/block-filters.md +++ b/docs/reference-guides/filters/block-filters.md @@ -294,32 +294,6 @@ 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. -It can be used to add a unique ID attribute for every block to maintain references to the block. - -```js -// Importing "js-md5" package -import { md5 } from "js-md5"; - -function addUniqueID( attributes ) { - - // Generating a hash value unique for every block. - // Similar technique used by ACF to add ids to their blocks. - const hash = md5(JSON.stringify(Object.keys(attributes).sort().reduce((acc, currVal) => { - acc[currVal] = attributes[currVal] - return acc; - }, {}))); - const id = `block_${hash}`; - const newAttrs = {blockId, ...attributes}; - return newAttrs; -} - -wp.hooks.addFilter( - 'blocks.getBlockAttributes', - 'my-plugin/add-unique-id', - addUniqueID -); -``` - ### `editor.BlockEdit` Used to modify the block's `edit` component. It receives the original block `BlockEdit` component and returns a new wrapped component. From 9485386db69f2d9d550173a6ee8e38794410c64e Mon Sep 17 00:00:00 2001 From: davy440 Date: Wed, 11 Sep 2024 00:12:18 -0400 Subject: [PATCH 03/10] modified example and provided additional info Explained the parameters accepted by the filter callback function. --- .../reference-guides/filters/block-filters.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/reference-guides/filters/block-filters.md b/docs/reference-guides/filters/block-filters.md index 637cecadf1402b..c53a3624c59fa6 100644 --- a/docs/reference-guides/filters/block-filters.md +++ b/docs/reference-guides/filters/block-filters.md @@ -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. + +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( attributes, props, content ) { + if(props['name'] === 'core/paragraph') { + attributes['lock'] = {move: true} + } + return attributes; +} + +// Call the filter +wp.hooks.addFilter( + 'blocks.getBlockAttributes', + 'it-residence/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. From ac26f84cab751e5f32250673c6a5b54c0c204f10 Mon Sep 17 00:00:00 2001 From: davy440 Date: Wed, 11 Sep 2024 00:15:36 -0400 Subject: [PATCH 04/10] modified example and provided additional info Fixed parameter names. --- docs/reference-guides/filters/block-filters.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/reference-guides/filters/block-filters.md b/docs/reference-guides/filters/block-filters.md index c53a3624c59fa6..241e9f4f1a06b6 100644 --- a/docs/reference-guides/filters/block-filters.md +++ b/docs/reference-guides/filters/block-filters.md @@ -304,11 +304,11 @@ In the example below, we use the `blocks.getBlockAttributes` filter to lock the ```js // Our filter function -function lockParagraphs( attributes, props, content ) { - if(props['name'] === 'core/paragraph') { - attributes['lock'] = {move: true} +function lockParagraphs( blockAttributes, blockType, innterHTML, attributes ) { + if(blockType['name'] === 'core/paragraph') { + blockAttributes['lock'] = {move: true} } - return attributes; + return blockAttributes; } // Call the filter From f645154fda0048cddc55d73d0a6f0342deafd99b Mon Sep 17 00:00:00 2001 From: davy440 Date: Thu, 12 Sep 2024 16:31:51 -0400 Subject: [PATCH 05/10] Update docs/reference-guides/filters/block-filters.md Thanks Co-authored-by: Sunil Prajapati <61308756+akasunil@users.noreply.github.com> --- docs/reference-guides/filters/block-filters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference-guides/filters/block-filters.md b/docs/reference-guides/filters/block-filters.md index 241e9f4f1a06b6..dacf3906267908 100644 --- a/docs/reference-guides/filters/block-filters.md +++ b/docs/reference-guides/filters/block-filters.md @@ -314,7 +314,7 @@ function lockParagraphs( blockAttributes, blockType, innterHTML, attributes ) { // Call the filter wp.hooks.addFilter( 'blocks.getBlockAttributes', - 'it-residence/lock-paragraphs', + 'my-plugin/lock-paragraphs', lockParagraphs ); ``` From cd9e0f96657c9c48c95ca7463c99fd3a283de6cc Mon Sep 17 00:00:00 2001 From: davy440 Date: Thu, 12 Sep 2024 16:33:20 -0400 Subject: [PATCH 06/10] Update docs/reference-guides/filters/block-filters.md thanks for fix Co-authored-by: Sunil Prajapati <61308756+akasunil@users.noreply.github.com> --- docs/reference-guides/filters/block-filters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference-guides/filters/block-filters.md b/docs/reference-guides/filters/block-filters.md index dacf3906267908..843c39a64bc481 100644 --- a/docs/reference-guides/filters/block-filters.md +++ b/docs/reference-guides/filters/block-filters.md @@ -311,7 +311,7 @@ function lockParagraphs( blockAttributes, blockType, innterHTML, attributes ) { return blockAttributes; } -// Call the filter +// Add the filter wp.hooks.addFilter( 'blocks.getBlockAttributes', 'my-plugin/lock-paragraphs', From 3039946faf667e2a13a54a625acc1dce6b9dcca7 Mon Sep 17 00:00:00 2001 From: davy440 Date: Thu, 12 Sep 2024 16:33:39 -0400 Subject: [PATCH 07/10] Update docs/reference-guides/filters/block-filters.md thanks for fix Co-authored-by: Sunil Prajapati <61308756+akasunil@users.noreply.github.com> --- docs/reference-guides/filters/block-filters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference-guides/filters/block-filters.md b/docs/reference-guides/filters/block-filters.md index 843c39a64bc481..9c661568e6c82b 100644 --- a/docs/reference-guides/filters/block-filters.md +++ b/docs/reference-guides/filters/block-filters.md @@ -304,7 +304,7 @@ In the example below, we use the `blocks.getBlockAttributes` filter to lock the ```js // Our filter function -function lockParagraphs( blockAttributes, blockType, innterHTML, attributes ) { +function lockParagraphs( blockAttributes, blockType, innerHTML, attributes ) { if(blockType['name'] === 'core/paragraph') { blockAttributes['lock'] = {move: true} } From b459937eb6efa36e988ea3a9f3a7c3fba3532077 Mon Sep 17 00:00:00 2001 From: davy440 Date: Thu, 12 Sep 2024 16:33:53 -0400 Subject: [PATCH 08/10] Update docs/reference-guides/filters/block-filters.md thanks for fix Co-authored-by: Sunil Prajapati <61308756+akasunil@users.noreply.github.com> --- docs/reference-guides/filters/block-filters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference-guides/filters/block-filters.md b/docs/reference-guides/filters/block-filters.md index 9c661568e6c82b..bcfdb93b47b768 100644 --- a/docs/reference-guides/filters/block-filters.md +++ b/docs/reference-guides/filters/block-filters.md @@ -298,7 +298,7 @@ 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. +- `attributes` (`object`): Known attributes of the block. In the example below, we use the `blocks.getBlockAttributes` filter to lock the position of all paragraph blocks on a page. From 1517178549aa080f5fe1c5a4af685a7b04d4e723 Mon Sep 17 00:00:00 2001 From: davy440 Date: Thu, 12 Sep 2024 16:34:14 -0400 Subject: [PATCH 09/10] Update docs/reference-guides/filters/block-filters.md thanks for fix Co-authored-by: Sunil Prajapati <61308756+akasunil@users.noreply.github.com> --- docs/reference-guides/filters/block-filters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference-guides/filters/block-filters.md b/docs/reference-guides/filters/block-filters.md index bcfdb93b47b768..b5c8a55e4366f8 100644 --- a/docs/reference-guides/filters/block-filters.md +++ b/docs/reference-guides/filters/block-filters.md @@ -305,7 +305,7 @@ In the example below, we use the `blocks.getBlockAttributes` filter to lock the ```js // Our filter function function lockParagraphs( blockAttributes, blockType, innerHTML, attributes ) { - if(blockType['name'] === 'core/paragraph') { + if('core/paragraph' === blockType.name) { blockAttributes['lock'] = {move: true} } return blockAttributes; From 503bdc3a3c8256eccb053d4d0e47e9c3261c999c Mon Sep 17 00:00:00 2001 From: davy440 Date: Thu, 19 Sep 2024 22:40:01 -0400 Subject: [PATCH 10/10] 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 <61308756+akasunil@users.noreply.github.com> --- docs/reference-guides/filters/block-filters.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/reference-guides/filters/block-filters.md b/docs/reference-guides/filters/block-filters.md index b5c8a55e4366f8..f1952ef9bf86f8 100644 --- a/docs/reference-guides/filters/block-filters.md +++ b/docs/reference-guides/filters/block-filters.md @@ -295,10 +295,10 @@ 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. -- `attributes` (`object`): Known attributes of the block. +- `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.