register_activation_hook(__FILE__, 'wp_sypexgeo_activation'); function wp_sypexgeo_activation() { update_option('sgeo_language', 'en'); update_option('sgeo_dbase', 'loc'); }
add_filter('the_content', 'geotargeting_filter'); add_filter('the_content_rss', 'geotargeting_filter'); add_filter('the_excerpt', 'geotargeting_filter'); add_filter('the_excerpt_rss', 'geotargeting_filter');
call function function geotargeting_filter($s) { //parse Country preg_match_all("#\[" . GEOTARGETING_COUNTY . "\s*(in|out)=([^\]]+)\](.*?)\[/" . GEOTARGETING_COUNTY . "\]#isu", $s, $country); //parse Country preg_match_all("#\[" . GEOTARGETING_REGION . "\s*(in|out)=([^\]]+)\](.*?)\[/" . GEOTARGETING_REGION . "\]#isu", $s, $region); //parse Country preg_match_all("#\[" . GEOTARGETING_CITY . "\s*(in|out)=([^\]]+)\](.*?)\[/" . GEOTARGETING_CITY . "\]#isu", $s, $city); if (empty($country) && empty($region) && empty($city)) { return $s; } $base_type = get_option('sgeo_dbase'); if ($base_type == 'loc') { $ipdata = getLocInfo(); } elseif ($base_type == 'rm') { $ipdata = getRemInfo(); } if (!empty($country)) { foreach ($country[0] as $i => $raw) { $type = strtolower($country[1][$i]); $countries = strtolower(trim(str_replace(array("\"", "'", "\n", "\r", "\t", " "), "", $country[2][$i]))); $content = $country[3][$i]; $countries = explode(",", $countries); $replacement = ""; if ((($type == "in") && in_array($ipdata['country'], $countries)) || (($type == "out") && !in_array($ipdata['country'], $countries))) { $replacement = $content; } $s = str_replace($raw, $replacement, $s); } } if (!empty($region)) { foreach ($region[0] as $i => $raw) { $type = strtolower($region[1][$i]); $regions = strtolower(trim(str_replace(array("\"", "'", "\n", "\r", "\t"), "", $region[2][$i]))); $content = $region[3][$i]; $regions = explode(",", $regions); $replacement = ""; if ((($type == "in") && in_array($ipdata['region'], $regions)) || (($type == "out") && !in_array($ipdata['region'], $regions))) { $replacement = $content; } $s = str_replace($raw, $replacement, $s); } } if (!empty($city)) { foreach ($city[0] as $i => $raw) { $type = strtolower($city[1][$i]); $cities = strtolower(trim(str_replace(array("\"", "'", "\n", "\r", "\t", " "), "", $city[2][$i]))); $content = $city[3][$i]; $cities = explode(",", $cities); $replacement = ""; if ((($type == "in") && in_array($ipdata['city'], $cities)) || (($type == "out") && !in_array($ipdata['city'], $cities))) { $replacement = $content; } $s = str_replace($raw, $replacement, $s); } } return $s; }
[GeoCountry in=Belarus,Russia] Belarus,Russia![/GeoCountry]
[GeoRegion in=Moscow] Moscow Region![/GeoRegion]
[GeoCity in=,] ,![/GeoCity]
[GeoRegion out=Minsk,Brest] , Minsk,Brest![/GeoRegion]
Source: https://habr.com/ru/post/258705/
All Articles