/*
Plugin Name: SES Theme Split Test
Plugin URI: http://www.leewillis.co.uk/
Description: Split test your wordpress theme, and track test using Google Analytics user defined values. Based on an idea by http://www.dellanave.com/blog/2009/07/15/how-to-split-test-your-wordpress-theme-w-plugin/
Author: Lee Willis
Version: 0.1
Author URI: http://www.leewillis.co.uk
*/
function ses_splittest_menu() {
add_options_page('SES Theme Split Test Settings', 'SES Theme Split Test', 10, basename(__FILE__), 'ses_splittest_options');
}
add_action("admin_menu", "ses_splittest_menu");
function ses_splittest_options() {
if ( isset($_POST['submit']) ) {
if (!current_user_can( 'manage_options' ))
die(__( 'You cannot edit the options.' ));
check_admin_referer( 'ses-splittest-updatesettings' );
if ($_POST['sesthemes'] != "") {
foreach(array_keys($_POST['sesthemes']) as $key) {
$ses_theme_list[] = $key;
}
}
update_option("ses_splittest_themes", $ses_theme_list);
echo '
'.__('Settings updated.').'
';
}
$ses_theme_list = "";
$ses_theme_list = get_option("ses_splittest_themes");
?>
}
class ses_splittest{
var $splittest = "";
function ses_splittest(){
$this->splittest = false;
add_action('plugins_loaded',array(&$this,'detectsplittest'));
add_action('wp_footer',array(&$this, 'output_themesetvar'),99);
add_filter('stylesheet',array(&$this,'get_stylesheet'));
add_filter('template',array(&$this,'get_template'));
}
function detectsplittest($query){
$ses_theme_list = get_option("ses_splittest_themes");
if (count($ses_theme_list) < 2) {
return;
}
if($_COOKIE['wp_splittest1']) {
$theme = $_COOKIE['wp_splittest1'];
}
// No cookie, or Theme is no longer part of split test - assign a new one
if (!isset($theme) || !in_array($theme, $ses_theme_list)) {
$id = rand(0,count($ses_theme_list)-1);
$theme = $ses_theme_list[$id];
}
setcookie("wp_splittest1",$theme,time()+(60*60*24*30),'/');
$this->splittest = $theme;
}
function get_stylesheet($stylesheet) {
if ($this->splittest != "") {
return $this->splittest;
} else {
return $stylesheet;
}
}
function get_template($template) {
if ($this->splittest != "") {
return $this->splittest;
} else {
return $template;
}
}
function output_themesetvar() {
if ($this->splittest != "") {
echo '';
}
}
}
$ses_splittest = new ses_splittest();
?>