feat: get default WP block attributes #1
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This allows you to get the default wp block attributes in the template.
It was tricky to do as main function returns string with attributes.
example:
string(39) “class=”wp-block-giantpeach-testimonial””
I had to keep acf in mind too https://www.advancedcustomfields.com/resources/acf-blocks-using-get_block_wrapper_attributes/
Wp by default is adding the styles, so there is no need to render it in the admin.
I managed to split it into chunks and use it as an array with keys.
There are 2 ways to use it in the template.
First by creating empty element and passing raw string directly into it like so:
Second option is to add it to class attribute by key:
I think second option is better as we don't have to create additional div as a wrapper and we have more control over different attributes. Because of these flexibility I decided to use this attributes individually per block, rather than using it globally as a wrapper for every block