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
Expected behavior
No new lines in the log file.
Additional context
Backlog Grooming
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:
Related ticket: https://secure.helpscout.net/conversation/1171062698/166759?folderId=273764#thread-3340520759
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