<?php
/*
Plugin Name: Admin Theme Preview Nocache
Plugin URI: http://bitbybit.wordpress.com/code/wordpress/plugins/admin-theme-preview/
Description: Appends ?atp=nocache to most Wordpress links, which can then be used as an exception string in caching plugins to disable caching.
Version: 1.0.0
Author: Bitbybit
Author URI: http://bitbybit.wordpress.com

Installation Instructions: Save this file as "admin-theme-preview-nocache.php" and place it in your wp-content/plugins/ directory.  Activate the plugin in the wordpress Plugins page, then add the following URI/string to your caching plugin cache exception strings (remove quotes): "?atp=nocache".  Browse your site normally, and if need be manually append "?atp=nocache" to any URLs which are being cached, eg: http://example.com/blog/ => http://example.com/blog/?atp=nocache

Upgrade Instructions: Overwrite old version with new version :P
*/ 

// Make sure user has sufficient permission to use this plugin
function atp_nocache_levelcheck() {
	if (current_user_can('switch_themes') || current_user_can('edit_themes')) {
		return('yay');
	} else {
		return('nay');
	}
}


// Append querystring to any URLs we're passed
function atp_nocache_querystring($url) {
        if ( atp_nocache_levelcheck() == 'nay' ) { return $url; }
        return $url . "?atp=nocache";
}


/*  --- Wordpress actions/filters used by this plugin --- */

// Add custom query string to links if caching enabled for this site
add_filter('category_link', 'atp_nocache_querystring');
add_filter('day_link', 'atp_nocache_querystring');
add_filter('month_link', 'atp_nocache_querystring');
add_filter('page_link', 'atp_nocache_querystring');
add_filter('post_link', 'atp_nocache_querystring');
add_filter('year_link', 'atp_nocache_querystring');

?>
