| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Visual Website Optimizer |
| 4 |
Plugin URI: https://vwo.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="https://vwo.com/">Visual Website Optimizer</a> for more details. |
| 6 |
Author: Andy Bailey |
| 7 |
Version: 2.4 |
| 8 |
screenshot-1.png |
| 9 |
screenshot-2.png |
| 10 |
visual-website-optimizer.php |
| 11 |
Author URI: http://fiddyp.co.uk |
| 12 |
|
| 13 |
This relies on the actions being present in the themes header.php and footer.php |
| 14 |
* header.php code before the closing </head> tag |
| 15 |
* wp_head(); |
| 16 |
* |
| 17 |
*/ |
| 18 |
|
| 19 |
//------------------------------------------------------------------------// |
| 20 |
//---Config---------------------------------------------------------------// |
| 21 |
//------------------------------------------------------------------------// |
| 22 |
|
| 23 |
$clhf_header_script_sync = ' |
| 24 |
<!-- Start 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(\'<s\' + \'cript src="\' + _vis_opt_protocol + \'dev.visualwebsiteoptimizer.com/deploy/js_visitor_settings.php?v=1&a=\'+_vis_opt_account_id+\'&url=\'+encodeURIComponent(document.URL)+\'&random=\'+Math.random()+\'" type="text/javascript">\' + \'<\/s\' + \'cript>\'); |
| 29 |
</script> |
| 30 |
<script type=\'text/javascript\'> |
| 31 |
if(typeof(_vis_opt_settings_loaded) == "boolean") { document.write(\'<s\' + \'cript src="\' + _vis_opt_protocol + \'d5phz18u4wuww.cloudfront.net/vis_opt.js" type="text/javascript">\' + \'<\/s\' + \'cript>\'); } |
| 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 |
vwo_$(document).ready(function() { _vis_opt_bottom_initialize(); }); } |
| 36 |
</script> |
| 37 |
<!-- End Visual Website Optimizer Code --> |
| 38 |
'; |
| 39 |
|
| 40 |
$clhf_header_script_async = ' |
| 41 |
<!-- Start Visual Website Optimizer Asynchronous Code --> |
| 42 |
<script type=\'text/javascript\'> |
| 43 |
var _vwo_code=(function(){ |
| 44 |
var account_id=VWO_ID, |
| 45 |
settings_tolerance=SETTINGS_TOLERANCE, |
| 46 |
library_tolerance=LIBRARY_TOLERANCE, |
| 47 |
use_existing_jquery=false, |
| 48 |
f=false,d=document;return{use_existing_jquery:function(){return use_existing_jquery;},library_tolerance:function(){return library_tolerance;},finish:function(){if(!f){f=true;var a=d.getElementById(\'_vis_opt_path_hides\');if(a)a.parentNode.removeChild(a);}},finished:function(){return f;},load:function(a){var b=d.createElement(\'script\');b.src=a;b.type=\'text/javascript\';b.innerText;b.onerror=function(){_vwo_code.finish();};d.getElementsByTagName(\'head\')[0].appendChild(b);},init:function(){settings_timer=setTimeout(\'_vwo_code.finish()\',settings_tolerance);this.load(\'//dev.visualwebsiteoptimizer.com/j.php?a=\'+account_id+\'&u=\'+encodeURIComponent(d.URL)+\'&r=\'+Math.random());var a=d.createElement(\'style\'),b=\'body{opacity:0 !important;filter:alpha(opacity=0) !important;background:none !important;}\',h=d.getElementsByTagName(\'head\')[0];a.setAttribute(\'id\',\'_vis_opt_path_hides\');a.setAttribute(\'type\',\'text/css\');if(a.styleSheet)a.styleSheet.cssText=b;else a.appendChild(d.createTextNode(b));h.appendChild(a);return settings_timer;}};}());_vwo_settings_timer=_vwo_code.init(); |
| 49 |
</script> |
| 50 |
<!-- End Visual Website Optimizer Asynchronous Code --> |
| 51 |
'; |
| 52 |
|
| 53 |
|
| 54 |
//------------------------------------------------------------------------// |
| 55 |
//---Hook-----------------------------------------------------------------// |
| 56 |
//------------------------------------------------------------------------// |
| 57 |
add_action ( 'wp_head', 'clhf_headercode',1 ); |
| 58 |
add_action( 'admin_menu', 'clhf_plugin_menu' ); |
| 59 |
add_action( 'admin_init', 'clhf_register_mysettings' ); |
| 60 |
add_action( 'admin_notices','clhf_warn_nosettings'); |
| 61 |
|
| 62 |
|
| 63 |
//------------------------------------------------------------------------// |
| 64 |
//---Functions------------------------------------------------------------// |
| 65 |
//------------------------------------------------------------------------// |
| 66 |
// options page link |
| 67 |
function clhf_plugin_menu() { |
| 68 |
add_options_page('Visual Website Optimizer', 'VWO', 'create_users', 'clhf_vwo_options', 'clhf_plugin_options'); |
| 69 |
} |
| 70 |
|
| 71 |
// whitelist settings |
| 72 |
function clhf_register_mysettings(){ |
| 73 |
register_setting('clhf_vwo_options','vwo_id','intval'); |
| 74 |
register_setting('clhf_vwo_options','code_type'); |
| 75 |
register_setting('clhf_vwo_options','settings_tolerance','intval'); |
| 76 |
register_setting('clhf_vwo_options','library_tolerance','intval'); |
| 77 |
} |
| 78 |
|
| 79 |
//------------------------------------------------------------------------// |
| 80 |
//---Output Functions-----------------------------------------------------// |
| 81 |
//------------------------------------------------------------------------// |
| 82 |
function clhf_headercode(){ |
| 83 |
// runs in the header |
| 84 |
global $clhf_header_script_sync, $clhf_header_script_async; |
| 85 |
$vwo_id = get_option('vwo_id'); |
| 86 |
$code_type = get_option('code_type'); |
| 87 |
if($vwo_id){ |
| 88 |
if($code_type == 'SYNC') |
| 89 |
echo str_replace('VWO_ID', $vwo_id, $clhf_header_script_sync); // only output if options were saved |
| 90 |
else { |
| 91 |
$settings_tolerance = get_option('settings_tolerance'); |
| 92 |
if(!is_numeric($settings_tolerance)) $settings_tolerance = 2000; |
| 93 |
|
| 94 |
$library_tolerance = get_option('library_tolerance'); |
| 95 |
if(!is_numeric($library_tolerance)) $library_tolerance = 2500; |
| 96 |
|
| 97 |
$clhf_header_script_async = str_replace('VWO_ID', $vwo_id, $clhf_header_script_async); |
| 98 |
$clhf_header_script_async = str_replace('SETTINGS_TOLERANCE', $settings_tolerance, $clhf_header_script_async); |
| 99 |
echo str_replace('LIBRARY_TOLERANCE', $library_tolerance, $clhf_header_script_async); |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
//------------------------------------------------------------------------// |
| 104 |
//---Page Output Functions------------------------------------------------// |
| 105 |
//------------------------------------------------------------------------// |
| 106 |
// options page |
| 107 |
function clhf_plugin_options() { |
| 108 |
echo '<div class="wrap">';?> |
| 109 |
<h2>Visual Website Optimizer</h2> |
| 110 |
<p>You need to have a <a href="https://vwo.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:</p> |
| 111 |
<form method="post" action="options.php"> |
| 112 |
<?php settings_fields( 'clhf_vwo_options' ); ?> |
| 113 |
<table class="form-table"> |
| 114 |
<tr valign="top"> |
| 115 |
<th scope="row">Your VWO Account ID</th> |
| 116 |
<td><input type="text" name="vwo_id" value="<?php echo get_option('vwo_id'); ?>" /></td> |
| 117 |
</tr> |
| 118 |
<tr valign="top"> |
| 119 |
<th scope="row">Code (default: Asynchronous)</th> |
| 120 |
<td> |
| 121 |
<input style="vertical-align: text-top;" type="radio" onclick="selectCodeType();" name="code_type" id="code_type_async" value="ASYNC" <?php if(get_option('code_type')!='SYNC') echo "checked"; ?> /> Asynchronous |
| 122 |
<input style="vertical-align: text-top;" type="radio" onclick="selectCodeType();" name="code_type" id="code_type_sync" value="SYNC" <?php if(get_option('code_type')=='SYNC') echo "checked"; ?> /> Synchronous |
| 123 |
<a href="https://vwo.com/blog/asynchronous-code" target="_blank">[Help]</a> |
| 124 |
</td> |
| 125 |
</tr> |
| 126 |
<tr valign="top" id='asyncOnly1' <?php if(get_option('code_type')=='SYNC') echo "style='display:none;'" ?>> |
| 127 |
<th scope="row">Settings Timeout</th> |
| 128 |
<td style="vertical-align: middle;"><input type="text" name="settings_tolerance" value="<?php echo get_option('settings_tolerance')?get_option('settings_tolerance'):2000; ?>" />ms (default: 2000)</td> |
| 129 |
</tr> |
| 130 |
<tr valign="top" id='asyncOnly2' <?php if(get_option('code_type')=='SYNC') echo "style='display:none;'" ?>> |
| 131 |
<th scope="row">Library Timeout</th> |
| 132 |
<td style="vertical-align: middle;"><input type="text" name="library_tolerance" value="<?php echo get_option('library_tolerance')?get_option('library_tolerance'):2500; ?>" />ms (default: 2500)</td> |
| 133 |
</tr> |
| 134 |
</table> |
| 135 |
|
| 136 |
<script type="text/javascript"> |
| 137 |
function selectCodeType() { |
| 138 |
var code_type = 'ASYNC'; |
| 139 |
if(document.getElementById('code_type_sync').checked) |
| 140 |
code_type = 'SYNC'; |
| 141 |
|
| 142 |
if(code_type == 'ASYNC') { |
| 143 |
document.getElementById('asyncOnly1').style.display = 'table-row'; |
| 144 |
document.getElementById('asyncOnly2').style.display = 'table-row'; |
| 145 |
} |
| 146 |
else { |
| 147 |
document.getElementById('asyncOnly1').style.display = 'none'; |
| 148 |
document.getElementById('asyncOnly2').style.display = 'none'; |
| 149 |
} |
| 150 |
} |
| 151 |
</script> |
| 152 |
<p class="submit"><input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /></p> |
| 153 |
<p>Your Account ID (a number) can be found in <i>Settings</i> area (top-right) after you <a href="https://app.vwo.com">login</a> into your Visual Website Optimizer account.</p> |
| 154 |
<?php |
| 155 |
echo '</div>'; |
| 156 |
} |
| 157 |
|
| 158 |
function clhf_warn_nosettings(){ |
| 159 |
if (!is_admin()) |
| 160 |
return; |
| 161 |
|
| 162 |
$clhf_option = get_option("vwo_id"); |
| 163 |
if (!$clhf_option || $clhf_option < 1){ |
| 164 |
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>"; |
| 165 |
} |
| 166 |
} |
| 167 |
?> |
| 168 |
|