Wp-rocket: PHP notices when updating

Created on 17 Mar 2020  ·  5Comments  ·  Source: wp-media/wp-rocket

Describe the bug
During the update process, 2 PHP notices appeared into the logs:

[17-Mar-2020 13:37:45 UTC] PHP Notice:  Undefined variable: home_root_escaped in /****/wp-content/plugins/wp-rocket/inc/functions/options.php on line 252
[17-Mar-2020 13:37:45 UTC] PHP Stack trace:
[17-Mar-2020 13:37:45 UTC] PHP   1. {main}() /****/wp-admin/admin-ajax.php:0
[17-Mar-2020 13:37:45 UTC] PHP   2. do_action() /****/wp-admin/admin-ajax.php:45
[17-Mar-2020 13:37:45 UTC] PHP   3. WP_Hook->do_action() /****/wp-includes/plugin.php:478
[17-Mar-2020 13:37:45 UTC] PHP   4. WP_Hook->apply_filters() /****/wp-includes/class-wp-hook.php:312
[17-Mar-2020 13:37:45 UTC] PHP   5. rocket_upgrader() /****/wp-includes/class-wp-hook.php:288
[17-Mar-2020 13:37:45 UTC] PHP   6. flush_rocket_htaccess() /****/wp-content/plugins/wp-rocket/inc/admin/upgrader.php:27
[17-Mar-2020 13:37:45 UTC] PHP   7. get_rocket_htaccess_marker() /****/wp-content/plugins/wp-rocket/inc/functions/htaccess.php:56
[17-Mar-2020 13:37:45 UTC] PHP   8. get_rocket_htaccess_mod_rewrite() /****/wp-content/plugins/wp-rocket/inc/functions/htaccess.php:148
[17-Mar-2020 13:37:45 UTC] PHP   9. get_rocket_cache_reject_uri() /****/wp-content/plugins/wp-rocket/inc/functions/htaccess.php:271
[17-Mar-2020 13:37:45 UTC] PHP Notice:  Undefined variable: home_root_len in /****/wp-content/plugins/wp-rocket/inc/functions/options.php on line 254
[17-Mar-2020 13:37:45 UTC] PHP Stack trace:
[17-Mar-2020 13:37:45 UTC] PHP   1. {main}() /****/wp-admin/admin-ajax.php:0
[17-Mar-2020 13:37:45 UTC] PHP   2. do_action() /****/wp-admin/admin-ajax.php:45
[17-Mar-2020 13:37:45 UTC] PHP   3. WP_Hook->do_action() /****/wp-includes/plugin.php:478
[17-Mar-2020 13:37:45 UTC] PHP   4. WP_Hook->apply_filters() /****/wp-includes/class-wp-hook.php:312
[17-Mar-2020 13:37:45 UTC] PHP   5. rocket_upgrader() /****/wp-includes/class-wp-hook.php:288
[17-Mar-2020 13:37:45 UTC] PHP   6. flush_rocket_htaccess() /****/wp-content/plugins/wp-rocket/inc/admin/upgrader.php:27
[17-Mar-2020 13:37:45 UTC] PHP   7. get_rocket_htaccess_marker() /****/wp-content/plugins/wp-rocket/inc/functions/htaccess.php:56
[17-Mar-2020 13:37:45 UTC] PHP   8. get_rocket_htaccess_mod_rewrite() /****/wp-content/plugins/wp-rocket/inc/functions/htaccess.php:148
[17-Mar-2020 13:37:45 UTC] PHP   9. get_rocket_cache_reject_uri() /****/wp-content/plugins/wp-rocket/inc/functions/htaccess.php:271

To Reproduce

  1. Install an old version of WP Rocket
  2. Clear the log file
  3. Update the plugin

Expected behavior
No new lines in the log file.

Additional context

  • I was updating WPR from 3.4.4 to 3.5.0.3
  • WordPress 5.3.2

Backlog Grooming

  • [x] Reproduce the problem
  • [x] Identify the root cause
  • [x] Scope a solution
  • [x] Estimate the effort
[S] low bug

All 5 comments

Identify the root cause ✅
inc/functions/options.php - get_rocket_cache_reject_uri() function
The root cause is the declaration of

        $home_root_escaped = preg_quote( $home_root, '/' );
        $home_root_len     = strlen( $home_root );

which is done in an if condition:
if ( '' !== $home_root && $uris ) {
These vars are used below and it seems that are not defined:
https://github.com/wp-media/wp-rocket/blob/8b2a567efcab3925dba6fff72c5a622ec2d16386/inc/functions/options.php#L198-L199

Scope a solution ✅
The solution will be to move the declaration of these 2 vars to be globally in this function.

Estimate the effort ✅
Effort: [S]
The effort will go in the Unit & Integration tests.

I just noticed the issue on mega/Divi and I can replicate it by enabling preload.

@GeekPress @hellofromtonya Shall we increase the priority of this issue? It's trivial, but since we know about it and since it's easy to fix, I feel we shouldn't let this reside in our code.

@arunbasillal The priority is set depending to the criticality of the issue. This one isn't critical and will be « low » because:

  • the error are displayed only into the logs
  • it doesn't break one of our feature
  • the number of ticket about this issue is very low

Related ticket:
https://secure.helpscout.net/conversation/1238067915/183094/

This error is logged when enabling our plugin:
[01-Aug-2020 11:54:49 UTC] PHP Notice Undefined variable: home_root_len in /var/www/vhosts/managed.hosting.com/managed.hosting.com/site/wp-content/plugins/wp-rocket/inc/functions/options.php on line 261

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Tabrisrp picture Tabrisrp  ·  5Comments

crystinutzaa picture crystinutzaa  ·  4Comments

webtrainingwheels picture webtrainingwheels  ·  5Comments

webtrainingwheels picture webtrainingwheels  ·  5Comments

webtrainingwheels picture webtrainingwheels  ·  5Comments