This plugin allows you fine grained control over who seems adverts or any other bit of html or Javascript code on your blog. For a more detailed discussion on how it’s used, read my Friends don’t let friends see adverts post.
The No Adverts for Friends API:
-
is_regular_user()
– returns true if the visitor has left a comment or is logged into your blog. -
is_whitelisted_site( $url )
– returns true if $url is in a pre-defined list of friend sites like Digg, Delicious and StumbleUpon. -
is_old_post()
– returns true if the current post is over a month old. -
is_searchengine_user()
– if a user comes from one of the listed search engines or this is an old post return true.
Each of the API calls depends on the one before it returning a favourable value. For example, is_old_post()
won’t return true if is_regular_user()
returned true, no matter how old the post is.
Example usage:
<?php if( is_searchengine_user() == false ) { echo "Google adsense code goes here"; }
?>
Edit single.php in your current theme and add that code somewhere within the loop. Now either visit an old page on your blog or use a Google search query to bring you to your blog. Hopefully you’ll see the text “Google adsense code goes here”. Replace this text with the Google Adsense Javascript.
Download
Install
- Rename both files to .php and place friendsadverts.php in your plugins folder. If you use WP-Cache copy wp-cache-phase1.php into plugins/wp-cache/ overwriting the file already there (make a backup first!)
- If you use WP-Cache copy the $nevershowads and $passingthrough arrays from friendsadverts.php into your wp-config.php. They’re needed by WP-Cache which kicks in well before plugins are loaded.
- Activate the “No Adverts for Friends” plugin from your plugins page and modify your templates using the new API.
Well, you’ve read this far. if you use this plugin and it improves the user experience of your regular visitors please consider uncommenting the add_action() command at the start of friendsadverts.php. The donnchas_happy_happy_notice() function prints a message in your blog’s footer saying you use this plugin and links back here.
Changelog
2007-09-11 – initial release.
2007-10-30 – fix for WordPress MU hosts, properly identify visitors from Google vs friends who come via Google Reader. Update to allow caching of password protected posts.