Custom WordPress Template
By using my own custom template and rolling much of the functionality within the template, it becomes much easier to create an efficient solution using a minimal number of minified JS and CSS front-end files, reduce duplication of code and resources 3rd party plugins often introduce, and unify much of the administration creating a simpler system to administrate.
Custom Post Type: Agents
One of the site challenges was handling the Location Agent functionality. To be able to search, a local version of the agent data needed to exist as a custom post type. Normally that would be it, define a custom type, create an editor to add/edit/delete, and move on to the search function and display of the data. In this case the maintenance of agent data was to continue to be handled on an existing external system.
Primary agent maintenance would be performed on an external system
The solution involved configuring the external system to nightly push a data file containing the relative agent data to the site’s server. Upon detecting the data file, the site would read the data synchronizing (add, update, and deleting) agent data with the custom post type data within WordPress. This action happens completely as a background process within WordPress.
Additional fields latitude and longitude for search function
The external agent system only had available some of the data required. Missing is the geographic location (latitude and longitude) for each agent (which wouldn’t always match their physical address). So while most agent data would managed externally, the site needed to allow creating/managing this extra data. When encountering a new agent or detecting an address change of an existing agent (either through direct edit or import), Google’s Geocoding API is used to convert the address to latitude/longitude which is stored in the custom agent post data. The editor also always manually changing those coordinates either by directly entering a new latitude or longitude, or usually more simply by dragging the displayed map marker to the location desired (using Google’s Map API).
Geographic distance based database search
The geographic search function (closest to user or an entered zip code) required a very specific radius database query. The user’s latitude and longitude or center of the entered zip code is calculated using Google’s APIs, and passed into a custom query that returns the agent list ordered closest to most distant.
Name and ‘nickname’ searches
A user can find agents by name, but a requirement was to support nicknames and other unique keywords at the agent level (‘Steve “daguy” Simons’). The nickname data would be provided in the external system’s data files the site synchronizes again, but keywords and special cases need to be handled within the local WordPress custom agent type data.
Custom Ninja Forms field, email agents but don’t expose the agent’s email address
Part of the requirements was information displayed would be limited to the agent’s name and phone number, but still support the user contacting the agent by email without revealing their often personal email address. Ninja Forms (NF) was used for handling all the contact forms, so to provide a way to display a user form with a dynamic recipient address and not display that address or create a mail relay security problem, a custom NF field was created. When the form is processed within NF, the custom field appends to the message recipients the agent’s email address it retrieves from the token set by the javascript code used to display the form for a selected agent.