You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Block's sourced attributes missing with parse_blocks #46029
[Status] Not ApplicableIssue outside Gutenberg, is not a bug, or is a support request.[Type] QuestionQuestions about the design or development of the editor.
Some attributes are missing from core blocks when I use parse_blocks. Some examples:
From core/paragraph block: content
From core/button block: text & url
Step-by-step reproduction instructions
Add a core/paragraph block to a page and type something - save the page/post
On console run wp.data.select('core/block-editor').getBlocks()
There is an attribute called content that has just the value of the paragraph (plain text)
Run parse_blocks($post->post_content); for the above page/post
The content attribute is missing
Screenshots, screen recording, code snippet
No response
Environment info
WordPress version: 6.1.1
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
The sourced attributes of static blocks are stored in the markup that is serialized (saved) to the database. WordPress does not have access to a full HTML parser in PHP, so it is not possible to extract the value of those attributes from the markup.
If you use the Gutenberg plugin, you can use the new HTML Tag Processor API to extract some of the sourced attributes that are saved in the HTML attributes. For example, for the core/button URL, you can do something like:
But the HTML Tag Processor is not a full HTML parser, so it can't extract the core/paragraph content or core/button text. There's no known workaround at this point, as relying on something like DOMDocument is not possible because it's not installed on every host (unless this is only for your own personal use).
EDIT: Please note that the HTML Tag Processor is still experimental.
@AldoS, I'm going to close this issue as it is a known problem and has no solution at the moment, but feel free to reopen it if you think it is necessary.
[Status] Not ApplicableIssue outside Gutenberg, is not a bug, or is a support request.[Type] QuestionQuestions about the design or development of the editor.
Activity
luisherranz commentedon Nov 24, 2022
The sourced attributes of static blocks are stored in the markup that is serialized (saved) to the database. WordPress does not have access to a full HTML parser in PHP, so it is not possible to extract the value of those attributes from the markup.
If you use the Gutenberg plugin, you can use the new
HTML Tag ProcessorAPI to extract some of the sourced attributes that are saved in the HTML attributes. For example, for thecore/buttonURL, you can do something like:But the
HTML Tag Processoris not a full HTML parser, so it can't extract thecore/paragraphcontent orcore/buttontext. There's no known workaround at this point, as relying on something likeDOMDocumentis not possible because it's not installed on every host (unless this is only for your own personal use).EDIT: Please note that the
HTML Tag Processoris still experimental.[-]Block's attributes missing with parse_blocks[/-][+]Block's sourced attributes missing with parse_blocks[/+]luisherranz commentedon Nov 24, 2022
@AldoS, I'm going to close this issue as it is a known problem and has no solution at the moment, but feel free to reopen it if you think it is necessary.