PHP Warning: Undefined array key

Home Forums AdRotate for WordPress Bug Reports PHP Warning: Undefined array key

  • #147478

    Been getting quite a few of these “PHP Warning: Undefined array key” from adrotate-functions.php.

    Looks to be related to the geo lookups (we may be at our limit of lookups). This is using the latest version of the plugin and php 8.

    Fixed this by putting “guards” in place at key points indicate by HERE We cleaned these up one by one and it’s possible not all the guards are needed once you have the first one.

    Would be great to include this in the next update to avoid regressing this issue!

    Thanks!

    function adrotate_filter_location($selected, $banner) {
    // Grab geo data from session
    if (array_key_exists('adrotate-geo', $_SESSION)) { // HERE
    $geo = $_SESSION['adrotate-geo'];
    if (is_array($geo) AND array_key_exists('code', $geo)) { // HERE
    //if(is_array($geo)) { // HERE
    ...
    if (is_array($geo_result) AND array_key_exists('code', $geo_result) AND array_key_exists('message', $geo_result)) { // HERE
    set_transient('ajdg_geo_response', array('code' => $geo_result['code'], 'message' => $geo_result['message'], 'last_checked' => date_i18n('F j, Y, g:i a')), 43200); // Expire in 6 hours
    } // HERE 
    } // HERE

    #147480

    Arnan de Gans
    Badges:

    Hi Jonathan, a fix is being tested for the next version already. But thanks for your input and report.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

You may be interested in