-
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
Fix gutenberg prefixed function references in core #37021
Conversation
I like the approach. It's simple, analogous to an existing concept we have ( I'd like more opinions from other @WordPress/gutenberg-core members and @hellofromtonya. Instead of a PR review, and because I like the sound of my fingers typing, you get a collection of my disparate thoughts on this approach:
|
Yeah agreed, this is something I already planned to do at some point. |
If I'm not mistaken, this is a similar problem like we've had before when backporting GB (and specifically, block specific) PHP code to Core. E.g. WordPress/wordpress-develop#1796 backported the FSE infrastructure, which includes the We solved the rename issue in GB by
For an example, see #36180 and #36201. Is this an approach that could be applied here, too? It'd be nice to consistently use the |
The difference here is that the block PHP ( |
4eef46c
to
b2b5bb9
Compare
Test failures seems unrelated, I just rebased – let's see what happens. |
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 PHP Unit Tests failures in trunk are exactly the same as in this PR. These functions still use the legacy attribute name so I'll rename them – otherwise it looks good. The functions here are only intended to be called in the Gutenberg plugin context, and so it introduces a IS_GUTENBERG_PLUGIN
constant that enables distinguishing between the two situations. I can't see any better way to do that. 👍
I'm sorry for my lateness in responding. 👍 I like the approach of guarding these Gutenberg-only functions by wrapping them within a check that specifically checks for the plugin being activated. A constant is one approach that works well, i.e. 👍 I also like the approach of removing the |
Thanks for elaborating @noisysocks! Right, I think the part that was lost on me is that this is for an optional/ I agree that it doesn't make sense to backport these to Core if it's not sure that we eventually want them there (so I'd rather recommend against the callsite-guarding and |
I might be wrong, but I think there's something about the block library that means this isn't required. There are already quite a lot of block functions that exist in core and don't require guarding in the Gutenberg plugin. I'm not entirely sure how or why that works. |
That's correct. When block PHP is processed for use in the Gutenberg plugin, all PHP function names in gutenberg/tools/webpack/blocks.js Lines 123 to 131 in e96d47b
|
934099c
to
6ae1420
Compare
Thanks for the feedback so far everyone. I'll keep this open until Monday or Tuesday next week to see if there's any more feedback, but if there isn't any will move ahead with merging. |
6ae1420
to
f334127
Compare
Co-authored-by: Tonya Mork <hello@hellofromtonya.com> Check value of `IS_GUTENBERG_PLUGIN` Co-authored-by: Tonya Mork <hello@hellofromtonya.com>
f334127
to
6610305
Compare
I rebased this to (hopefully) fix failing tests. |
* Remove navigation area preloading * Remove navigation area theme switching functionality * Only run if statement in the gutenberg plugin * Move functions to nav block php * Gate function defintions using an if statement * Fix incorrectly named function * Rename navigationMenuId to ref * Also check value of `IS_GUTENBERG_PLUGIN` Co-authored-by: Tonya Mork <hello@hellofromtonya.com> Check value of `IS_GUTENBERG_PLUGIN` Co-authored-by: Tonya Mork <hello@hellofromtonya.com> Co-authored-by: Adam Zieliński <adam@adamziel.com> Co-authored-by: Tonya Mork <hello@hellofromtonya.com>
@hellofromtonya: This was already backported. You can tell by looking for a commit in |
Description
Closes #36962
The problem described there is that when the navigation block's PHP file is copied to WordPress core's codebase, it still contains calls to three functions with
gutenberg_
prefixes, which do not exist in core.This PR moves the three functions (
gutenberg_get_menu_items_at_location
,gutenberg_sort_menu_items_by_parent_id
, andgutenberg_parse_blocks_from_menu_items
) to the navigation block's PHP file and renames them to have block prefixes. Also introduces aIS_GUTENBERG_PLUGIN
definition and uses that to avoid defining and calling these functions in WordPress coreAs part of that, I deleted
gutenberg_migrate_menu_to_navigation_post
which also calls those functions. That function isn't needed any more as the navigation area block is deprecated. This won't break any user content, as this migration is a side-effect rather than a main feature of the block.I also removed
gutenberg_get_navigation_areas_paths_to_preload
for the same reason.How has this been tested?
Testing that __unstableLocation works in the plugin
<!-- wp:navigation {"__unstableLocation":"primary"} /-->
Testing that __unstableLocation is disabled in core
lib/load.php
:Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).