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 Bindings: Add private HTML API subclass with experimental set_inner_html #7742

Draft
wants to merge 7 commits into
base: trunk
Choose a base branch
from

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Nov 7, 2024

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.

Copy link

github-actions bot commented Nov 7, 2024

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@sirreal sirreal changed the title block bindings/html api private set inner html Block Bindings: Add private HTML API subclass with experimental set_inner_html Nov 7, 2024
@sirreal
Copy link
Member Author

sirreal commented Nov 8, 2024

9691991 extracted to #7754

*/
class PrivateProcessor extends WP_HTML_Processor {

public function set_inner_html( ?string $html ) {
Copy link
Member Author

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 {
Copy link
Member

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:

$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 {

@gziolo
Copy link
Member

gziolo commented Nov 21, 2024

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.

@sirreal sirreal force-pushed the block-bindings/html-api-private-set-inner-html branch from 2703671 to 058d473 Compare November 27, 2024 09:39
/*}*/

if ( '' !== $html ) {
$fragment_parser = $this->create_fragment_at_current_node( $html );

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.

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants