Argument 2 ($url) passed to exclude_rocket_from_wp_updates() must be of the type string
Describe the bug User reported the following error with version 3.17.1 (incomplete stack trace was provided):
Se ha producido un error del tipo E_ERROR en la línea 135 del archivo /home/customer/www/isodeco.net/public_html/wp-content/plugins/wp-rocket/inc/Engine/Plugin/UpdaterSubscriber.php. Mensaje de error: Uncaught TypeError: Argument 2 passed to WP_Rocket\Engine\Plugin\UpdaterSubscriber::exclude_rocket_from_wp_updates() must be of the type string, null given, called in /home/customer/www/isodeco.net/public_html/wp-includes/class-wp-hook.php on line 324 and defined in /home/customer/www/isodeco.net/public_html/wp-content/plugins/wp-rocket/inc/Engine/Plugin/UpdaterSubscriber.php:135
Stack trace:
#0 /home/customer/www/isodeco.net/public_html/wp-includes/class-wp-hook.php(324): WP_Rocket\Engine\Plugin\UpdaterSubscriber->exclude_rocket_from_wp_updates(Array, NULL)
#1 /home/customer/www/isodeco.net/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array)
#2 /home/customer/www/isodeco.net/public_html/wp-includes/class-wp-http.php(234): apply_filters('http_request_ar...', Array, NULL)
#3 /home/customer/www/isodeco.net/public_html/wp-includes/class-wp-http.php(638): WP_Http->request(NULL, Array)
#4 /home/customer/www/isodeco.net/public_html/wp-includes/http.php(184): WP_Http->get(NULL, Array)
#5 /h
It relates to this line: https://github.com/wp-media/wp-rocket/blob/ce7b6014eba3777825b2a4cacf942f6b0e7300be/inc/Engine/Plugin/UpdaterSubscriber.php#L135
I can see a recent update to the related method here: https://github.com/wp-media/wp-rocket/commit/73488699424f726bef28dbf2c934340efcab8e47 https://imageshack.com/a/img922/4788/YNsWPZ.png
The change removed the check to make sure $url is a string, and it opens us up to errors like these.
To Reproduce Steps to reproduce the behavior:
- Update to version 3.17.1
- Not sure exactly what other condition is required. Could be a conflict with another plugin or theme.
- Anything that could cause the
$urlparameter to not be of typestring.
Expected behavior
We should check to confirm the $url parameter is a string to prevent this error from happening.
Additional context Ticket - https://secure.helpscout.net/conversation/2737001255/518317 Slack - https://wp-media.slack.com/archives/C43T1AYMQ/p1729176825682779
Related: https://secure.helpscout.net/conversation/2737958899/518476/
The complete stack trace is in the ticket above
related: https://secure.helpscout.net/conversation/2739225788/518711?folderId=2683093
another one: https://secure.helpscout.net/conversation/2740067797/518850?folderId=2008123
error stack
/public/wp-content/plugins/wp-rocket/inc/Engine/Plugin/UpdaterSubscriber.php on line 135
[21-Oct-2024 08:37:27 UTC] PHP Fatal error: Uncaught TypeError: WP_Rocket\Engine\Plugin\UpdaterSubscriber::exclude_rocket_from_wp_updates(): Argument #2 ($url) must be of type string, null given, called in /public/wp-includes/class-wp-hook.php on line 324 and defined in /public/wp-content/plugins/wp-rocket/inc/Engine/Plugin/UpdaterSubscriber.php:135
Stack trace:
#0 /public/wp-includes/class-wp-hook.php(324): WP_Rocket\Engine\Plugin\UpdaterSubscriber->exclude_rocket_from_wp_updates()
#1 /public/wp-includes/plugin.php(205): WP_Hook->apply_filters()
#2 /public/wp-includes/class-wp-http.php(234): apply_filters()
#3 /public/wp-includes/class-wp-http.php(638): WP_Http->request()
#4 /public/wp-includes/http.php(184): WP_Http->get()
**#5 /public/wp-content/plugins/bizreview-pro/inc/google-review/google-api-config.php(50): wp_remote_get()**
#6 /public/wp-content/plugins/bizreview-pro/inc/functions.php(28): BizReview_Google_API->get_place_data()
#7 /public/wp-includes/class-wp-hook.php(324): bizreview_google_api()
The same thing here on 3 websites after updating from 3.17.0.2 to 3.17.1
Related: https://secure.helpscout.net/conversation/2736553837/518231
related: https://secure.helpscout.net/conversation/2742392632/519264?folderId=273761 https://secure.helpscout.net/conversation/2739071952/518691
I think we have few instances where $url is not set.
Scope a solution ✅
We can add a nullable type hint to the ?string $url here and a condition to check if $url is not string
if( is_null( $url ) ) {
return $request;
}
Estimate the effort ✅
[XS]
IMO, we should revert to what was there before: no typehint in the method declaration, and a check for is_string() inside the method. We can't know if a plugin will be modifying the URL value to a specific type, some plugins use null, others might use false.
Related: https://secure.helpscout.net/conversation/2743534579/519516
Related: https://secure.helpscout.net/conversation/2748931857/520442
I'm still experiencing this issue in the latest WP Rocket version (v3.17.2).
Steps to reproduce the behavior: Just load the WP plugins page (/wp-admin/plugins.php)
I'm getting the following error:
Fatal error: Uncaught TypeError: WP_Rocket\Engine\Plugin\UpdaterSubscriber::exclude_rocket_from_wp_updates(): Argument #2 ($url) must be of type string, null given, called in /home/terroir/public_html/wp-includes/class-wp-hook.php on line 324 and defined in /home/terroir/public_html/wp-content/plugins/wp-rocket/inc/Engine/Plugin/UpdaterSubscriber.php:135 Stack trace: #0 /home/terroir/public_html/wp-includes/class-wp-hook.php(324): WP_Rocket\Engine\Plugin\UpdaterSubscriber->exclude_rocket_from_wp_updates(Array, NULL) #1 /home/terroir/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array) #2 /home/terroir/public_html/wp-includes/class-wp-http.php(234): apply_filters('http_request_ar...', Array, NULL) #3 /home/terroir/public_html/wp-includes/class-wp-http.php(638): WP_Http->request(NULL, Array) #4 /home/terroir/public_html/wp-includes/http.php(184): WP_Http->get(NULL, Array) #5 /home/terroir/public_html/wp-content/plugins/hmenu/classes/core/checkin.class.php(42): wp_remote_get(NULL) #6 /home/terroir/public_html/wp-includes/class-wp-hook.php(326): hmenu_checkin->hmenu_check_in(Object(stdClass)) #7 /home/terroir/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters(Object(stdClass), Array) #8 /home/terroir/public_html/wp-includes/option.php(2576): apply_filters('pre_set_site_tr...', Object(stdClass), 'update_plugins') #9 /home/terroir/public_html/wp-includes/update.php(394): set_site_transient('update_plugins', Object(stdClass)) #10 /home/terroir/public_html/wp-includes/class-wp-hook.php(324): wp_update_plugins('') #11 /home/terroir/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #12 /home/terroir/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #13 /home/terroir/public_html/wp-admin/admin.php(385): do_action('load-plugins.ph...') #14 /home/terroir/public_html/wp-admin/plugins.php(10): require_once('/home/terroir/p...') #15 {main} thrown in /home/terroir/public_html/wp-content/plugins/wp-rocket/inc/Engine/Plugin/UpdaterSubscriber.php on line 135
As a temporary workaround, I've edited the maybe_set_rocket_user_agent() function in UpdaterApiCommonSubscriber.php to check if $url is a string:
if ( ! is_string( $url ) ) {
return $request;
}
However, after applying this fix, I encountered another fatal error, so I had to apply the same fix to the exclude_rocket_from_wp_updates() function in UpdaterSubscriber.php.
I hope this information is helpful in resolving this issue.
Hello @salvia34 the issue is will be fixed in the 3.17.3 version of WP Rocket. The proposed fix can be seen here: https://github.com/wp-media/wp-rocket/pull/7059/files
Related Issue: https://secure.helpscout.net/conversation/2756375620/521828/
Related: https://secure.helpscout.net/conversation/2762917106/523258/