Skip to content

Conversation

@dmsnell
Copy link
Member

@dmsnell dmsnell commented Jan 25, 2023

What?

Wraps HTML Tag Processor class definitions inside if ( ! class_exists( … ) ) checks.

Why?

In preparation for a merge into WordPress 6.2 we're wrapping the class definitions for the HTML Tag Processor and its dependent helper classes in checks for whether they already exist. This ensures that they don't trigger errors if and when they are included both by Core and by the Gutenberg plugin on sites having the plugin installed.

How?

Using the if ( … ) : and endif; syntax here to avoid introducing another indent level for what is essentially the entire file.

If this file is required multiple times then successive calls will be effective noops.

Testing Instructions

If any problems are introduced here they should completely crash the PHP unit tests.

@dmsnell dmsnell requested review from adamziel and ockham January 25, 2023 22:33
@dmsnell dmsnell marked this pull request as ready for review January 25, 2023 22:35
@dmsnell dmsnell requested a review from spacedmonkey as a code owner January 25, 2023 22:35
Copy link
Contributor

@adamziel adamziel left a comment

Choose a reason for hiding this comment

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

This is great, thank you!

Oh, and the linter is ruthless and wants us to indent these classes :-(

@dmsnell
Copy link
Member Author

dmsnell commented Jan 26, 2023

The linter is ruthless, I agree 😄

I wasn't sure what ignore-statement I needed to find to blast over the code to get the linter to chill out. None of the classes in Core are indented, and I couldn't find any ignore comments there so I think the linter only marches over Gutenberg.

If I can find the ignore comment I'll add it.

@dmsnell dmsnell force-pushed the tag-processor/wrap-in-if-exists-checks branch from 1a3c5eb to 400a4da Compare January 27, 2023 04:19
@dmsnell
Copy link
Member Author

dmsnell commented Jan 27, 2023

The linter problem seemed more challenging than I first expected: because the problem isn't the if ( ! class_exists() ) : line, it's every other line in the file.

In response I have taken an approach that is objectively less safe so I don't have to fight against the linter.

@github-actions
Copy link

Flaky tests detected in 400a4da.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4021526132
📝 Reported issues:

@dmsnell dmsnell force-pushed the tag-processor/wrap-in-if-exists-checks branch from 400a4da to b25d218 Compare January 27, 2023 18:41
@ockham
Copy link
Contributor

ockham commented Jan 30, 2023

Thank you @dmsnell and @adamziel!

I'll try a rebase to get failing tests to pass.

In preparation for a merge into WordPress 6.2 we're wrapping the
class definitions for the HTML Tag Processor and its dependent
helper classes in checks for whether they already exist.

Additionaly we've renamed the `index.php` file to `wp-html.php`
to better align with its role of loading the WordPress HTML
parsing subsystem, both with the Tag Processor itself but also
with future higher-level APIs and expansions on top of it.

Co-Authored-By: Bernie Reiter <[email protected]>
@ockham ockham force-pushed the tag-processor/wrap-in-if-exists-checks branch from b25d218 to cf2b7b5 Compare January 30, 2023 09:24
@ockham ockham merged commit 7826bd5 into trunk Jan 30, 2023
@ockham ockham deleted the tag-processor/wrap-in-if-exists-checks branch January 30, 2023 10:20
@github-actions github-actions bot added this to the Gutenberg 15.1 milestone Jan 30, 2023
@juanmaguitar juanmaguitar added the [Type] Enhancement A suggestion for improvement. label Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants