Skip to content

Commit

Permalink
Allow API key entry
Browse files Browse the repository at this point in the history
  • Loading branch information
zerocrates committed May 4, 2016
1 parent 4e7063c commit 990f05a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
18 changes: 14 additions & 4 deletions GeolocationPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function hookUninstall()
delete_option('geolocation_per_page');
delete_option('geolocation_add_map_to_contribution_form');
delete_option('geolocation_use_metric_distances');
delete_option('geolocation_api_key');

// This is for older versions of Geolocation, which used to store a Google Map API key.
delete_option('geolocation_gmaps_key');
Expand Down Expand Up @@ -126,6 +127,7 @@ public function hookConfig($args)
set_option('geolocation_use_metric_distances', $_POST['geolocation_use_metric_distances']);
set_option('geolocation_map_type', $_POST['map_type']);
set_option('geolocation_auto_fit_browse', $_POST['auto_fit_browse']);
set_option('geolocation_api_key', $_POST['api_key']);
}

public function hookDefineAcl($args)
Expand Down Expand Up @@ -156,15 +158,23 @@ public function hookDefineRoutes($args)

public function hookAdminHead($args)
{
queue_css_file('geolocation-marker');
queue_js_url("//maps.google.com/maps/api/js");
queue_js_file('map');
$this->_head();
}

public function hookPublicHead($args)
{
$this->_head();
}

private function _head()
{
$key = get_option('geolocation_api_key');
$mapsUrl = '//maps.googleapis.com/maps/api/js';
if ($key) {
$mapsUrl .= "?key=$key";
}
queue_css_file('geolocation-marker');
queue_js_url("//maps.google.com/maps/api/js");
queue_js_url($mapsUrl);
queue_js_file('map');
}

Expand Down
9 changes: 9 additions & 0 deletions config_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
?>
</div>
</div>
<div class="field">
<div class="two columns alpha">
<label for="api_key"><?php echo __('API Key'); ?></label>
</div>
<div class="inputs five columns omega">
<p class="explanation"><?php echo __('Google API key for this project.'); ?></p>
<?php echo $view->formText('api_key', get_option('geolocation_api_key')); ?>
</div>
</div>
</fieldset>

<fieldset>
Expand Down

0 comments on commit 990f05a

Please sign in to comment.