wordpress-seo
wordpress-seo copied to clipboard
Plugin calling exit() directly when it's loaded, would cause a fatal error in yoast shutdown callback
- [x] I've read and understood the contribution guidelines.
- [x] I've searched for any related issues and avoided creating a duplicate issue.
Please give us a description of what happened
Yoast uses the shutdown hook in class-yoast-notification-center.php to perform some stuff. Inside the callback function, Yoast will use some wordpress functions. If there is a plugin that calls the exit() function on the plugins_loaded hook, this would result in an error, which i will place below.
2024/01/19 12:03:50 [error] 1928165#1928165: *3550890 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to undefined function get_userdata() in /srv/http/shared/www/wp-includes/user.php:673
Stack trace:
#0 /srv/http/shared/deploys/releases/20240118064815/plugins/wordpress-seo/admin/class-yoast-notification-center.php(940): get_user_option('yoast_notificat...', 0)
#1 /srv/http/shared/deploys/releases/20240118064815/plugins/wordpress-seo/admin/class-yoast-notification-center.php(927): Yoast_Notification_Center->get_stored_notifications()
#2 /srv/http/shared/deploys/releases/20240118064815/plugins/wordpress-seo/admin/class-yoast-notification-center.php(913): Yoast_Notification_Center->has_stored_notifications()
#3 /srv/http/shared/deploys/releases/20240118064815/plugins/wordpress-seo/admin/class-yoast-notification-center.php(623): Yoast_Notification_Center->remove_storage()
#4 /srv/http/shared/www/wp-includes/class-wp-hook.php(310): Yoast_Notification_Center->update_storage('')
#5 /srv/http/shared/www/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters" while reading response header from upstream, client: 10.0.3.1, server: _, request: "POST /wp-admin/admin-ajax.php?action=koko_analytics_collect&p=17378&nv=1&up=1&r=https%3A%2F%2Fwww.google.com%2F HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "example.com", referrer: "https://example.com/some-url/"
The reason this happens, is that WordPress loads it's pluggable.php file later than the plugins_loaded hook. And therefore, it's not loaded at this stage.
The fix should be quite simple. By adding require_once ABSPATH . 'wp-includes/pluggable.php'; to the shutdown callback function, this issue can be resolved.
I will make a PR to resolve this issue.
To Reproduce
Step-by-step reproduction instructions
- Make a php file inside the plugins directory
- Inside the file, paste
<?php
add_action(
'plugins_loaded', function(): void {
exit;
}
);
- Activate the plugin
- Visit any page of your website, it should result in a 500 error as shown above.
Expected results
- No 500 error should occur
Actual results
- An 500 error occurs
Screenshots, screen recording, code snippet
If possible, please provide a screenshot, a screen recording or a code snippet which demonstrates the bug.
2024/01/19 12:03:50 [error] 1928165#1928165: *3550890 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to undefined function get_userdata() in /srv/http/shared/www/wp-includes/user.php:673
Stack trace:
#0 /srv/http/shared/deploys/releases/20240118064815/plugins/wordpress-seo/admin/class-yoast-notification-center.php(940): get_user_option('yoast_notificat...', 0)
#1 /srv/http/shared/deploys/releases/20240118064815/plugins/wordpress-seo/admin/class-yoast-notification-center.php(927): Yoast_Notification_Center->get_stored_notifications()
#2 /srv/http/shared/deploys/releases/20240118064815/plugins/wordpress-seo/admin/class-yoast-notification-center.php(913): Yoast_Notification_Center->has_stored_notifications()
#3 /srv/http/shared/deploys/releases/20240118064815/plugins/wordpress-seo/admin/class-yoast-notification-center.php(623): Yoast_Notification_Center->remove_storage()
#4 /srv/http/shared/www/wp-includes/class-wp-hook.php(310): Yoast_Notification_Center->update_storage('')
#5 /srv/http/shared/www/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters" while reading response header from upstream, client: 10.0.3.1, server: _, request: "POST /wp-admin/admin-ajax.php?action=koko_analytics_collect&p=17378&nv=1&up=1&r=https%3A%2F%2Fwww.google.com%2F HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "example.com", referrer: "https://example.com/some-url/"
Technical info
- If relevant, which editor is affected (or editors):
- [ ] Block Editor
- [ ] Gutenberg Editor
- [ ] Elementor Editor
- [ ] Classic Editor
- [x] Other: NotificationCenter on shutdown
- Which browser is affected (or browsers):
- [x] Chrome
- [x] Firefox
- [x] Safari
- [x] Other: Any browser
Used versions
- Device you are using: Macbook pro 13-inch, 2020, Four Thunderbolt 3 ports
- Operating system: 14.1.2 (23B92)
- PHP version: 8.0
- WordPress version: 6.4
- WordPress Theme: Custom
- Yoast SEO version: 21.8
- Gutenberg plugin version:
- Elementor plugin version:
- Classic Editor plugin version:
- Relevant plugins in case of a bug: Koko Analytics https://wordpress.org/plugins/koko-analytics/
Hi @menno-ll
Thanks for using the Yoast SEO plugin and for creating the PR. Our development team will review the PR you have provided and will keep you posted.