Last active
October 28, 2021 12:46
-
-
Save timersys/1bd5e69400fd5d12e1a14c3472963813 to your computer and use it in GitHub Desktop.
GeotargetingWP PHP functions
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 | |
/** | |
* geot_target() | |
* | |
* Main function that return true or false depending if current user | |
* target the given countries | |
* | |
* @param string/Array $country - Pass an array of countries ,country 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 | |
*/ | |
// Usage with countries | |
if ( geot_target( [ 'AR', 'US' ] ) ) { | |
// show content | |
} | |
// Usage with country regions | |
if ( geot_target('', 'europe') ) { | |
// show content | |
} | |
/** | |
* geot_target_city() | |
* | |
* 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 | |
*/ | |
// Usage with cities | |
if ( geot_target_city( [ 'New York', 'Miami' ] ) ) { | |
// show content | |
} | |
// Usage excluding a region | |
if ( geot_target_city( '', '', '', 'region_to_exclude' ) ) { | |
// show content | |
} | |
/** | |
* geot_target_state() | |
* | |
* Main function that return true or false depending if current user | |
* target the given state | |
* | |
* @param string/Array $state - Pass an array of states , state name | |
* @param string $state_region - Region name | |
* @param string $exclude /Array -Pass an array of states ,or a single state | |
* @param string $exclude_region - Region name | |
* | |
* @return bool | |
*/ | |
// Usage | |
if ( geot_target_state( [ 'Florida' ] ) ) { | |
// show content | |
} | |
/** | |
* geot_target_zip() | |
* | |
* Main function that return true or false depending if current user | |
* target the given cities | |
* | |
* @param string/Array $zip - Pass an array of zips , | |
* zip name | |
* @param string $zip_region | |
* @param string $exclude/Array -Pass an array of zips , | |
* or a single zip name | |
* @param string $exclude_region | |
* @return bool | |
*/ | |
// Usage | |
if ( geot_target_zip( [ '12345' ] ) ) { | |
// show content | |
} | |
/////////////////////////////////// | |
///////////// AJAX MODE /////////// | |
/////////////////////////////////// | |
/* | |
* We do have the same functions to run with ajax mode includes/functions-ajax.php | |
* where you need to pass the output as second parameter | |
* usually by saving the buffer as shown in the following example | |
*/ | |
$args = [ | |
'country' => 'AR', | |
'region' => '', | |
'exclude_country' => '', | |
'exclude_region' => '', | |
'html_tag' => 'div', | |
]; | |
ob_start(); | |
// do your logic and print HTML in here | |
$html = ob_get_clean(); | |
// echo the generated shortcode that will be executed in AJAX mode | |
echo ajax_geotwp_filter($args, $html); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment