judoman
Forum Replies Created
-
Forum: Plugins
In reply to: multiple api’s with store locatorI had the same problem and got it working. My solution isn’t the most elegant, but it works. BTW, using v1.2.42.1 of the Store Locator (SL) plugin.
First, the API is stored in the WordPress DB using the following name “store_locator_api_key”. So the trick is to search the SL source files for where this key is obtained so that we can override it. It’s used in three places:
- public_html/wp-content/plugins/store-locator/api-key.php
- public_html/wp-content/plugins/store-locator/functions.sl.php
- public_html/wp-content/plugins/store-locator/view-locations.php
The first place is the GUI interface to load the WP DB with the “store_locator_api_key” value. My quick-n-dirty solution is to hardcode the API, so I’m never using the DB value. This means I don’t have to touch this file.
The second place has four entries of the “store_locator_api_key”, and the third, one entry. All five of these entries needs to be changed.
Here’s an example of one of the entries:
$api_key=get_option('store_locator_api_key');
I changed it to this:
$lookup["mywebsite.com"]="put_mywebsite_GoogleApiKeyHere"; $lookup["www.mywebsite.com"]="put_mywebsite_GoogleApiKeyHere"; $lookup["myotherwebsite.com"]="put_myotherwebsite_GoogleApiKeyHere"; $lookup["www.myotherwebsite.com"]="put_myotherwebsite_GoogleApiKeyHere"; $api_key=$lookup[$_SERVER['HTTP_HOST']];
The idea is that I’m building an array of key/value pairs, where each key is one of the domain names, and its value is the corresponding API key. The $_SERVER[‘HTTP_HOST’] in the last line gets the domain the end-user is currently at, thereby providing the key for the array. Whammo, the corresponding API is returned.
I copied this code five times, once for each of the “store_locator_api_key” entries. I simply changed the variable name to match the entry I replaced. So I used $api_key twice, $api twice, and $slak once.
Hope this quick-n-dirty hardcode method helps. One caveat is that any upgrade to this plug-in will smash our hard coding. Caveat emptor!