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

Backport: Add filter for duotone to account for gutenberg_restore_image_outer_container in classic themes #6607

Conversation

scruffian
Copy link

@scruffian scruffian commented May 22, 2024

Backport for WordPress/gutenberg#59764

Trac ticket: https://core.trac.wordpress.org/ticket/61271


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

Trac Ticket Missing

This pull request is missing a link to a Trac ticket. For a contribution to be considered, there must be a corresponding ticket in Trac.

To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. More information about contributing to WordPress on GitHub can be found in the Core Handbook.

Copy link

github-actions bot commented May 22, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props scruffian, isabel_brison, ajlende.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

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.

Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

Hmm, this changeset doesn't match the one from WordPress/gutenberg#59764, which adds a new restore_image_outer_container function to the duotone class. Is that intentional?

I also see in testing that this is removing the outer wrapper on aligned images, instead of moving the duotone classname to it (which is what happens in the plugin after WordPress/gutenberg#59764)

@ajlende
Copy link

ajlende commented Jun 3, 2024

@tellthemachines I have the correct backport at #6719

@scruffian
Copy link
Author

@tellthemachines you're right I had done this wrongly. I have updated the PR with the correct approach (I hope!)

I had incorrectly read the original PR and thought it was removing the restore_image_outer_container filter, but it was actually removing the Duotone specific filter.

@@ -57,3 +57,7 @@

// Migrate the old experimental duotone support flag.
add_filter( 'block_type_metadata_settings', array( 'WP_Duotone', 'migrate_experimental_duotone_support_flag' ), 10, 2 );

// Restore duotone classes to the image wrapper div.
add_filter( 'render_block_core/image', array( 'WP_Duotone', 'restore_image_outer_container' ), 11, 2 );
Copy link

Choose a reason for hiding this comment

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

Suggested change
add_filter( 'render_block_core/image', array( 'WP_Duotone', 'restore_image_outer_container' ), 11, 2 );
add_filter( 'render_block_core/image', array( 'WP_Duotone', 'restore_image_outer_container' ), 10, 1 );

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we might have to keep the higher priority because the filter isn't working on your other PR @ajlende, but it's working on this one.

Copy link

Choose a reason for hiding this comment

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

I forgot that this was weird in the PR. Things have to be loaded in a very specific order. WordPress/gutenberg#59764 (comment)

When this gets backported to core, the same should happen with the core version of the functions. Although, it looks like the imports will have to be reordered during the core backport (WordPress/wordpress-develop@9a616a5/src/wp-settings.php#L371).

In my opinion, with the way WordPress code is written with side effects in many files, the way that we mostly centralize imports, the size of the codebase, and the number of contributors, it makes more sense for use to just preserve the order of imports when backporting things to not have to worry so much about priority levels. It seems better to me to maintain that order than force extenders to use extra high priorities to override core behavior.

Copy link

Choose a reason for hiding this comment

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

@tellthemachines I don't have permissions to push to this branch, but I updated the import order to match Gutenberg in #6719 and that seems to work for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool we can go with that one then!

* Fixes the issue with our generated class name not being added to the block's outer container
* in classic themes.
*
* @since 6.5.0
Copy link

Choose a reason for hiding this comment

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

Suggested change
* @since 6.5.0
* @since 6.6.0

return $tags->get_updated_html();
}


Copy link

Choose a reason for hiding this comment

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

Suggested change


// Restore duotone classes to the image wrapper div.
add_filter( 'render_block_core/image', array( 'WP_Duotone', 'restore_image_outer_container' ), 11, 2 );

Copy link

Choose a reason for hiding this comment

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

Suggested change

@tellthemachines
Copy link
Contributor

Closing this one in favour of #6719.

* @since 6.5.0
*
* @param string $block_content Rendered block content.
* @return string Filtered block content.
Copy link
Member

Choose a reason for hiding this comment

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

@tellthemachines @return string Filtered block content. space should be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

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

Successfully merging this pull request may close these issues.

4 participants