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

Filter to allow plugins override block attributes #11730

Closed
Closed
10 changes: 10 additions & 0 deletions lib/class-wp-block-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ public function prepare_attributes_for_render( $attributes ) {
$prepared_attributes[ $attribute_name ] = $value;
}

/**
* Filter to allow plugins to override block attributes
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
*
* @since 3.5.0
kkarpieszuk marked this conversation as resolved.
Show resolved Hide resolved
*
* @param array $prepared_attributes block attributes
kkarpieszuk marked this conversation as resolved.
Show resolved Hide resolved
*/

kkarpieszuk marked this conversation as resolved.
Show resolved Hide resolved
$prepared_attributes = apply_filters( 'block_attributes', $prepared_attributes );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO $this should be passed to the filter as well. Otherwise one has no idea which block type the attributes are for.

Copy link
Member

@gziolo gziolo Nov 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't it pass the block name instead of $this? What other information plugins would need? It feels like there is no need to pass the block type object by reference.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I second idea to pass the whole object. Mind it, plugin authors will filter not only core Blocks but also many 3rd party with who knows what kind of data. Sometimes it will be helpful to have bigger picture inside of the hook.

But finally it is up to you, I can change but please decide :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 It will be more useful to be given the whole object here instead of the "block type name".


return $prepared_attributes;
}

Expand Down