Created
February 3, 2019 18:17
-
-
Save strarsis/baf2f5c01b74285661568353bff47b73 to your computer and use it in GitHub Desktop.
Set ACF Free + ACF PRO Google Maps API key in WordPress (plugin) (Bedrock based WordPress installation)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Authorize API for project: | |
// https://console.developers.google.com/apis/api/places_backend?project=_ | |
// Uses GOOGLE_API_KEY environment variable (WordPress Bedrock dotenv) | |
$google_api_key = getenv('GOOGLE_API_KEY'); | |
if($google_api_key !== false and !empty($google_api_key)) { | |
// ACF | |
add_filter('acf/fields/google_map/api', function($value) { | |
global $google_api_key; | |
return array( | |
'libraries' => 'places', | |
'key' => $google_api_key | |
); | |
}); | |
// ACF PRO | |
add_action('acf/init', function() { | |
global $google_api_key; | |
acf_update_setting('google_api_key', $google_api_key); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment