-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Google Maps API key now required for admin #44
Comments
+1 |
Thanks for the feedback @chrisdrake. My initial thoughts for passing in the key include:
I'm leaning towards defining the key. It's clearly not as user friendly as a settings page. However, it's my view that CMB2 and this field are already developer orientated. Any thoughts/strong opinions? |
Thanks for the reply :) I'd be more than happy to have it developer defined key because I fully agree with your point about CMB2. However I'd prefer to see it in a config file in the plugin, or perhaps in a pluggable function that we can include in our plugin or theme? I'm not too keen on it being in wp-config.php because that won't travel with the theme or plugin if it's moved. |
I agree that CMB2 and this field are developer oriented and so the key should be defined in the source code. Maybe using a WordPress filter? |
I like the filter approach, for the reasons chrisdrake outlined.. Doesn't make sense in a field's arguments, since the key is added just once, when the api script is registered. This basic implementation seems to work: public function setup_admin_scripts() {
$api_url = '//maps.googleapis.com/maps/api/js?libraries=places';
$api_key = apply_filters( 'pw-google-maps-api-key', '' );
if ( ! empty( $api_key ) ) {
$api_url .= '&key=' . $api_key;
}
wp_register_script( 'pw-google-maps-api', $api_url, null, null );
wp_enqueue_script( 'pw-google-maps', plugins_url( 'js/script.js', __FILE__ ), array( 'pw-google-maps-api' ), self::VERSION );
wp_enqueue_style( 'pw-google-maps', plugins_url( 'css/style.css', __FILE__ ), array(), self::VERSION );
} I can add my API key by dropping this in a plugin: add_filter( 'pw-google-maps-api-key', function() {
return 'MY_API_KEY';
}); |
That looks absolutely perfect and exactly the sort of thing I was rambling on about ;) |
sorry, where do i put this code in order to fix maps? |
That code prevents the lookup from working but the map does load and doens't come up with the javascript error. |
so? where i must put this code? |
To fix this issue, i updated the method just you can add in your // add the plugin's google map api key
add_filter('os-pw-google-maps-api-key', function(){
return 'APIKEY';
}); Note : head to google map to get api key if you don't have one |
thank you very much |
For the lookup / autocomplete to work, you need to enable the Google Places API in your google api console. More info: http://stackoverflow.com/a/38297390 |
While we wait for this to get merged in here is a little filter that might help you:
|
Perfect @phh ;) |
Thanks it has fixed my issue too!!! |
As per this article. This plugin no longer works until it's updated to allow an API key to be added.
https://googlegeodevelopers.blogspot.co.uk/2016/06/building-for-scale-updates-to-google.html
Great plugin though, I hope to be able to continue using it!
The text was updated successfully, but these errors were encountered: