WordPress Plugin Developers – Please Stop Auto Enabling Google Maps Api’s
I have wasted another day finding a hidden setting in another plugin that includes the Google Maps Api js without a key.
At Coffee Black we have a sort of rolling default setup for new WordPress websites.
It includes all of the plugins we always use and some tweaks and other nice to haves which make our lives so much simpler and makes us more efficient when creating a new site.
We use WP Bakery Page builder on all of our client sites and several addons for this.
Over the past 6 months, I have now spent an inordinate amount of time troubleshooting Google Maps API errors.
That seems like a simple thing to do right?
Here lies the issue. When you get an issue in WordPress the first port of call is generally to open console and see whats up.
But with a Google maps API error it only shows you the remote scripts and not the js file or PHP file that is calling the script.
Without the offending file being shown we can naturally assume that the component/plugin on the current page is what is causing the issue.
In my case this was LocatorAid a nice store locator plugin we have used on a few sites to show stockists or offices.
I raise a support ticket as the API key works fine in the back end of the site, they usefully load a google map on the api key config page so you can confirm it is working correctly, but on the front end I get the dreaded “Do you own this website” error
Now over the past six months we have had around 4 or 5 occasions when we have had odd API key issues, it turns out that the reason we were getting the API key issue is that another plugin is trying to load the maps API before the one we are troubleshooting.
Plugin Developers are including maps functionality into their plugins and activating the script includes by default.
Now until perhaps a year ago this wasn’t too big an issue as API keys were not mandatory for the maps API.
They are now……
So, In order, we have to do the following on every website for the following plugins
Great set of additional elements for WP-Bakery page builder. But if you have all of their shortcodes active it will load the Google Maps JS library on every page.
You can either,
- Disable the map shortcode by going to the Massive Panel dashboard and disabling it there
- Add in the google maps api key in here.
Custom Page Templates – ACF, Advanced Custom Fields.
Another great plugin. this allows you to design page templates and override the defaults in a really simple way. Their dynamic values functionality opened up a lot of new options for us when creating pages.
When you install Custom Page Templates it automatically installs Advanced Custom Fields Pro as it relies on it to work.
And in the CPT Settings panel you will find another tickbox which needs to be unticked to stop it from loading the google maps API JS on every page.
again you can add your maps API key here if you are going to use the maps custom field. But they do at least provide a simple tick box to say do not include this script.
Similar setup to Massive addons and another great selection of elements for WP-Bakery.
to stop them from including the google maps API you need to add the following “define(‘DISABLE_ULTIMATE_GOOGLE_MAP_API’, true);” into your wp-config.php file.
They do say they only load it on pages that use the element but it can cause conflicts with other plugins that load it everywhere.
My very favourite of the bunch so far.
Yep, that’s right. This is a Mega Menu plugin that by default includes the Google Maps API script.
As per the other plugins, I do very highly recommend the UberMenu plugin and we use it on every website as it provides a massive range of possible layouts for your menus and the documentation is very good as is the integration with the WordPress menu system.
The UberMenu options will appear in the header of the site. Hover on this and click onto the UberMenu Control Panel.
In here you will click onto the second tab for General Settings.
In the left hand menu you then click assets and scroll down to the Google Maps Section. Untick the Load Google Maps API box and save.
Chris Mavricos from SevenSpark the creators of UberMenu was very quick to respond to our request for information and sent us the following
Short version: You are correct – it should not be nor is it intended to be! This is a bug that was introduced in an earlier update. Thank you for bringing it to my attention, and my apologies!
The UberMenu Google Maps functionality is designed such that the Google Maps API is only loaded if the UberMenu Google Maps shortcode is present on a specific page. The setting in the Control Panel exists so that if you are using the shortcode along with another Google Maps plugin, you have control over which version to use. Having it enabled isn’t intended to actually load the API unless you’re also using the shortcode. In other words, the setting is enabled by default so you can use the shortcode out of the box if you want to, but the script should not be loaded by default unless you’re actually adding a map via UberMenu’s shortcode.
I’ve been reviewing the code this morning and found the issue. In an earlier commit, the wp_register_script() call was replaced with a wp_enqueue_script() call, for reasons unknown. That resulted in the script being loaded even without using the shortcode, if the setting is enabled, which broke the previously implemented functionality described above. This is definitely not intended functionality and will be addressed in the next issue – thank you for bringing it to my attention!
So again, my apologies for both the frustration and the time waste! I know troubleshooting conflicts like that are super frustrating. As you mentioned in your article, there isn’t a great way to deal with these commonly shared assets, but this issue shouldn’t have occurred in this case regardless. I really do appreciate you letting me know so that it can be fixed.
I don’t know what the real solution is here, perhaps someone can put together a centralised Google Maps Script Include that every other plugin can access via an API?
What I do know is including a script by default which requires API keys so will never work unless configured, and is used so widely by other plugins, is a daft idea and I want everyone to just stop it now.
For the sake of my sanity and business.
Leave a Response