818 pointsLike some sort of WPMU DEV God"Mindblowingly helpful member
nickd32
Member
—
26th March 2011 (1 year ago)
Hi gang,
I've just written a plugin to show ads (HTML code) to site visitors (as sidebar widgets) based on which country they're in.
From the US? ==> You get the US ad
From the UK? ==> You get the UK ad
From Australia? ==> You get the AU ad
It's been possible to do this using "Who Sees Ads" (or WSA) except that WSA doesn't work when you've got caching turned on. The WSA logic is all written in PHP.
I had a requirement to use W3 Total Cache. So I wrote this plugin using Javascript only. It uses the (free) MaxMind GeoIP JS Web Service to return the user's IP/Country using only Javascript.
OUTSTANDING QUESTIONS:
I'm not a great coder, so I may be making some mistakes...
1. There is an "Ads by Country" options page where you put in your ads (your HTML Code). That code gets saved into the WP database (wp_options table).
2. Should I create a different entry in the DB for each country, or combine all this into one array?
3. Should I implement some kind of simple caching? Right now, every time the user loads the page, it uses the WP "get_option" function to pull the ad code from the DB. I'm thinking each user only needs to pull that from the DB once.
4. Does it need some error checks?
Above all, I'm trying to reduce the impact on the server by being smart about using the DB.
I've just written a plugin to show ads (HTML code) to site visitors (as sidebar widgets) based on which country they're in.
From the US? ==> You get the US ad
From the UK? ==> You get the UK ad
From Australia? ==> You get the AU ad
It's been possible to do this using "Who Sees Ads" (or WSA) except that WSA doesn't work when you've got caching turned on. The WSA logic is all written in PHP.
I had a requirement to use W3 Total Cache. So I wrote this plugin using Javascript only. It uses the (free) MaxMind GeoIP JS Web Service to return the user's IP/Country using only Javascript.
OUTSTANDING QUESTIONS:
I'm not a great coder, so I may be making some mistakes...
1. There is an "Ads by Country" options page where you put in your ads (your HTML Code). That code gets saved into the WP database (wp_options table).
2. Should I create a different entry in the DB for each country, or combine all this into one array?
3. Should I implement some kind of simple caching? Right now, every time the user loads the page, it uses the WP "get_option" function to pull the ad code from the DB. I'm thinking each user only needs to pull that from the DB once.
4. Does it need some error checks?
Above all, I'm trying to reduce the impact on the server by being smart about using the DB.
10635 pointsLike some sort of WPMU DEV GodMindblowingly helpful memberLifetime member
Sales & Support Lead
—
27th March 2011 (1 year ago)
#
Hiya nickd32!
Well, first off, thanks for sharing! :)
I'm gonna ask a couple of our developers to drop in and see if they can take a look and give you some pointers. I will note that they're crazy busy at the moment as we're down a man right now.
What do you guys think? Barry, Ivan, Aaron? Any thoughts on this one?
I have gone trough the code and it looks good. Maybe some formating and indentation will improve the readability. Also you haven't localized all the stings.
Re your questions:
1. This one looks alright.
2. For this particular thing I would recommend storing all entries into a single array.
3. The get_option function has an internal cache so you don't need to cache anything explicitly.
4. Yeah, it will be good to verify _wpnonce on form submission.
Responses (3)
Sales & Support Lead — 27th March 2011 (1 year ago) #
Hiya nickd32!
Well, first off, thanks for sharing! :)
I'm gonna ask a couple of our developers to drop in and see if they can take a look and give you some pointers. I will note that they're crazy busy at the moment as we're down a man right now.
What do you guys think? Barry, Ivan, Aaron? Any thoughts on this one?
Thanks!
Developer — 5th April 2011 (1 year ago) #
Hi Nick,
I have gone trough the code and it looks good. Maybe some formating and indentation will improve the readability. Also you haven't localized all the stings.
Re your questions:
1. This one looks alright.
2. For this particular thing I would recommend storing all entries into a single array.
3. The get_option function has an internal cache so you don't need to cache anything explicitly.
4. Yeah, it will be good to verify _wpnonce on form submission.
Keep up the good work ;)
Member — 7th April 2011 (1 year ago) #
Thanks Ivan! I appreciate you taking a look at the code. I'll make these updates.
Also, the plugin has moved to the official WP plugin repository:
http://wordpress.org/extend/plugins/ads-by-country/
Become a member