-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 Bindings: Add private HTML API subclass with experimental set_inner_html #7742
base: trunk
Are you sure you want to change the base?
Block Bindings: Add private HTML API subclass with experimental set_inner_html #7742
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
src/wp-includes/class-wp-block.php
Outdated
*/ | ||
class PrivateProcessor extends WP_HTML_Processor { | ||
|
||
public function set_inner_html( ?string $html ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method allows does "naive" inner HTML replacement, where the content that should be inside the node can change the HTML tree beyond the node.
This is also true with the existing implementation so it's not a regression and can be dealt with now or in follow-up work.
* | ||
* @access private | ||
*/ | ||
class PrivateProcessor extends WP_HTML_Processor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#6838 uses a pattern for a private processor class:
wordpress-develop/src/wp-includes/class-wp-block.php
Lines 338 to 341 in 825f78e
$bindings_processor_builder = new class( | |
'Do not use this, it will not work. It is only here to create a subclass and call the static creator method', | |
WP_HTML_Processor::CONSTRUCTOR_UNLOCK_CODE | |
) extends WP_HTML_Processor { |
Nice progress here. In #6838, an HTML API subclass was explored to add support for a new Image attribute. It might be interesting to use it as a reference and potentially borrow the unit test when playing with it. |
2703671
to
058d473
Compare
/*}*/ | ||
|
||
if ( '' !== $html ) { | ||
$fragment_parser = $this->create_fragment_at_current_node( $html ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was testing the pull request, and it seems this method is private. If I change it to protected
, everything seems to work as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! The changes (that I rebased this on) were partially reverted. This method may become public again in #7912.
For now we can make it protected as part of this PR.
Depends on #7348
Uses an implementation from sirreal#9
Trac ticket:
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.