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

Block's sourced attributes missing with parse_blocks #46029

Closed
AldoS opened this issue Nov 24, 2022 · 2 comments
Closed

Block's sourced attributes missing with parse_blocks #46029

AldoS opened this issue Nov 24, 2022 · 2 comments
Labels
[Status] Not Applicable Issue outside Gutenberg, is not a bug, or is a support request. [Type] Question Questions about the design or development of the editor.

Comments

@AldoS
Copy link

AldoS commented Nov 24, 2022

Description

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

  1. Add a core/paragraph block to a page and type something - save the page/post
  2. On console run wp.data.select('core/block-editor').getBlocks()
  3. There is an attribute called content that has just the value of the paragraph (plain text)
  4. Run parse_blocks($post->post_content); for the above page/post
  5. 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.

Yes

@Mamaduka Mamaduka added the Needs Technical Feedback Needs testing from a developer perspective. label Nov 24, 2022
@luisherranz
Copy link
Member

luisherranz commented 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 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:

$w = new WP_HTML_Tag_Processor( $button_html );
$w->next_tag( 'a' );
$url = $w->get_attribute( 'href' );

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.

@luisherranz luisherranz changed the title Block's attributes missing with parse_blocks Block's sourced attributes missing with parse_blocks Nov 24, 2022
@luisherranz luisherranz added [Type] Question Questions about the design or development of the editor. [Status] Not Applicable Issue outside Gutenberg, is not a bug, or is a support request. and removed Needs Technical Feedback Needs testing from a developer perspective. labels Nov 24, 2022
@luisherranz
Copy link
Member

@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.

@luisherranz luisherranz closed this as not planned Won't fix, can't repro, duplicate, stale Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] Not Applicable Issue outside Gutenberg, is not a bug, or is a support request. [Type] Question Questions about the design or development of the editor.
Projects
None yet
Development

No branches or pull requests

3 participants