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.