Skip to content

Commit 59c2cf8

Browse files
author
Benjamin Pick
committed
Move API function
1 parent 5ffc43a commit 59c2cf8

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

ajax.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function _geoip_detect_ajax_get_data($options = array()) {
111111
* Call this function if you want to register the JS script only for specific pages
112112
* @api
113113
*/
114-
function geoip_detect2_enqueue_javascript() {
114+
function _geoip_detect2_enqueue_javascript() {
115115
if (did_action('wp_enqueue_scripts')) {
116116
wp_enqueue_script('geoip-detect-js');
117117
} else {

api-stubs.php

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ function geoip_detect2_get_reader($locales = null, $options = array()) { return
88
function geoip_detect2_get_current_source_description($source = null) { return ''; }
99
function geoip_detect2_get_client_ip() { return ''; }
1010
function geoip_detect2_get_external_ip_adress($unfiltered = false) { return ''; }
11+
function geoip_detect2_enqueue_javascript() { return false; }

api.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function geoip_detect2_get_info_from_ip($ip, $locales = null, $options = array()
8686
* After loading the information from the Geolocation-Database AND after the cache, you can add information to it.
8787
*
8888
* @param array $data Information found.
89-
* @param string $orig_ip IP that originally passed to the function.
89+
* @param string $orig_ip IP that originally passed to the function.
9090
* @return array
9191
*/
9292
$data = apply_filters('geoip_detect2_record_data_after_cache', $data, $ip);
@@ -232,3 +232,11 @@ function geoip_detect2_get_external_ip_adress($unfiltered = false) {
232232

233233
return $ip_cache;
234234
}
235+
236+
/**
237+
* Call this function if you want to register the JS script for AJAX mode only for specific pages
238+
* @see https://github.com/yellowtree/geoip-detect/wiki/API-Usage-Examples#ajax-enqueue-the-js-file-manually
239+
*/
240+
function geoip_detect2_enqueue_javascript() {
241+
_geoip_detect2_enqueue_javascript();
242+
}

tests/test-api.php

+4
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,8 @@ function testCamelcase() {
127127
$this->assertSame('helloWorld.youAreLoved', _geoip_dashes_to_camel_case('hello_world.you_are_loved'));
128128
$this->assertSame('helloWorld.youAreLoved.really', _geoip_dashes_to_camel_case('hello_world.you_are_loved.really'));
129129
}
130+
131+
function testEnqueue() {
132+
geoip_detect2_enqueue_javascript();
133+
}
130134
}

0 commit comments

Comments
 (0)