PHP Functions

You are here:

If you need you have a set of php functions to interact with the plugin without the need of using shortcodes. Be sure to wrap all your functions in a function_exists() block to avoid fatal errors when plugin is not enabled. Eg:

function_exists

1
2
3
4
5
if( function_exists( 'geot_target' ) ) {
    if( geot_target( 'Argentina' ) ) {
        echo 'Only show to Argentina';
    }
}

geot_target

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
/**
 * Main function that return true or false depending if current user
 * target the given countries
 *
 * @param string/Array $country - Pass an array of countries ,
 * conutry name or country code
 * @param string $country_region - Region name
 * @param string $exclude/Array -Pass an array of countries ,
 * country name or country code
 * @param  string $exclude_region - Region name
 *
 * @return bool
 */
geot_target( $country = '', $country_region = '', $exclude = '', $exclude_region  = '' );
 
// Usage
 
if ( geot_target(array( 'Argentina', 'Brazil' )) ) {
    // show content
}

geot_target_city

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
/**
 * Main function that return true or false depending if current user
 * target the given cities
 *
 * @param string/Array $city - Pass an array of cities ,
 * city name
 * @param string $city_region - Region name
 * @param string $exclude/Array -Pass an array of cities ,
 * or a single city
 * @param  string $exclude_region - Region name
 *
 * @return bool
 */
geot_target_city( $city = '', $city_region = '', $exclude = '', $exclude_region  = '' );
 
// Usage
 
if ( geot_target_city(array( 'New York', 'Miami' )) ) {
    // show content
}

geot_target_state

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
/**
 * Main function that return true or false depending if current user
 * target the given cities
 *
 * @param string/Array $state - Pass an array of states ,
 * state name
 * @param string $exclude/Array -Pass an array of states ,
 * or a single state name
 *
 * @return bool
 */
geot_target_state( $state = '', $exclude = '' );
 
// Usage
 
if ( geot_target_state(array( 'Florida' )) ) {
    // show content
}

geot_user_country

1
2
3
4
5
// Return object of current user country details
$country = geot_user_country();
 
echo $country->name;
echo $country->isoCode;

geot_country_code

1
2
3
// return current user country code
 
echo 'You country code is : ' . geot_country_code();

geot_country_name

1
2
3
// return current user country name
 
echo 'You country name is : ' . geot_country_name();

geot_country_by_ip

1
2
3
4
5
// Return country by given ip or current user if not ip is given
// $country->name $country->isoCode
$country = geot_country_by_ip("190.188.153.122");
 
echo 'Your country is : '. $country->name;

geot_state_by_ip

1
2
3
4
5
// Return state by given ip or current user if not ip is given
// $state->name $state->isoCode
$state = geot_state_by_ip("190.188.153.122");
 
echo 'Your state is : '. $state->name;

geot_city_name

1
2
3
// Return current user city name
 
echo 'Your city is: '. geot_city_name();

geot_zip

1
2
3
// Return current user zip code
 
echo 'Your zip is: '. geot_zip();