Yoast / wordpress-seo

Yoast SEO for WordPress
https://yoast.com/wordpress/plugins/seo/
Other
1.75k stars 883 forks source link

Plugin calling exit() directly when it's loaded, would cause a fatal error in yoast shutdown callback #21061

Open menno-ll opened 7 months ago

menno-ll commented 7 months ago

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

  1. Make a php file inside the plugins directory
  2. Inside the file, paste
    <?php
    add_action(
    'plugins_loaded', function(): void {
        exit;
    }
    );
  3. Activate the plugin
  4. Visit any page of your website, it should result in a 500 error as shown above.

Expected results

  1. No 500 error should occur

Actual results

  1. 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/"
image

Technical info

Used versions

josevarghese commented 7 months ago

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.

menno-ll commented 13 hours ago

Hi @josevarghese , Unfortunately the PR has not yet been approved and merged. I received a suggestion, made a modification, re-requested a review and then the reviewer unassigned himself. And since then, nothing happened. Is there a possibility to have someone re-review it?

Please note this problem is also present in the premium version in the plugin. I'm not quite sure how changes from the free plugin are ported to the premium one, so might need to copy the solution over to there as well.

Thanks in advance!