Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#53140 closed enhancement (fixed)

State clearly that has_block() doesn't work in reusable blocks

Reported by: vyskoczilova's profile vyskoczilova Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.8 Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch commit
Focuses: docs Cc:

Description

The has_block() function doesn't work in reusable blocks. Since the content of reusable blocks is not parsed yet (see my [blog post](https://kybernaut.cz/en/clanky/check-for-has_block-inside-reusable-blocks/) for more details).

That's fine, but I think that should be stated more clearly than the original [description](https://developer.wordpress.org/reference/functions/has_block/#description):
This test optimizes for performance rather than strict accuracy, detecting the block type exists but not validating its structure. For strict accuracy, you should use the block parser on post content.

I would suggest changing that to the following, so it's clear what it's mostly impacted with the "performance accuracy."

This test optimizes for performance rather than strict accuracy, detecting the block type exists but not validating its structure (e.g., doesn't check reusable blocks). For strict accuracy, you should use the block parser on post content.

What do you think?

I'm happy to submit it as a patch since it looks like a good "first issue," but never done it before.

Attachments (1)

53140.patch (696 bytes) - added by vyskoczilova 4 years ago.

Download all attachments as: .zip

Change History (8)

@vyskoczilova
4 years ago

#1 @vyskoczilova
4 years ago

  • Keywords has-patch added

The proposed change is attached as a patch.

This ticket was mentioned in Slack in #core by chaion07. View the logs.


4 years ago

#3 @peterwilsoncc
4 years ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 5.8

Thanks for the ticket @vyskoczilova,

This was discussed in a triage session today and it was agreed that a little clarity around reusable blocks would be helpful.

I've moved this on to the 5.8 milestone and labeled it ready for commit.

Related #52628.

#4 follow-up: @vyskoczilova
4 years ago

Hi @peterwilsoncc! Thanks for the approval. Anything else should be done from my side? It's my first time with Trac.

I've quickly checked the triage session and as far as I know, there are no other blocks you need to render first, but I guess this can change.

#5 in reply to: ↑ 4 @peterwilsoncc
4 years ago

Replying to vyskoczilova:

Hi @peterwilsoncc! Thanks for the approval. Anything else should be done from my side?

No, nothing more needs to be done from your side. If another contributor has language change suggestions, then they can produce another patch and you'll still get props and become an official contributor yourself.

It's my first time with Trac.

If you prefer Git, then you are welcome to create a pull request on the GitHub mirror and link to a ticket in the description. Many committers use GitHub until it comes time to commit.

I've quickly checked the triage session and as far as I know, there are no other blocks you need to render first, but I guess this can change.

Great, thanks for checking.

#6 @SergeyBiryukov
4 years ago

  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#7 @SergeyBiryukov
4 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 51046:

Docs: Document that has_block() does not check reusable blocks.

Since the function only checks the raw, non-parsed post content, reusable blocks are just a core/block type and nothing more at that point.

In order to also check reusable blocks, the content needs to be parsed using parse_blocks() first.

Props vyskoczilova, peterwilsoncc.
Fixes #53140.

Note: See TracTickets for help on using tickets.