Please note that caution has to be used when manipulating the Maps Marker Pro database directly via the API to avoid data loss. All calls are immediate and cannot be undone.
Please also be aware that our support does not cover detailed questions about custom developement based on this API.
Usage
To use the DB API, we first have to instantiate the class:
$db = new MMP\DB();
Maps return objects with the following properties:
id: ID name: Name settings: An object containing the map settings (JSON encoded) filters: An object containing the map filters (JSON encoded) created_by_id: The ID of the user who created the map created_on: The date and time when the map was created updated_by_id: The ID of the user who last updated the map updated_on: The date and time when the map was last updated markers: The number of markers that are assigned to this map (if requested)
Markers return objects with the following properties:
id: ID name: Name address: Address lat: Latitude lng: Longitude zoom: Zoom icon: Icon filename popup: Popup contents link: URL to be opened instead of showing a popup created_by_id: The ID of the user who created the marker created_on: The date and time when the marker was created updated_by_id: The ID of the user who last updated the marker updated_on: The date and time when the marker was last updated maps: Array of map IDs that the marker is assigned to
Examples
Get the map with ID 1, change the name, width and height and save the changes
$map = $db->get_map(1); $map->name = 'Car dealerships'; $settings = json_decode($map->settings); $settings->width = 640; $settings->height = 480; $map->settings = json_encode($settings); $db->update_map($map, 1);
Get the marker with ID 1, change the name, icon and popup and save the changes
$marker = $db->get_marker(1); $marker->name = 'Dealership 1'; $marker->icon = 'car.png'; $marker->popup = '<a href="https://example.com">Dealership 1 website</a>'; $db->update_marker($marker, 1);
Method Reference
create_tables()
Creates the database tables
Parameters
This method has no parameters
Return Values
No value is returned
Changelog
Version | Description |
---|---|
4.0 | Introduced |
delete_tables()
Deletes the database tables
Parameters
This method has no parameters
Return Values
No value is returned
Changelog
Version | Description |
---|---|
4.0 | Introduced |
reset_tables()
Resets the database tables
Parameters
This method has no parameters
Return Values
No value is returned
Changelog
Version | Description |
---|---|
4.0 | Introduced |
count_maps($filters = array())
Returns the total number of maps
Optionally accepts a list of filters
Parameters
- $filters
- (array) (optional) List of filters
Return Values
(int) Total number of maps
Changelog
Version | Description |
---|---|
4.0 | Introduced |
get_map($id, $count = false)
Returns the map for the given ID
Parameters
- $id
- (int) Map ID
- $count
- (bool) (optional) Whether to count the assigned markers
Return Values
(object|null) Map object or null if no result is found
Changelog
Version | Description |
---|---|
4.0 | Introduced |
get_maps($ids, $count = false)
Returns the maps for the given IDs
Parameters
- $ids
- (array|string) List or CSV of map IDs
- $count
- (bool) (optional) Whether to count the assigned markers
Return Values
(array) List of map objects
Changelog
Version | Description |
---|---|
4.0 | Introduced |
get_all_maps($count = false, $filters = array())
Returns all maps
Optionally accepts a list of filters
Parameters
- $count
- (bool) (optional) Whether to count the assigned markers
- $filters
- (array) (optional) List of filters
Return Values
(array) List of map objects
Changelog
Version | Description |
---|---|
4.0 | Introduced |
get_map_shortcodes($id)
Returns all posts that use a shortcode for the given map ID
Parameters
- $id
- (int) Map ID
Return Values
(array) List of posts
Changelog
Version | Description |
---|---|
4.0 | Introduced |
add_map($data, $id = 0)
Adds a map
Parameters
- $data
- (object) Map data to be written
- $id
- (int) (optional) ID for the new map
Return Values
(int|bool) Map ID or false if the map could not be added
Changelog
Version | Description |
---|---|
4.0 | Introduced |
add_maps($data)
Adds multiple maps
Parameters
- $data
- (array) List of map data to be written
Return Values
(int|bool) Number of affected rows or false if the maps could not be added
Changelog
Version | Description |
---|---|
4.0 | Introduced |
update_map($data, $id)
Updates a map
Parameters
- $data
- (object) Map data to be written
- $id
- (int) ID of the map to be updated
Return Values
(int|bool) Number of affected rows or false if the map could not be updated
Changelog
Version | Description |
---|---|
4.0 | Introduced |
update_maps($data, $ids)
Updates multiple maps
Parameters
- $data
- (object) Map data to be written
- $ids
- (array|string) List or CSV of map IDs
Return Values
(int) Number of affected rows
Changelog
Version | Description |
---|---|
4.0 | Introduced |
delete_map($id)
Deletes a map and its relationships
Parameters
- $id
- (int) ID of the map to be deleted
Return Values
(int|bool) Number of affected rows or false if the map could not be deleted
Changelog
Version | Description |
---|---|
4.0 | Introduced |
delete_maps($ids)
Deletes multiple maps and their relationships
Parameters
- $ids
- (array|string) List or CSV of map IDs
Return Values
(int|bool) Number of affected rows or false if the maps could not be deleted
Changelog
Version | Description |
---|---|
4.0 | Introduced |
count_markers($filters = array())
Returns the total number of markers
Optionally accepts a list of filters
Parameters
- $filters
- (array) (optional) List of filters
Return Values
(int) Total number of markers
Changelog
Version | Description |
---|---|
4.0 | Introduced |
count_map_markers($id)
Returns the total number of markers for the given map ID
Parameters
- $id
- (int) Map ID
Return Values
(int) Total number of markers for the given map ID
Changelog
Version | Description |
---|---|
4.0 | Introduced |
get_marker($id)
Returns the marker for the given ID
Parameters
- $id
- (int) Marker ID
Return Values
(object|null) Marker object or null if no result is found
Changelog
Version | Description |
---|---|
4.0 | Introduced |
get_markers($ids)
Returns the markers for the given IDs
Parameters
- $ids
- (array|string) List or CSV of marker IDs
Return Values
(array) List of marker objects
Changelog
Version | Description |
---|---|
4.0 | Introduced |
get_all_markers($filters = array())
Returns all markers
Optionally accepts a list of filters
Parameters
- $filters
- (array) (optional) List of filters
Return Values
(array) List of marker objects
Changelog
Version | Description |
---|---|
4.0 | Introduced |
get_map_markers($id)
Returns the markers for the given map ID
Parameters
- $id
- (int) Map ID
Return Values
(array) List of marker objects
Changelog
Version | Description |
---|---|
4.0 | Introduced |
get_maps_markers($ids)
Returns the markers for the given map IDs
Parameters
- $ids
- (int) Map IDs
Return Values
(array) List of marker objects
Changelog
Version | Description |
---|---|
4.0 | Introduced |
add_marker($data, $id = 0)
Adds a marker
Parameters
- $data
- (object) Marker data to be written
- $id
- (int) (optional) ID for the new marker
Return Values
(int|bool) Marker ID or false if the marker could not be added
Changelog
Version | Description |
---|---|
4.0 | Introduced |
add_markers($data)
Adds multiple markers
Parameters
- $data
- (array) List of marker data to be written
Return Values
(int|bool) Number of affected rows or false if the markers could not be added
Changelog
Version | Description |
---|---|
4.0 | Introduced |
update_marker($data, $id)
Updates a marker
Parameters
- $data
- (object) Marker data to be written
- $id
- (int) ID of the marker to be updated
Return Values
(int|bool) Number of affected rows or false if the marker could not be updated
Changelog
Version | Description |
---|---|
4.0 | Introduced |
update_markers($data, $ids)
Updates multiple markers
Parameters
- $data
- (object) Marker data to be written
- $ids
- (array|string) List or CSV of marker IDs
Return Values
(int|bool) Number of affected rows or false if the markers could not be updated
Changelog
Version | Description |
---|---|
4.0 | Introduced |
assign_marker($map_id, $marker_id)
Assigns a marker to a map
Parameters
- $map_id
- (int) Map ID
- $marker_id
- (int) Marker ID
Return Values
(int|bool) Number of affected rows or false if the marker could not be assigned
Changelog
Version | Description |
---|---|
4.0 | Introduced |
assign_markers($map_id, $marker_ids)
Assigns multiple markers to a map
Parameters
- $map_id
- (int) Map ID
- $marker_ids
- (array|string) List or CSV of marker IDs
Return Values
(int|bool) Number of affected rows or false if the markers could not be assigned
Changelog
Version | Description |
---|---|
4.0 | Introduced |
assign_maps_marker($map_ids, $marker_id)
Assigns a marker to multiple maps
Parameters
- $map_ids
- (array|string) List or CSV of map IDs
- $marker_id
- (int) Marker ID
Return Values
(int|bool) Number of affected rows or false if the marker could not be assigned
Changelog
Version | Description |
---|---|
4.0 | Introduced |
assign_maps_markers($map_ids, $marker_ids)
Assigns multiple markers to multiple maps
Parameters
- $map_ids
- (array|string) List or CSV of map IDs
- $marker_ids
- (array|string) List or CSV of marker IDs
Return Values
(int|bool) Number of affected rows or false if the markers could not be assigned
Changelog
Version | Description |
---|---|
4.0 | Introduced |
assign_assoc($assoc)
Assigns markers from an associative list
Parameters
- $assoc
- (array) Associative list of marker ID => map IDs
Return Values
(int|bool) Number of affected rows or false if the markers could not be assigned
Changelog
Version | Description |
---|---|
4.9 | Introduced |
unassign_marker($map_id, $marker_id)
Unassigns a marker from a map
Parameters
- $map_id
- (int) Map ID
- $marker_id
- (int) Marker ID
Return Values
(int|bool) Number of affected rows or false if the marker could not be unassigned
Changelog
Version | Description |
---|---|
4.0 | Introduced |
unassign_markers($map_id, $marker_ids)
Unassigns multiple markers from a map
Parameters
- $map_id
- (int) Map ID
- $marker_ids
- (array|string) List or CSV of marker IDs
Return Values
(int|bool) Number of affected rows or false if the markers could not be unassigned
Changelog
Version | Description |
---|---|
4.0 | Introduced |
unassign_maps_marker($map_ids, $marker_id)
Unassigns a marker from multiple maps
Parameters
- $map_ids
- (array|string) List or CSV of map IDs
- $marker_id
- (int) Marker ID
Return Values
(int|bool) Number of affected rows or false if the marker could not be unassigned
Changelog
Version | Description |
---|---|
4.0 | Introduced |
unassign_all_markers($map_id)
Unassigns all markers from a map
Parameters
- $map_id
- (int) Map ID
Return Values
(int|bool) Number of affected rows or false if the markers could not be unassigned
Changelog
Version | Description |
---|---|
4.0 | Introduced |
unassign_all_maps($marker_id)
Unassigns a marker from all maps
Parameters
- $marker_id
- (int) Marker ID
Return Values
(int|bool) Number of affected rows or false if the marker could not be unassigned
Changelog
Version | Description |
---|---|
4.14 | Introduced |
delete_marker($id)
Deletes a marker and its relationships
Parameters
- $id
- (int) ID of the marker to be deleted
Return Values
(int|bool) Number of affected rows or false if the marker could not be deleted
Changelog
Version | Description |
---|---|
4.0 | Introduced |
delete_markers($ids)
Deletes multiple markers and their relationships
Parameters
- $ids
- (array|string) List or CSV of marker IDs
Return Values
(int|bool) Number of affected rows or false if the markers could not be deleted
Changelog
Version | Description |
---|---|
4.0 | Introduced |
get_layer($id)
Returns the layer for the given ID
Parameters
- $id
- (int) Layer ID
Return Values
(object|null) Layer object or null if no result is found
Changelog
Version | Description |
---|---|
4.0 | Introduced |
get_all_layers()
Returns all layers
Parameters
This method has no parameters
Return Values
(array) List of layer objects
Changelog
Version | Description |
---|---|
4.0 | Introduced |
get_all_basemaps()
Returns all basemaps
Parameters
This method has no parameters
Return Values
(array) List of layer objects
Changelog
Version | Description |
---|---|
4.0 | Introduced |
get_all_overlays()
Returns all overlays
Parameters
This method has no parameters
Return Values
(array) List of layer objects
Changelog
Version | Description |
---|---|
4.0 | Introduced |
add_layer($data, $id = 0)
Adds a layer
Parameters
- $data
- (object) Layer data to be written
- $id
- (int) (optional) ID for the new layer
Return Values
(int|bool) Layer ID or false if the layer could not be added
Changelog
Version | Description |
---|---|
4.0 | Introduced |
update_layer($data, $id)
Updates a layer
Parameters
- $data
- (object) Layer data to be written
- $id
- (int) ID of the layer to be updated
Return Values
(int|bool) Number of affected rows or false if the layer could not be updated
Changelog
Version | Description |
---|---|
4.0 | Introduced |
delete_layer($id)
Deletes a layer
Parameters
- $id
- (int) Layer ID
Return Values
(int|bool) Number of affected rows or false if the layer could not be deleted
Changelog
Version | Description |
---|---|
4.0 | Introduced |
delete_orphaned_rels()
Deletes orphaned relationships
Parameters
This method has no parameters
Return Values
(int|bool) Number of affected rows or false if the orphans could not be deleted
Changelog
Version | Description |
---|---|
4.7 | Introduced |
build_marker($data, $geojson = false)
Builds a valid marker object
Parameters
- $data
- (array) List of marker data
- $geojson
- (bool) (optional) Whether the data is in GeoJSON format
Return Values
(array) Marker object
Changelog
Version | Description |
---|---|
4.9 | Introduced |
sanitize_ids($ids, $csv = false)
Sanitizes an array or comma-separated list of IDs
Parameters
- $ids
- (array|string) List or CSV of IDs
- $csv
- (bool) (optional) Whether to return the sanitized IDs as CSV
Return Values
(array|string) List or CSV of sanitized IDs
Changelog
Version | Description |
---|---|
4.0 | Introduced |
prepare_layers()
Returns the layers table sanitization rules for prepare statements
Parameters
This method has no parameters
Return Values
(array) List of sanitization rules (column => rule)
Changelog
Version | Description |
---|---|
4.0 | Introduced |
prepare_maps()
Returns the maps table sanitization rules for prepare statements
Parameters
This method has no parameters
Return Values
(array) List of sanitization rules (column => rule)
Changelog
Version | Description |
---|---|
4.0 | Introduced |
prepare_markers()
Returns the markers table sanitization rules for prepare statements
Parameters
This method has no parameters
Return Values
(array) List of sanitization rules (column => rule)
Changelog
Version | Description |
---|---|
4.0 | Introduced |
prepare_rels()
Returns the relationships table sanitization rules for prepare statements
Parameters
This method has no parameters
Return Values
(array) List of sanitization rules (column => rule)
Changelog
Version | Description |
---|---|
4.0 | Introduced |