-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Create an alias get_element_class_name to use it in blocks #44099
Conversation
lib/compat/wordpress-6.1/theme.php
Outdated
if ( ! class_exists( 'WP_Theme_JSON_Gutenberg' ) || ! method_exists( 'WP_Theme_JSON_Gutenberg', 'get_element_class_name' ) ) { | ||
return ''; |
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'm not really sure if this case can happen.
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 don't think we use that in other places. The class and the method are present in the Gutenberg plugin so I belive you can skip the check.
Size Change: 0 B Total Size: 1.25 MB ℹ️ View Unchanged
|
tools/webpack/blocks.js
Outdated
@@ -30,6 +30,7 @@ const blockViewRegex = new RegExp( | |||
const prefixFunctions = [ | |||
'build_query_vars_from_query_block', | |||
'wp_enqueue_block_support_styles', | |||
'wp_theme_element_class_name', |
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 would be happier if we wouldn't have to list those functions here. What's the reasoning behind using the function name with gutenberg_
prefix?
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.
That was my suggestion. I probably applied the conclusion from #43779 (comment) and the naming collision too strongly.
Since we're not dealing with a different version of the same function (as was the case in #43779, which was then superseded by #43859), it's probably fine to name it wp_theme_element_class_name
in Gutenberg (and wrap the definition in a ! function_exists()
check).
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.
Aside: @mtias has pointed out to me in Slack that
The one issue with the function check is that it prevents improvements on the plugin to the core functions
-- which was basically the situation we had in #43859. As we've discussed above, this doesn't currently apply to wp_theme_element_class_name
-- if we ever decide to modify that function, we can still adopt a prefix-rewriting strategy.
We should probably put some guidelines into writing -- there currently seems to be a bit of confusion around what strategies to apply to avoid collisions (see e.g. #44100).
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.
There are guidelines present in the documentation:
https://github.com/WordPress/gutenberg/tree/trunk/lib#wrap-functions-and-classes-with--function_exists-and--class_exists
Feel free to add more details, so it makes the process less confusing.
I think there is rarely a reason to use the trick with webpack and prefixFunctions
list. Two existing cases are related to the function param changes in the function definition. Otherwise, you can use all sorts of feature detection to figure out what needs to be polyfilled.
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.
The solution proposed works. I would be happier if we could conditionally define a fallback for wp_theme_element_class_name
when it's not present in WordPress.
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.
Nice, thank you for following up with the changes 👍🏻
This changeset backports the `wp_theme_element_class_name()` alias for the "internal" `WP_Theme_JSON::get_element_class_name()` function. This is a backport of [WordPress/gutenberg#44099 gutenberg/PR44099]. Note: this changeset doesn't replace calls to `WP_Theme_JSON::get_element_class_name` in the tests, since those are specifically for the `WP_Theme_JSON` class. Props bernhard-reiter, cbravobernal, costdev. See #56467. git-svn-id: https://develop.svn.wordpress.org/trunk@54174 602fd350-edb4-49c9-b593-d223f7449a82
This changeset backports the `wp_theme_element_class_name()` alias for the "internal" `WP_Theme_JSON::get_element_class_name()` function. This is a backport of [WordPress/gutenberg#44099 gutenberg/PR44099]. Note: this changeset doesn't replace calls to `WP_Theme_JSON::get_element_class_name` in the tests, since those are specifically for the `WP_Theme_JSON` class. Props bernhard-reiter, cbravobernal, costdev. See #56467. Built from https://develop.svn.wordpress.org/trunk@54174 git-svn-id: http://core.svn.wordpress.org/trunk@53733 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This changeset backports the `wp_theme_element_class_name()` alias for the "internal" `WP_Theme_JSON::get_element_class_name()` function. This is a backport of [WordPress/gutenberg#44099 gutenberg/PR44099]. Note: this changeset doesn't replace calls to `WP_Theme_JSON::get_element_class_name` in the tests, since those are specifically for the `WP_Theme_JSON` class. Props bernhard-reiter, cbravobernal, costdev. See #56467. Built from https://develop.svn.wordpress.org/trunk@54174 git-svn-id: https://core.svn.wordpress.org/trunk@53733 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This changeset backports the `wp_theme_element_class_name()` alias for the "internal" `WP_Theme_JSON::get_element_class_name()` function. This is a backport of [WordPress/gutenberg#44099 gutenberg/PR44099]. Note: this changeset doesn't replace calls to `WP_Theme_JSON::get_element_class_name` in the tests, since those are specifically for the `WP_Theme_JSON` class. Props bernhard-reiter, cbravobernal, costdev. See #56467. Built from https://develop.svn.wordpress.org/trunk@54174
This changeset backports the `wp_theme_element_class_name()` alias for the "internal" `WP_Theme_JSON::get_element_class_name()` function. This is a backport of [WordPress/gutenberg#44099 gutenberg/PR44099]. Note: this changeset doesn't replace calls to `WP_Theme_JSON::get_element_class_name` in the tests, since those are specifically for the `WP_Theme_JSON` class. Props bernhard-reiter, cbravobernal, costdev. See #56467. git-svn-id: https://develop.svn.wordpress.org/trunk@54174 602fd350-edb4-49c9-b593-d223f7449a82
What?
Creates an alias for the internal API class WP_Theme_JSON_Gutenberg
Why?
Following the discussion on Sync Gutenberg packages, we noticed that some blocks are using a Class WP_Theme_JSON_Gutenberg method.
How?
Testing Instructions
Go to post or site editor.
Add Search block or Comments Form block. Check that the button has
wp-element-button
class.Screenshots or screencast