0

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.

1
  • Hello and welcome. Not all of us have a perfect encyclopedic knowledge of the internals. It would certainly help me (and probably others) to know which files these code blocks come from. – Matthew Brown aka Lord Matt Mar 14 at 11:05
0

Not all of us have a perfect encyclopedic knowledge of the internals. It would certainly help me (and probably others) to know which files these code blocks come from.

All I can tell you at the moment is that $selected_tourstyles is probably an empty array if it is an array at all.

To debug look for where $_GET['tourstyles'] is coming from. Probably a link or a form. It could be that the link or form is not getting the data to put into the query string.

You could try wrapping:

write_log('selected_original_tours: ' . $selected_tourstyles[0]);

with:

if(count($selected_tourstyles)>0){
    write_log('selected_original_tours: ' . $selected_tourstyles[0]);
}

This will only run that line if the array has something in it. I have no earthly idea if that will be good for the overall design of whatever this code does.

Not the answer you're looking for? Browse other questions tagged or ask your own question.