Undefined offset: 0 in WordPress after latest version upgrade
My WordPress powered website always worked great, however after the latest upgrade to 5.6.2 and 5.7 I have a major issue that actually breaks an important part of the website, I have seen to go through the logs and found the following error:
[14-Mar-2021 00:29:32 UTC] PHP Notice: Undefined offset: 0 in /var/www/html/wp-content/plugins/tours/includes/class-tours-tour-post-type.php on line 1709
[14-Mar-2021 00:29:32 UTC] selected_original_tours:
The code in question seems to be the following:
if($show_filter) {
$selected_destinations = isset($_GET['destinations']) ? explode(',', $_GET['destinations']) : [];
$selected_tourstyles = isset($_GET['tourstyles']) ? explode(',', $_GET['tourstyles']) : [];
write_log('selected_original_tours: ' . $selected_tourstyles[0]);
for($i = 0; $i count($selected_tourstyles); $i++) {
$selected_tourstyles[$i] = str_replace('and', '', $selected_tourstyles[$i]);
$selected_tourstyles[$i] = str_replace('_', ' ', $selected_tourstyles[$i]);
write_log('Selected_tourstyles:' . $selected_tourstyles[$i]);
}
$selected_dates = isset($_GET['dates']) ? explode(',', $_GET['dates']) : [];
}
So the line in question must be:
write_log('selected_original_tours: ' . $selected_tourstyles[0]);
The upgrade always worked seamlessly, however since 5.6.2 and 5.7 something must have changed within WordPress. Since I do not have contact with the original developer any longer it would be great if someone could help me address this or change the affected code in order to have my function work again? Some expert advice would be greatly appreciated.