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

Update WP compatibility check in gutenberg_pre_init() #29938

Merged
merged 4 commits into from
Apr 14, 2021

Conversation

jeremyfelt
Copy link
Member

@jeremyfelt jeremyfelt commented Mar 17, 2021

Description

This updates the version_compare() check in gutenberg_pre_init() in a few ways:

  1. Move from requiring 5.3 to 5.6. The plugin relies on WP_Block_Supports, which was added in WP 5.6, and register_block_format(), which was added in WP 5.5.
  2. Fix the version comparison. WordPress reports its version as 5.7 rather than 5.7.0. version_compare( '5.7', '5.7.0', '<' ) evaluates as true, which puts 5.7.1 as the actual minimum version. When compatibility is checked against a major WP release, the X.Y version number should be used. See previously, Gutenberg is not compatible with WordPress 5.0 #15565.
  3. After adding an admin notice, the plugin bails with return; and Gutenberg libraries are not loaded. Other hooks are added by the plugin that require those libraries, and a fatal error occurs rather than a compatibility notice. This removes the return, which helps to eliminate immediate fatal errors and allows the notice to be shown.

A (likely preferable) alternative to item 3 would be to remove all other functionality from the main plugin file so that it too is only loaded when gutenberg_pre_init() fires successfully.

Current culprits appear to be:

  • modify_welcome_panel()
  • modify_admin_bar()
  • gutenberg_site_editor_menu()
  • gutenberg_menu()

How has this been tested?

I've tested by updating core back and forth between WP 5.3, 5.5, 5.6, and 5.7 while the plugin is in an active an inactive state.

Types of changes

Bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • [NA] My code follows the accessibility standards.
  • [NA] I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • [NA] I've updated all React Native files affected by any refactorings/renamings in this PR.

The plugin relies on `WP_Block_Supports`, which was added in 5.6
and `register_block_format()`, which was added in 5.5.
When `return` is used here, Gutenberg is not loaded and the other
hooks added in this file use functions that are only loaded with
Gutenberg.
@jeremyfelt
Copy link
Member Author

I don't see how the end-to-end test failure is related to this change and I don't have the capability to restart the job to see if it's just a one-off issue. Happy to fix anything if needed! :)

@gziolo gziolo requested review from mcsf and aristath March 18, 2021 10:20
@gziolo gziolo added Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Type] Bug An existing feature does not function as intended labels Mar 18, 2021
@gziolo
Copy link
Member

gziolo commented Mar 18, 2021

I don't see how the end-to-end test failure is related to this change and I don't have the capability to restart the job to see if it's just a one-off issue. Happy to fix anything if needed! :)

Yes, it looks unrelated. E2E tests don't run with the older versions of WordPress. I re-triggered those tests.

@paaljoachim
Copy link
Contributor

Hey

I just want to say that I tried activating the Gutenberg plugin 10.2.1 on an older WP site that is running 5.3.6.
It would not activate and gave the message that the plugin could not be activated as a fatal error was detected (loosely translated from Norwegian).
It would be helpful if it also mentioned update to the newest version of WordPress to be able to use a new version of Gutenberg.

Activating-Gutenberg-10-2-1-on-older-site.mp4

gutenberg.php Show resolved Hide resolved
@gziolo
Copy link
Member

gziolo commented Mar 23, 2021

I see another line where 5.3 is hardcoded:

printf( __( 'Gutenberg requires WordPress %s or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ), '5.3.0' );

We should probably move the version to the constant to make it easier to upgrade in the future.

@swissspidy
Copy link
Member

Previously reported in #27998

@jeremyfelt
Copy link
Member Author

I'll update the PR to add the return statement back in. #30230 is excellent. 👍🏻

We should probably move the version to the constant to make it easier to upgrade in the future.

function print_production_defines() {

Does it complicate things too much to add this to print_production_defines()? If I understand how that file is used, it could then be automatically generated based on the plugin header's required version.

Previously reported in #27998

I completely missed this! 🤦🏻

@gziolo
Copy link
Member

gziolo commented Mar 26, 2021

I landed #30230 to unblock this PR.

Does it complicate things too much to add this to print_production_defines()? If I understand how that file is used, it could then be automatically generated based on the plugin header's required version.

I thought about a simpler approach where we define the constant in the file, but given that we need it only on production, we can take a more complex path 😄 I leave it up to you to decide. The solution you mentioned has the benefit of updating only the minimum version in the plugin's metadata moving forward. The downside is that we would not have access to this constant in development mode, so we would have to account for that somehow.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

This should be good to go now with the changes I applied.

@gziolo gziolo merged commit 2864336 into WordPress:trunk Apr 14, 2021
@github-actions github-actions bot added this to the Gutenberg 10.5 milestone Apr 14, 2021
@gziolo
Copy link
Member

gziolo commented Apr 14, 2021

It works great now in my testing when using the latest trunk.

@jeremyfelt jeremyfelt deleted the fix/gutenberg-wp-version-check branch June 7, 2021 00:20
walbo pushed a commit to walbo/gutenberg that referenced this pull request Jul 2, 2021
Minimum required WP version is 5.6 (WordPress#29701 and WordPress#29938). `wp_filter_content_tags` was added in 5.5 so these checks is no longer needed.
aristath pushed a commit that referenced this pull request Jul 5, 2021
…33182)

Minimum required WP version is 5.6 (#29701 and #29938). `wp_filter_content_tags` was added in 5.5 so these checks is no longer needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants