A case from the practice: You have an e-commerce website integrated with the local delivery company. The thing is that all the address’ fields should be filled in Cyrillic as this is the expected input. Any Latin input will break the delivery service. So you need to make sure that only Cyrillic characters are used. …
Author Archives: sas
Get the visitor’s country by their IP
Basically the code is something like this:
1 2 3 4 5 6 7 8 9 10 11 12 |
function check_contry(){ $ip = $_SERVER["REMOTE_ADDR"]; if (filter_var(@$_SERVER['<a href="http://en.wikipedia.org/wiki/X-Forwarded-For">HTTP_X_FORWARDED_FOR</a>'], FILTER_VALIDATE_IP))} $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)){ $ip = $_SERVER['HTTP_CLIENT_IP']; } $ipdata = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip)); return $ipdata->geoplugin_countryCode; } |
So we are using the GeoPlugin API to retrieve the Country code. You can also get the full country name, state, city, continent and some other stuff. Here is a simple dump of the data returned from the site:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
{ ["geoplugin_request"]=> string(13) "93.152.143.66" ["geoplugin_status"]=> int(206) ["geoplugin_credit"]=> string(145) "Some of the returned data includes GeoLite data created by MaxMind, available from http://www.maxmind.com." ["geoplugin_city"]=> string(6) "Sofiya" ["geoplugin_region"]=> string(11) "Grad Sofiya" ["geoplugin_areaCode"]=> string(1) "0" ["geoplugin_dmaCode"]=> string(1) "0" ["geoplugin_countryCode"]=> string(2) "BG" ["geoplugin_countryName"]=> string(8) "Bulgaria" ["geoplugin_continentCode"]=> string(2) "EU" ["geoplugin_latitude"]=> string(2) "43" ["geoplugin_longitude"]=> string(2) "25" ["geoplugin_regionCode"]=> string(0) "" ["geoplugin_regionName"]=> NULL ["geoplugin_currencyCode"]=> string(3) "BGL" ["geoplugin_currencySymbol"]=> NULL ["geoplugin_currencySymbol_UTF8"]=> string(0) "" ["geoplugin_currencyConverter"]=> int(0) } |
For more info and explanations and …
Displaying the shortcode from Custom post type content or Metabox
Whenever you try to display a shortcode through custom field you will get the text part and the shortcode function won’t be trigger. To avoid this you can apply the following filter in your code:
1 |
<?php echo apply_filters('the_content', get_post_meta($post->ID, 'the_custom_field', true)); ?> |
“the_custom_field” should be replaced by your own custom field name. Basically you can apply this filter to any …
Continue reading “Displaying the shortcode from Custom post type content or Metabox”
Add new options to any wordpress theme in the Customize panel
Let’s say that you need a second logo image to be added in your header. And let’s assume that this should be editable feature. The easiest way to manage this task is to make a new option in the Customize panel (Appearance -> Customize) to upload a logo image and add a link to it. …
Continue reading “Add new options to any wordpress theme in the Customize panel”