| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Visual Website Optimizer |
| 4 |
Plugin URI: http://comluv.com |
| 5 |
Description: Visual Website Optimizer is the world's easiest to use A/B, split and multivariate testing tool. Simply enable the plugin and start running tests on your Wordpress website without doing any other code changes. Visit <a href="http://visualwebsiteoptimizer.com/">Visual Website Optimizer</a> for more details. |
| 6 |
Author: Andy Bailey |
| 7 |
Version: 1.0 |
| 8 |
Author URI: http://fiddyp.co.uk |
| 9 |
|
| 10 |
This relies on the actions being present in the themes header.php and footer.php |
| 11 |
* header.php code before the closing </head> tag |
| 12 |
* wp_head(); |
| 13 |
* |
| 14 |
* footer.php code before </body> (maybe before last </div>) |
| 15 |
* do_action('wp_footer'); |
| 16 |
* |
| 17 |
*/ |
| 18 |
|
| 19 |
//------------------------------------------------------------------------// |
| 20 |
//---Config---------------------------------------------------------------// |
| 21 |
//------------------------------------------------------------------------// |
| 22 |
|
| 23 |
$clhf_header_script = ' |
| 24 |
<!-- Start Top Visual Website Optimizer Code --> |
| 25 |
<script type=\'text/javascript\'> |
| 26 |
var _vis_opt_account_id = VWO_ID; |
| 27 |
var _vis_opt_protocol = ((\'https:\' == document.location.protocol) ? \'https://\' : \'http://\'); |
| 28 |
document.write(unescape(\'%3Cscript src=\"\' + _vis_opt_protocol + \'s3.amazonaws.com/wingify/vis_opt.js\" type=\"text/javascript\"%3E%3C/script%3E\')); |
| 29 |
</script> |
| 30 |
<script type=\'text/javascript\'> |
| 31 |
if(typeof(_vis_opt_top_initialize) == "function") { document.write(unescape(\'%3Cscript src=\"\' + _vis_opt_protocol + \'dev.visualwebsiteoptimizer.com/deploy/js_visitor_settings.php?a=\'+_vis_opt_account_id+\'&random=\'+Math.random()+\'\" type=\"text/javascript\"%3E%3C/script%3E\')); } |
| 32 |
</script> |
| 33 |
<script type=\'text/javascript\'> |
| 34 |
if(typeof(_vis_opt_settings_loaded) == "boolean" && typeof(_vis_opt_top_initialize) == "function"){ _vis_opt_top_initialize(); } |
| 35 |
</script> |
| 36 |
<!-- End Top Visual Website Optimizer Code --> |
| 37 |
'; |
| 38 |
|
| 39 |
$clhf_footer_script = ' |
| 40 |
<!-- Start Bottom Visual Website Optimizer Code --> |
| 41 |
<script type=\'text/javascript\'> |
| 42 |
if(typeof(_vis_opt_settings_loaded) == "boolean" && typeof(_vis_opt_bottom_initialize) == "function") |
| 43 |
{_vis_opt_bottom_initialize();} |
| 44 |
</script> |
| 45 |
<!-- End Bottom Visual Website Optimizer Code --> |
| 46 |
'; |
| 47 |
|
| 48 |
//------------------------------------------------------------------------// |
| 49 |
//---Hook-----------------------------------------------------------------// |
| 50 |
//------------------------------------------------------------------------// |
| 51 |
add_action ( 'wp_footer', 'clhf_footercode',10 ); |
| 52 |
add_action ( 'wp_head', 'clhf_headercode',1 ); |
| 53 |
add_action( 'admin_menu', 'clhf_plugin_menu' ); |
| 54 |
add_action( 'admin_init', 'clhf_register_mysettings' ); |
| 55 |
add_action( 'admin_notices','clhf_warn_nosettings'); |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
//------------------------------------------------------------------------// |
| 60 |
//---Functions------------------------------------------------------------// |
| 61 |
//------------------------------------------------------------------------// |
| 62 |
// options page link |
| 63 |
function clhf_plugin_menu() { |
| 64 |
add_options_page('Visual Website Optimizer', 'VWO', 'create_users', 'clhf_vwo_options', 'clhf_plugin_options'); |
| 65 |
} |
| 66 |
|
| 67 |
// whitelist settings |
| 68 |
function clhf_register_mysettings(){ |
| 69 |
register_setting('clhf_vwo_options','vwo_id','intval'); |
| 70 |
} |
| 71 |
|
| 72 |
//------------------------------------------------------------------------// |
| 73 |
//---Output Functions-----------------------------------------------------// |
| 74 |
//------------------------------------------------------------------------// |
| 75 |
function clhf_headercode(){ |
| 76 |
// runs in the header |
| 77 |
global $clhf_header_script; |
| 78 |
$vwo_id = get_option('vwo_id'); |
| 79 |
if($vwo_id){ |
| 80 |
// only output if options were saved |
| 81 |
echo str_replace('VWO_ID',$vwo_id,$clhf_header_script); |
| 82 |
} |
| 83 |
|
| 84 |
} |
| 85 |
function clhf_footercode(){ |
| 86 |
// runs in the footer |
| 87 |
global $clhf_footer_script; |
| 88 |
$vwo_id = get_option('vwo_id'); |
| 89 |
if($vwo_id){ |
| 90 |
// only output if header was done |
| 91 |
echo $clhf_footer_script; |
| 92 |
} |
| 93 |
} |
| 94 |
//------------------------------------------------------------------------// |
| 95 |
//---Page Output Functions------------------------------------------------// |
| 96 |
//------------------------------------------------------------------------// |
| 97 |
// options page |
| 98 |
function clhf_plugin_options() { |
| 99 |
echo '<div class="wrap">';?> |
| 100 |
<h2>Visual Website Optimizer</h2> |
| 101 |
<p>You need to have a <a href="http://visualwebsiteoptimizer.com/">Visual Website Optimizer</a> account in order to use this plugin. This plugin inserts the neccessary code into your Wordpress site automatically without you having to touch anything. In order to use the plugin, you need to enter your VWO Account ID in the field below:</p> |
| 102 |
<form method="post" action="options.php"> |
| 103 |
<?php settings_fields( 'clhf_vwo_options' ); ?> |
| 104 |
<table class="form-table"> |
| 105 |
<tr valign="top"> |
| 106 |
<th scope="row">Your VWO Account ID</th> |
| 107 |
<td><input type="text" name="vwo_id" value="<?php echo get_option('vwo_id'); ?>" /></td> |
| 108 |
</tr> |
| 109 |
</table> |
| 110 |
<p class="submit"> |
| 111 |
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> |
| 112 |
</p> |
| 113 |
<p>Your Account ID (a number) can be found in <i>Settings</i> area (top-left, just under the logo) after you <a href="https://dev.visualwebsiteoptimizer.com/login.php">login</a> into your Visual Website Optimizer account</a>. |
| 114 |
<div style="padding: 5px; border-top: 1px solid #000000; border-left: 1px solid #000000; border-bottom: 1px solid #cccccc; border-right: 1px solid #cccccc; display:none"> |
| 115 |
<?php |
| 116 |
global $clhf_header_script; |
| 117 |
echo str_replace(array('VWO_ID',"\n"),array('<span class="updated">Your ID Here</span>','<br>'),htmlspecialchars($clhf_header_script)); |
| 118 |
?> |
| 119 |
</div> |
| 120 |
<?php |
| 121 |
echo '</div>'; |
| 122 |
} |
| 123 |
|
| 124 |
function clhf_warn_nosettings(){ |
| 125 |
if (!is_admin()) |
| 126 |
return; |
| 127 |
|
| 128 |
$clhf_option = get_option("vwo_id"); |
| 129 |
if (!$clhf_option || $clhf_option < 1){ |
| 130 |
echo "<div id='vwo-warning' class='updated fade'><p><strong>Visual Website Optimizer is almost ready.</strong> You must <a href=\"options-general.php?page=clhf_vwo_options\">enter your Account ID</a> for it to work.</p></div>"; |
| 131 |
} |
| 132 |
} |
| 133 |
?> |