SLPlus_Location
in package
Store Locator Plus location interface and management class.
Make a location an in-memory object and handle persistence via data I/O to the MySQL tables.
FIELDS:
Table of Contents
Constants
- MaxDelay = 6000000
- StartingDelay = 2000000
Properties
- $active_radius : float
- $address : string
- $address2 : string
- $all : bool
- $all : mixed
- $attributes : array<string|int, mixed>
- $attributes : mixed
- $city : string
- $count : int
- $country : string
- $data_is_loading : bool
- $dataChanged : bool
- $dataChanged : mixed
- $db : wpdb
- $dbFieldPrefix : string
- $dbFieldPrefix : mixed
- $dbFields : array<string|int, string>
- $dbfields : array<string|int, string>
- $delay : int
- $description : string
- $email : string
- $exdata : array<string|int, mixed>
- $exdata : mixed
- $fax : string
- $geocodeIssuesRendered : bool
- $geocodeSkipOKNotices : bool
- $geocodeSkipOKNotices : mixed
- $hours : string
- $id : int
- $image : string
- $initial_distance : float
- $lastupdated : datetime
- $latitude : string
- $linked_postid : int
- $locationData : array<string|int, mixed>
- $longitude : string
- $map_center_valid : bool
- $neat_title : string
- $option_value : string
- $pageData : array<string|int, mixed>
- $pageDefaultStatus : string
- $pages_on : bool
- $pages_url : string
- $phone : string
- $private : bool
- $retry_maximum_delayms : int
- $settings : array<string|int, mixed>
- $slplus : SLPlus
- $state : string
- $store : string
- $tags : string
- $url : string
- $validate_fields : bool
- $validate_fields : mixed
- $zip : string
- $active_radius : mixed
- $address : mixed
- $address2 : mixed
- $city : mixed
- $count : mixed
- $country : mixed
- $data_is_loading : mixed
- $db : mixed
- $dbFields : mixed
- $delay : mixed
- $description : mixed
- $display_types : mixed
- $email : mixed
- $fax : mixed
- $geocodeIssuesRendered : mixed
- $hours : mixed
- $id : mixed
- $image : mixed
- $initial_distance : mixed
- $lastupdated : mixed
- $latitude : mixed
- $legacy_field_map : mixed
- $linked_postid : mixed
- $locationData : mixed
- $longitude : mixed
- $map_center_valid : mixed
- $neat_title : mixed
- $option_value : mixed
- $pageData : mixed
- $pageDefaultStatus : mixed
- $pages_on : mixed
- $pages_url : mixed
- $phone : mixed
- $private : mixed
- $property_names : mixed
- $slplus : mixed
- $state : mixed
- $store : mixed
- $tags : mixed
- $temporary : mixed
- $url : mixed
- $zip : mixed
Methods
- __construct() : mixed
- Initialize a new location
- __get() : null
- Fetch a location property from the valid object properties list.
- __isset() : bool
- Allow isset to be called on private properties.
- __set() : SLPlus_Location
- Set a location property in the valid object properties list to the given value.
- add_to_database() : string
- Add an address into the SLP locations database.
- crupdate_Page() : int
- Create or update the custom store_page page type for this location.
- delete() : WP_Error|int|false
- Delete this location permanently.
- delete_extended_data() : mixed
- Delete extended data.
- delete_page_links() : mixed
- Delete the associated page.
- delete_store_pages() : mixed
- Delete store pages.
- do_geocoding() : mixed
- GeoCode a given location, updating the slplus_plugin currentLocation object lat/long.
- get() : $this|array<string|int, mixed>
- Return location as OBJECT (default) , named array (ARRAY_A), or numeric array (ARRAY_N)
- get_display_type() : null|string
- Get the display type for the specified property.
- get_formatted_address() : mixed
- Return a formatted address. Unlike get_formatted_name this is used for a typical "postal address block".
- get_formatted_name() : mixed|null
- Send back a formatted name including the store, city, and state space separated by default.
- get_location() : SLPLus_location
- Set the current location to the given location ID and return the SLPlus_Location object.
- get_PersistentProperty() : mixed
- Return the values for each of the persistent properties of this location.
- get_property_name() : string
- Return the base name without the leading sl_.
- get_property_using_fieldname() : string|null
- Get a property value by the DB field name.
- is_base_field() : bool
- Return true if the field slug or sl_<field_slug> is a base field.
- is_valid_lat() : bool
- Latitude is valid.
- is_valid_lng() : bool
- Longitude is valid.
- isvalid_ID() : bool
- Return true of the given string is an int greater than 0.
- MakePersistent() : bool
- Make the location data persistent.
- MakePersistentIfChanged() : mixed
- Write a location record to the database if dataChanged is true.
- only_delete_store_pages() : mixed
- Filter to make sure we only delete SLP Store Pages
- page_exists() : mixed
- Return true if the Store Page actually exists for the current location.
- reset() : mixed
- Set all the db field properties to blank.
- set_PropertiesViaArray() : mixed
- Set location properties via a named array containing the field data.
- set_PropertiesViaDB() : SLPlus_Location
- Load a location from the database.
- update_Attributes() : mixed
- Update the location attributes, merging existing attributes with new attributes.
- valid_location_property() : bool
- Return true if the property is valid.
- calculate_initial_distance() : mixed
- Calculate the initial distance from the map center point.
- decode_Base64UrlSafe() : string
- Decode a string from URL-safe base64.
- is_map_center_valid() : bool
- Return if map center is valid.
- make_extended_data_persistent() : bool
- Make extended data persistent.
- mapPropertyToField() : array<string|int, mixed>
- Return a named array that sets key = db field name, value = location property
- set_LatLong() : mixed
- Set latitude & longitude for this location.
- set_PageData() : array<string|int, mixed>
- Setup the data for the current page, run through augmentation filters.
- val_or_blank() : mixed
- Return the value of the specified location data element or blank if not set.
Constants
MaxDelay
public
mixed
MaxDelay
= 6000000
StartingDelay
public
mixed
StartingDelay
= 2000000
Properties
$active_radius read-only
public
float
$active_radius
The current active radius of the earth in MI or KM.
$address
public
string
$address
$address2
public
string
$address2
$all
public
bool
$all
Process ALL location records (currently used for delete all)
$all
public
mixed
$all
$attributes
public
array<string|int, mixed>
$attributes
The deserialized option_value field. This can be augmented by multiple add-on packs. Tagalong adds: array[] ['store_categories'] int[] ['stores']
PAGE RELATIONS:
$attributes
public
mixed
$attributes
$city
public
string
$city
$count read-only
public
int
$count
How many locations have processed for geocoding this session.
$country
public
string
$country
$data_is_loading read-only
public
bool
$data_is_loading
Set to true if we want to postpone all property change processing until later.
$dataChanged
public
bool
$dataChanged
True if the location data has changed. Used to manage the MakePersistent method, if false do not write to disk.
$dataChanged
public
mixed
$dataChanged
= \true
$db read-only
public
wpdb
$db
The WPDB connection.
$dbFieldPrefix read-only
public
string
$dbFieldPrefix
The database field prefix for locations
$dbFieldPrefix
public
mixed
$dbFieldPrefix
= 'sl_'
$dbFields read-only
public
array<string|int, string>
$dbFields
An array of properties that are in the db table
FUNCTIONALITY:
$dbfields read-only
public
array<string|int, string>
$dbfields
Array of locator table field names.
$delay read-only
public
int
$delay
How long to wait between geocoding requests.
$description
public
string
$description
public
string
$email
$exdata
public
array<string|int, mixed>
$exdata
- the extended data fields
DESERIALIZED DATA:
$exdata
public
mixed
$exdata
= array()
$fax
public
string
$fax
$geocodeIssuesRendered read-only
public
bool
$geocodeIssuesRendered
$geocodeSkipOKNotices
public
bool
$geocodeSkipOKNotices
If true do not show valid geocodes.
$geocodeSkipOKNotices
public
mixed
$geocodeSkipOKNotices
= \false
$hours
public
string
$hours
$id
public
int
$id
$image
public
string
$image
$initial_distance
public
float
$initial_distance
EXTENDED DATA FIELDS:
$lastupdated
public
datetime
$lastupdated
$latitude
public
string
$latitude
$linked_postid
public
int
$linked_postid
$locationData read-only
public
array<string|int, mixed>
$locationData
Remember the last location data array passed into set properties via DB.
$longitude
public
string
$longitude
$map_center_valid read-only
public
bool
$map_center_valid
Is the map center lat/lng valid?
$neat_title
public
string
$neat_title
$option_value
public
string
$option_value
$pageData
public
array<string|int, mixed>
$pageData
The related store_page custom post type properties. WordPress Standard Custom Post Type Features: int ['ID'] - the WordPress page ID string ['post_type'] - always set to this.PageType string ['post_status'] - current post status, 'draft', 'published' string ['post_title'] - the title for the page string ['post_content']- the page content, defaults to blank
Store Pages adds: post_content attribute is loaded with auto-generated HTML content
Tagalong adds: mixed[] ['tax_input'] - the custom taxonomy values for this location
$pageDefaultStatus read-only
public
string
$pageDefaultStatus
The default page status
DB META:
$pages_on
public
bool
$pages_on
$pages_url
public
string
$pages_url
$phone
public
string
$phone
$private
public
bool
$private
$retry_maximum_delayms read-only
public
int
$retry_maximum_delayms
Maxmium delay in milliseconds.
$settings
public
array<string|int, mixed>
$settings
The deserialized option_value field
$slplus
public
SLPlus
$slplus
The parent plugin object
$state
public
string
$state
$store
public
string
$store
the store name
$tags
public
string
$tags
$url
public
string
$url
$validate_fields
public
bool
$validate_fields
Validate fields? no by default.
$validate_fields
public
mixed
$validate_fields
= \false
$zip
public
string
$zip
$active_radius
private
mixed
$active_radius
$address
private
mixed
$address
$address2
private
mixed
$address2
$city
private
mixed
$city
$count
private
mixed
$count
= 0
$country
private
mixed
$country
$data_is_loading
private
mixed
$data_is_loading
= \false
$db
private
mixed
$db
$dbFields
private
mixed
$dbFields
= array('id', 'store', 'address', 'address2', 'city', 'state', 'zip', 'country', 'latitude', 'longitude', 'tags', 'description', 'email', 'url', 'hours', 'phone', 'fax', 'image', 'private', 'neat_title', 'linked_postid', 'pages_url', 'pages_on', 'option_value', 'lastupdated', 'initial_distance')
$delay
private
mixed
$delay
= self::StartingDelay
$description
private
mixed
$description
$display_types
private
mixed
$display_types
= array()
private
mixed
$email
$fax
private
mixed
$fax
$geocodeIssuesRendered
private
mixed
$geocodeIssuesRendered
= \false
$hours
private
mixed
$hours
$id
private
mixed
$id
$image
private
mixed
$image
$initial_distance
private
mixed
$initial_distance
$lastupdated
private
mixed
$lastupdated
$latitude
private
mixed
$latitude
$legacy_field_map
private
mixed
$legacy_field_map
= array('sl_id' => 'id', 'sl_store' => 'store', 'sl_address' => 'address', 'sl_address2' => 'address2', 'sl_city' => 'city', 'sl_state' => 'state', 'sl_zip' => 'zip', 'sl_country' => 'country', 'sl_latitude' => 'latitude', 'sl_longitude' => 'longitude', 'sl_tags' => 'tags', 'sl_description' => 'description', 'sl_email' => 'email', 'sl_url' => 'url', 'sl_hours' => 'hours', 'sl_phone' => 'phone', 'sl_fax' => 'fax', 'sl_image' => 'image', 'sl_private' => 'private', 'sl_neat_title' => 'neat_title', 'sl_linked_postid' => 'linked_postid', 'sl_pages_url' => 'pages_url', 'sl_pages_on' => 'pages_on', 'sl_option_value' => 'option_value', 'sl_lastupdated' => 'lastupdated', 'sl_initial_distance' => 'initial_distance')
$linked_postid
private
mixed
$linked_postid
$locationData
private
mixed
$locationData
$longitude
private
mixed
$longitude
$map_center_valid
private
mixed
$map_center_valid
$neat_title
private
mixed
$neat_title
$option_value
private
mixed
$option_value
$pageData
private
mixed
$pageData
$pageDefaultStatus
private
mixed
$pageDefaultStatus
$pages_on
private
mixed
$pages_on
$pages_url
private
mixed
$pages_url
$phone
private
mixed
$phone
$private
private
mixed
$private
$property_names
private
mixed
$property_names
= array()
$slplus
private
mixed
$slplus
$state
private
mixed
$state
$store
private
mixed
$store
$tags
private
mixed
$tags
$temporary
private
mixed
$temporary
= array()
$url
private
mixed
$url
$zip
private
mixed
$zip
Methods
__construct()
Initialize a new location
public
__construct(array<string|int, mixed> $params) : mixed
Parameters
- $params : array<string|int, mixed>
-
- a named array of the plugin options.
__get()
Fetch a location property from the valid object properties list.
public
__get(mixed $property) : null
$currentLocation = new SLPlus_Location() print $currentLocation->id
Parameters
- $property : mixed
-
- which property to set.
Return values
null__isset()
Allow isset to be called on private properties.
public
__isset( $property) : bool
Parameters
Return values
bool__set()
Set a location property in the valid object properties list to the given value.
public
__set(mixed $property, mixed $value) : SLPlus_Location
$currentLocation = new SLPlus_Location() $currentLocation->store = 'My Place'
Parameters
- $property : mixed
- $value : mixed
Return values
SLPlus_Locationadd_to_database()
Add an address into the SLP locations database.
public
add_to_database(array<string|int, array<string|int, mixed>> $locationData[, string $duplicates_handling = 'none' ][, bool $skipGeocode = false ]) : string
NOTE: Only saves PRIMARY data fields. DOES NOT save extended data. Use the slp_location_added action.
duplicates_handling can be: o none = ignore duplicates o skip = skip duplicates o update = update duplicates
Returns: o added = new location added o location_exists = store id provided and not in update mode o not_updated = existing location not updated o skipped = duplicate skipped o updated = existing location updated
Parameters
- $locationData : array<string|int, array<string|int, mixed>>
- $duplicates_handling : string = 'none'
- $skipGeocode : bool = false
Return values
stringcrupdate_Page()
Create or update the custom store_page page type for this location.
public
crupdate_Page([bool $MakePersistent = true ]) : int
Set MakePersistent to false if you are going to manage the persistent store later. You can check $this->dataChanged to see if the data is dirty to determine whether or not persistence might be needed.
Parameters
- $MakePersistent : bool = true
-
if true will write the location to disk if the linked_postid was changed.
Return values
int —return the page ID linked to this location.
delete()
Delete this location permanently.
public
delete([int|null $id = null ][, bool $all = false ]) : WP_Error|int|false
Parameters
- $id : int|null = null
- $all : bool = false
-
- Delete all processing
Return values
WP_Error|int|falsedelete_extended_data()
Delete extended data.
public
delete_extended_data() : mixed
delete_page_links()
Delete the associated page.
public
delete_page_links() : mixed
delete_store_pages()
Delete store pages.
public
delete_store_pages() : mixed
do_geocoding()
GeoCode a given location, updating the slplus_plugin currentLocation object lat/long.
public
do_geocoding([string $address = null ]) : mixed
Writing to disk is to be handled by the calling function.
slplus_plugin->currentLocation->dataChanged is set to true if the lat/long is updated.
Parameters
- $address : string = null
-
the address to geocode, if not set use currentLocation
get()
Return location as OBJECT (default) , named array (ARRAY_A), or numeric array (ARRAY_N)
public
get([string $output = OBJECT ]) : $this|array<string|int, mixed>
Parameters
- $output : string = OBJECT
Return values
$this|array<string|int, mixed>get_display_type()
Get the display type for the specified property.
public
get_display_type( $property) : null|string
Parameters
Return values
null|stringget_formatted_address()
Return a formatted address. Unlike get_formatted_name this is used for a typical "postal address block".
public
get_formatted_address() : mixed
get_formatted_name()
Send back a formatted name including the store, city, and state space separated by default.
public
get_formatted_name() : mixed|null
Use the slp_formatted_location_name_elements filter to change which elements are returned. Use the slp_formatted_location_name filter to change the final string.
Return values
mixed|nullget_location()
Set the current location to the given location ID and return the SLPlus_Location object.
public
get_location( $location_id) : SLPLus_location
Parameters
Return values
SLPLus_location —|| WP_Error
get_PersistentProperty()
Return the values for each of the persistent properties of this location.
public
get_PersistentProperty([string $property = 'all' ]) : mixed
Parameters
- $property : string = 'all'
-
name of the persistent property to get, defaults to 'all' = array of all properties
Return values
mixed —the value the property or a named array of all properties (default)
get_property_name()
Return the base name without the leading sl_.
public
get_property_name(string $field_slug) : string
Parameters
- $field_slug : string
Return values
stringget_property_using_fieldname()
Get a property value by the DB field name.
public
get_property_using_fieldname( $fieldname) : string|null
Parameters
Return values
string|nullis_base_field()
Return true if the field slug or sl_<field_slug> is a base field.
public
is_base_field(string $field_slug) : bool
Parameters
- $field_slug : string
Return values
boolis_valid_lat()
Latitude is valid.
public
is_valid_lat([string $lat = null ]) : bool
Parameters
- $lat : string = null
-
if not passed defaults to current location latitude.
Return values
boolis_valid_lng()
Longitude is valid.
public
is_valid_lng([string $lng = null ]) : bool
Parameters
- $lng : string = null
-
if not passed defaults to current location longitude.
Return values
boolisvalid_ID()
Return true of the given string is an int greater than 0.
public
isvalid_ID([string $id = null ][, string $request_param = null ]) : bool
If not id is presented, check the current location ID.
request_param is used if ID is set to null to try to set the value from a request variable of that name.
Parameters
- $id : string = null
- $request_param : string = null
Return values
boolMakePersistent()
Make the location data persistent.
public
MakePersistent() : bool
Return values
bool —data write OK
MakePersistentIfChanged()
Write a location record to the database if dataChanged is true.
public
MakePersistentIfChanged() : mixed
only_delete_store_pages()
Filter to make sure we only delete SLP Store Pages
public
only_delete_store_pages(mixed $value, WP_Post $post) : mixed
Parameters
- $value : mixed
- $post : WP_Post
Return values
mixed —returns false to not delete
page_exists()
Return true if the Store Page actually exists for the current location.
public
page_exists() : mixed
reset()
Set all the db field properties to blank.
public
reset() : mixed
set_PropertiesViaArray()
Set location properties via a named array containing the field data.
public
set_PropertiesViaArray(array<string|int, mixed> $locationData[, string $mode = 'reset' ]) : mixed
Used to set properties based on the MySQL SQL fetch to ARRAY_A method or on a prepped named array where the field names are keys and field values are the values.
Mode parameter: o dbreset = reset location data to blank before loading it up o reset = reset location data to blank before loading it up o update = do NOT reset location data to blank before updating
Assumes the field names start with 'sl_'.
Parameters
- $locationData : array<string|int, mixed>
- $mode : string = 'reset'
-
which mode? 'add' , 'dbreset' , 'load' , 'reset', or 'update' add is called from \SLPlus_Location::add_to_database based when in 'add' mode dbreset is called from \SLPlus_Location::set_PropertiesViaDB which resets if the location ID changed load is used when a process already read the ENTIRE location data from the DB and is setting properties reset is the general default update is called from \SLPlus_Location::add_to_database based when in 'update' mode
set_PropertiesViaDB()
Load a location from the database.
public
set_PropertiesViaDB(int $locationID) : SLPlus_Location
Only re-reads database if the location ID has changed.
Parameters
- $locationID : int
-
- ID of location to be loaded
Return values
SLPlus_Location —$this - the location object
update_Attributes()
Update the location attributes, merging existing attributes with new attributes.
public
update_Attributes(array<string|int, mixed> $newAttributes) : mixed
Parameters
- $newAttributes : array<string|int, mixed>
valid_location_property()
Return true if the property is valid.
public
valid_location_property(string $property) : bool
Parameters
- $property : string
-
property name to validate
Return values
bool —true if property is OK
calculate_initial_distance()
Calculate the initial distance from the map center point.
private
calculate_initial_distance() : mixed
decode_Base64UrlSafe()
Decode a string from URL-safe base64.
private
decode_Base64UrlSafe( $value) : string
Parameters
Return values
stringis_map_center_valid()
Return if map center is valid.
private
is_map_center_valid() : bool
Sets active_radius and map_center_valid for cache in \SLPlus_Location::calculate_initial_distance
Return values
boolmake_extended_data_persistent()
Make extended data persistent.
private
make_extended_data_persistent() : bool
Return values
bool —true if data was added or changed
mapPropertyToField()
Return a named array that sets key = db field name, value = location property
private
mapPropertyToField(mixed $result, string $property) : array<string|int, mixed>
Parameters
- $result : mixed
- $property : string
-
- name of the location property
Return values
array<string|int, mixed> —- key = string of db field name, value = location property value
set_LatLong()
Set latitude & longitude for this location.
private
set_LatLong(float $lat, float $lng) : mixed
Parameters
- $lat : float
- $lng : float
set_PageData()
Setup the data for the current page, run through augmentation filters.
private
set_PageData() : array<string|int, mixed>
This method applies the slp_location_page_attributes filter.
Using that filter allows other parts of the system to change or augment the data before we create or update the page in the WP database.
Return values
array<string|int, mixed> —WordPress custom post type property array
val_or_blank()
Return the value of the specified location data element or blank if not set.
private
val_or_blank(array<string|int, mixed> $data, string $key) : mixed
Parameters
- $data : array<string|int, mixed>
-
the location data array
- $key : string
-
store locator plus location data array key
Return values
mixed —- the data element value or a blank string