Issue and Potential Fix Regarding Property Access in Mappress_Poi Class

Home Forums MapPress Support Issue and Potential Fix Regarding Property Access in Mappress_Poi Class

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #20511
    Myluxurytravel
    Participant

    Hi Support,

    I’ve encountered an issue with the MapPress Maps plugin that I wanted to share with you, along with a potential fix. The goal was to create a dynamic map using MapPress, with Points of Interest (POIs) specified dynamically through our PHP code,

    Issue:
    When utilizing the plugin, PHP Notices are being generated regarding attempts to access properties on a non-object within the mappress_poi.php file:

    PHP Notice: Trying to get property ‘lat’ of non-object in /path_to_file/mappress_poi.php on line [line_number]
    PHP Notice: Trying to get property ‘lng’ of non-object in /path_to_file/mappress_poi.php on line [line_number]

    Upon investigating the code, it seems like the issue is occurring in the to_html() method where $this->point is being accessed as if it’s an object:

    $vars->point = (isset($this->point)) ? $this->point->lat . ‘,’ . $this->point->lng : ”;

    However, within the Mappress_Poi class, $point is declared and initialized as an associative array:

    $point = array(‘lat’ => 0, ‘lng’ => 0);
    This discrepancy in access method vs. declaration seems to be the root cause of the issue.

    Proposed Fix:
    Modifying the to_html() method to access $this->point as an array appears to resolve the issue without generating the PHP Notices:

    $vars->point = (isset($this->point)) ? $this->point[‘lat’] . ‘,’ . $this->point[‘lng’] : ”;

    Request:
    Could you please consider validating and possibly incorporating this adjustment in a future plugin update to prevent the aforementioned PHP Notices from occurring? The modification aligns with the current variable type declaration and seems to be coherent with the intended use of $point.

    #20537
    Chris
    Keymaster

    Hi,

    I’m sorry I didn’t respond sooner. The warning notice doesn’t appear on my test sites. How are you generating the maps? Are you using PHP, or a shortcode, or a block?

    In any case, this should be fixed in 2.88.9, which should accept both arrays and objects.

    #20553
    Myluxurytravel
    Participant

    Hi there. yes it was with php.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.