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

gutenberg_pre_init() does not prevent plugin from loading #27998

Closed
swissspidy opened this issue Jan 5, 2021 · 9 comments
Closed

gutenberg_pre_init() does not prevent plugin from loading #27998

swissspidy opened this issue Jan 5, 2021 · 9 comments
Labels
Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Type] Bug An existing feature does not function as intended

Comments

@swissspidy
Copy link
Member

Describe the bug

When using Gutenberg on WP < 5.3, gutenberg_pre_init() will trigger an admin notice and won't load lib/load.php because of that.

However, the rest of the code in gutenberg.php is still executed, including all the add_action calls, like gutenberg_menu().

That function in turn calls gutenberg_use_widgets_block_editor(), which only exists if load.php is loaded.

Because of that, on WP < 5.3 you will not get any admin notice, but instead this fatal error:

Fatal error: Call to undefined function gutenberg_use_widgets_block_editor() in /var/www/html/wp-content/plugins/gutenberg/gutenberg.php on line 47

To reproduce
Steps to reproduce the behavior:

  1. Try to activate Gutenberg on WP < 5.3 (e.g. by using wp-env)
  2. See fatal error

Expected behavior

Admin notice instead of fatal error

Screenshots
If applicable, add screenshots to help explain your problem.

Editor version (please complete the following information):

  • WordPress version: Anything below 5.3
  • Gutenberg version: 6.2

Additional context

@swissspidy swissspidy added [Type] Bug An existing feature does not function as intended Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts labels Jan 5, 2021
@noisysocks
Copy link
Member

We don't support versions less than 5.3.

* Requires at least: 5.3

@swissspidy
Copy link
Member Author

@noisysocks I think you misunderstood the purpose of this ticket. I'll try to explain it differently :)

I know that Gutenberg does not support WP < 5.3.

There's even this function that should warn the user about it:

gutenberg/gutenberg.php

Lines 139 to 151 in 35a94fd

/**
* Display a version notice and deactivate the Gutenberg plugin.
*
* @since 0.1.0
*/
function gutenberg_wordpress_version_notice() {
echo '<div class="error"><p>';
/* translators: %s: Minimum required version */
printf( __( 'Gutenberg requires WordPress %s or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ), '5.3.0' );
echo '</p></div>';
deactivate_plugins( array( 'gutenberg/gutenberg.php' ) );
}

However, it does not work as intended. Neither does gutenberg_build_files_notice run as intended.

That's because there's a fatal error happening before this code can even run.

This ticket is about this fatal error and how this logic needs to be fixed so that this notice is being displayed as intended.

@noisysocks
Copy link
Member

Ah! Thanks for clarifying 🙂

@xavortm
Copy link

xavortm commented Jan 12, 2021

I have just installed WordPress-Develop and on latest master + latest master Gutenberg repository, I am still getting this fatal error after activating the plugin :/

Fatal error: Uncaught Error: Call to undefined function gutenberg_use_widgets_block_editor() in /var/www/src/wp-content/plugins/gutenberg/gutenberg.php:128 Stack trace: #0 /var/www/src/wp-includes/class-wp-hook.php(292): modify_admin_bar(Object(WP_Admin_Bar)) #1 /var/www/src/wp-includes/class-wp-hook.php(316): WP_Hook->apply_filters(NULL, Array) #2 /var/www/src/wp-includes/plugin.php(551): WP_Hook->do_action(Array) #3 /var/www/src/wp-includes/admin-bar.php(95): do_action_ref_array('admin_bar_menu', Array) #4 /var/www/src/wp-includes/class-wp-hook.php(292): wp_admin_bar_render('') #5 /var/www/src/wp-includes/class-wp-hook.php(316): WP_Hook->apply_filters('', Array) #6 /var/www/src/wp-includes/plugin.php(484): WP_Hook->do_action(Array) #7 /var/www/src/wp-includes/general-template.php(3037): do_action('wp_body_open') #8 /var/www/src/wp-content/themes/twentytwentyone/header.php(24): wp_body_open() #9 /var/www/src/wp-includes/template.php(730): require_once('/var/www/src/wp...') #10 /var/www/src/wp-includes/template.php(676): in /var/www/src/wp-content/plugins/gutenberg/gutenberg.php on line 128

So the WP version is 5.7, not <5.3; Gutenberg v.9.7.1

I might be missing something obvious, it's my first time setting up the two. Considering how the fatal error showed up right after doing the latest pull from both, I guess I might be wrong as I am not finding it reported, but still, posting if it helps. Apologies if this needs a separate ticket

@swissspidy
Copy link
Member Author

@xavortm Since you are using Gutenberg master Have you built Gutenberg properly? npm install && npm run build

@xavortm
Copy link

xavortm commented Jan 12, 2021

Apologies :( I did npm install and then npm run build, the same error shows up. It was after the npm run dev that worked. Sorry!

@bph
Copy link
Contributor

bph commented Jan 14, 2021

I saw the flaw in my logic just before I went to sleep - there is no concern for backwards compatibility at all.
Either a user is using an older version with the block-editor's capabilities of that time, or they are on a new WordPress version 5.5 +. Neither version would have problems. This only concerns the Gutenberg plugin and with setting the minimum requirement to WordPress 5.5 this seems to be sufficiently handled.

It's very likely, I am missing something essential, though. Please forgive my ignorance.
Turns out I did. Thanks to @swissspidy for the 'confused' signal.

@gziolo
Copy link
Member

gziolo commented Mar 25, 2021

The mix of #30230 and #29938 should address this issue.

@gziolo
Copy link
Member

gziolo commented Aug 5, 2021

The mix of #30230 and #29938 should address this issue.

Both PRs landed a while ago. Let's close this issue.

@gziolo gziolo closed this as completed Aug 5, 2021
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

No branches or pull requests

5 participants