PluginProbe
Visual Website Optimizer / 2.1
Visual Website Optimizer v2.1
trunk 1.0 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.10 All 37 releases
← All changes | visual-website-optimizer.php +67 -193 4.02.1 View file →
@@ -1,13 +1,12 @@
1 1 <?php
2 2 /*
3 -Plugin Name: VWO
4 -Plugin URI: https://vwo.com/
5 -Description: VWO is the all-in-one platform that helps you conduct visitor research, build an optimization roadmap, and run continuous experimentation. Simply enable the plugin and start running tests on your Wordpress website without doing any other code changes. Visit <a href="https://vwo.com/">VWO</a> for more details.
6 -Author: VWO
7 -Version: 4.0
8 -visual-website-optimizer.php
9 -Author URI: https://vwo.com/
3 +Plugin Name: Visual Website Optimizer
4 +Plugin URI: http://visualwebsiteoptimizer.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: 2.1
8 +Author URI: http://fiddyp.co.uk
10 9
11 10 This relies on the actions being present in the themes header.php and footer.php
12 11 * header.php code before the closing </head> tag
13 12 * wp_head();
@@ -17,104 +16,46 @@
17 16 //------------------------------------------------------------------------//
18 17 //---Config---------------------------------------------------------------//
19 18 //------------------------------------------------------------------------//
20 19
21 -/**
22 - * Generate Common Code
23 - * @param type $vwo_id integer
24 - * @return type string
25 - */
26 -function get_vwo_clhf_script_common_code($vwo_clicks = 10) {
27 - ob_start();
28 - ?>
29 - <!-- Start VWO Common Smartcode -->
30 - <script <?php echo vwo_clhf_ignore_js_attr(); ?> type='text/javascript'>
31 - var _vwo_clicks = <?php echo $vwo_clicks ?>;
32 - </script>
33 - <!-- End VWO Common Smartcode -->
34 - <?php
35 - $script_code = ob_get_clean();
36 - return $script_code;
37 -}
20 +$clhf_header_script_sync = '
21 +<!-- Start Visual Website Optimizer Code -->
22 +<script type=\'text/javascript\'>
23 +var _vis_opt_account_id = VWO_ID;
24 +var _vis_opt_protocol = ((\'https:\' == document.location.protocol) ? \'https://\' : \'http://\');
25 +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>\');
26 +</script>
27 +<script type=\'text/javascript\'>
28 +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>\'); }
29 +</script>
30 +<script type=\'text/javascript\'>
31 +if(typeof(_vis_opt_settings_loaded) == "boolean" && typeof(_vis_opt_top_initialize) == "function"){ _vis_opt_top_initialize();
32 +vwo_$(document).ready(function() { _vis_opt_bottom_initialize(); }); }
33 +</script>
34 +<!-- End Visual Website Optimizer Code -->
35 +';
38 36
39 -/**
40 - * Get ignore js field setting
41 - * @return type boolean
42 - */
43 -function get_vwo_clhf_ignore_js(){
44 - $ignore_js = get_option('ignore_js');
45 - $ignore_js = ($ignore_js == '1') ? true : false;
46 - return $ignore_js;
47 -}
37 +$clhf_header_script_async = '
38 +<!-- Start Visual Website Optimizer Asynchronous Code -->
39 +<script type=\'text/javascript\'>
40 +var _vwo_code=(function(){
41 +var account_id=VWO_ID,
42 +settings_tolerance=SETTINGS_TOLERANCE,
43 +library_tolerance=LIBRARY_TOLERANCE,
44 +use_existing_jquery=false,
45 +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();
46 +</script>
47 +<!-- End Visual Website Optimizer Asynchronous Code -->
48 +';
48 49
49 -/**
50 - * Get ignore js script attribute value
51 - * @return type boolean
52 - */
53 -function vwo_clhf_ignore_js_attr(){
54 - $ignore_js = get_vwo_clhf_ignore_js();
55 - $js_attr = '';
56 - if(function_exists('get_vwo_clhf_ignore_js') && $ignore_js){
57 - $js_attr = 'data-cfasync="false"';
58 - }
59 - return $js_attr;
60 -}
61 50
62 -/**
63 - * Generate Synchronous Code
64 - * @param type $vwo_id integer
65 - * @return type string
66 - */
67 -function get_vwo_clhf_script_sync_code($vwo_id = 0) {
68 - ob_start();
69 - ?>
70 - <!-- Start VWO Smartcode -->
71 - <script <?php echo vwo_clhf_ignore_js_attr();?> src="https://dev.visualwebsiteoptimizer.com/lib/<?php echo $vwo_id ?>.js"></script>
72 - <!-- End VWO Smartcode -->
73 - <?php
74 - $sync_script = ob_get_clean();
75 - return $sync_script;
76 -}
77 -
78 -/**
79 - * Generate Asynchronous Code
80 - * @param type $vwo_id integer
81 - * @param type $settings_tolerance integer
82 - * @param type $library_tolerance integer
83 - * @param type $use_existing_jquery string
84 - * @return type string
85 - */
86 -function get_vwo_clhf_script_async_code($vwo_id, $settings_tolerance, $library_tolerance, $use_existing_jquery) {
87 - ob_start();
88 -?>
89 - <!-- Start VWO Async SmartCode -->
90 - <link rel="preconnect" href="https://dev.visualwebsiteoptimizer.com" />
91 - <script <?php echo vwo_clhf_ignore_js_attr(); ?> type='text/javascript' id='vwoCode'>
92 - /* Fix: wp-rocket (application/ld+json) */
93 - window._vwo_code || (function() {
94 - var account_id= <?php echo $vwo_id ?>,
95 - version = 2.0,
96 - settings_tolerance= <?php echo $settings_tolerance ?>,
97 - library_tolerance= <?php echo $library_tolerance ?>,
98 - use_existing_jquery= <?php echo ($use_existing_jquery) ? 'true' : 'false'; ?>,
99 - hide_element='body',
100 - hide_element_style = 'opacity:0 !important;filter:alpha(opacity=0) !important;background:none !important',
101 - /* DO NOT EDIT BELOW THIS LINE */
102 - f=false,w=window,d=document,v=d.querySelector('#vwoCode'),cK='_vwo_'+account_id+'_settings',cc={};try{var c=JSON.parse(localStorage.getItem('_vwo_'+account_id+'_config'));cc=c&&typeof c==='object'?c:{}}catch(e){}var stT=cc.stT==='session'?w.sessionStorage:w.localStorage;code={use_existing_jquery:function(){return typeof use_existing_jquery!=='undefined'?use_existing_jquery:undefined},library_tolerance:function(){return typeof library_tolerance!=='undefined'?library_tolerance:undefined},settings_tolerance:function(){return cc.sT||settings_tolerance},hide_element_style:function(){return'{'+(cc.hES||hide_element_style)+'}'},hide_element:function(){return typeof cc.hE==='string'?cc.hE:hide_element},getVersion:function(){return version},finish:function(){if(!f){f=true;var e=d.getElementById('_vis_opt_path_hides');if(e)e.parentNode.removeChild(e)}},finished:function(){return f},load:function(e){var t=this.getSettings(),n=d.createElement('script'),i=this;if(t){n.textContent=t;d.getElementsByTagName('head')[0].appendChild(n);if(!w.VWO||VWO.caE){stT.removeItem(cK);i.load(e)}}else{n.fetchPriority='high';n.src=e;n.type='text/javascript';n.onerror=function(){_vwo_code.finish()};d.getElementsByTagName('head')[0].appendChild(n)}},getSettings:function(){try{var e=stT.getItem(cK);if(!e){return}e=JSON.parse(e);if(Date.now()>e.e){stT.removeItem(cK);return}return e.s}catch(e){return}},init:function(){if(d.URL.indexOf('__vwo_disable__')>-1)return;var e=this.settings_tolerance();w._vwo_settings_timer=setTimeout(function(){_vwo_code.finish();stT.removeItem(cK)},e);var t=d.currentScript,n=d.createElement('style'),i=this.hide_element(),r=t&&!t.async&&i?i+this.hide_element_style():'',c=d.getElementsByTagName('head')[0];n.setAttribute('id','_vis_opt_path_hides');v&&n.setAttribute('nonce',v.nonce);n.setAttribute('type','text/css');if(n.styleSheet)n.styleSheet.cssText=r;else n.appendChild(d.createTextNode(r));c.appendChild(n);this.load('https://dev.visualwebsiteoptimizer.com/j.php?a='+account_id+'&u='+encodeURIComponent(d.URL)+'&vn='+version)}};w._vwo_code=code;code.init();})();
103 - </script>
104 - <!-- End VWO Async SmartCode -->
105 - <?php
106 - $async_script = ob_get_clean();
107 - return $async_script;
108 -}
109 -
110 51 //------------------------------------------------------------------------//
111 52 //---Hook-----------------------------------------------------------------//
112 53 //------------------------------------------------------------------------//
113 -add_action( 'wp_head', 'vwo_clhf_headercode',1 );
114 -add_action( 'admin_menu', 'vwo_clhf_plugin_menu' );
115 -add_action( 'admin_init', 'vwo_clhf_register_mysettings' );
116 -add_action( 'admin_notices','vwo_clhf_warn_nosettings');
54 +add_action ( 'wp_head', 'clhf_headercode',1 );
55 +add_action( 'admin_menu', 'clhf_plugin_menu' );
56 +add_action( 'admin_init', 'clhf_register_mysettings' );
57 +add_action( 'admin_notices','clhf_warn_nosettings');
117 58
118 59
119 60 //------------------------------------------------------------------------//
120 61 //---Functions------------------------------------------------------------//
@@ -119,77 +60,48 @@
119 60 //------------------------------------------------------------------------//
120 61 //---Functions------------------------------------------------------------//
121 62 //------------------------------------------------------------------------//
122 63 // options page link
123 -function vwo_clhf_plugin_menu() {
124 - add_options_page('Visual Website Optimizer', 'VWO', 'create_users', 'clhf_vwo_options', 'vwo_clhf_plugin_options');
64 +function clhf_plugin_menu() {
65 + add_options_page('Visual Website Optimizer', 'VWO', 'create_users', 'clhf_vwo_options', 'clhf_plugin_options');
125 66 }
126 67
127 68 // whitelist settings
128 -function vwo_clhf_register_mysettings(){
69 +function clhf_register_mysettings(){
129 70 register_setting('clhf_vwo_options','vwo_id','intval');
130 - register_setting('clhf_vwo_options','code_type');
131 - register_setting('clhf_vwo_options','vwo_clicks');
132 - register_setting('clhf_vwo_options','ignore_js','boolval');
71 + register_setting('clhf_vwo_options','code_type');
133 72 register_setting('clhf_vwo_options','settings_tolerance','intval');
134 73 register_setting('clhf_vwo_options','library_tolerance','intval');
135 - register_setting('clhf_vwo_options','use_existing_jquery','boolval');
136 74 }
137 75
138 76 //------------------------------------------------------------------------//
139 77 //---Output Functions-----------------------------------------------------//
140 78 //------------------------------------------------------------------------//
141 -function vwo_clhf_headercode() {
142 - // runs in the header
143 - $vwo_id = get_option('vwo_id');
144 - $code_type = get_option('code_type');
145 -
146 - if ($vwo_id) {
147 - if(empty(get_option('vwo_clicks'))){
148 - update_option('vwo_clicks', '10' );
149 - }
150 - $vwo_clicks = get_option('vwo_clicks');
151 - //common script code
152 - echo get_vwo_clhf_script_common_code($vwo_clicks);
153 - if ($code_type == 'SYNC') {
154 - //sync script code
155 - echo get_vwo_clhf_script_sync_code($vwo_id); // only output if options were saved
156 - } else {
157 -
158 - $settings_tolerance = get_option('settings_tolerance');
159 - if (!is_numeric($settings_tolerance))
160 - $settings_tolerance = 2000;
161 -
162 - $library_tolerance = get_option('library_tolerance');
163 - if (!is_numeric($library_tolerance))
164 - $library_tolerance = 2500;
165 -
166 - $use_existing_jquery = get_option('use_existing_jquery');
167 - $use_existing_jquery = ($use_existing_jquery == 1) ? true : false;
168 -
169 - //async script code
170 - echo get_vwo_clhf_script_async_code($vwo_id, $settings_tolerance, $library_tolerance, $use_existing_jquery);
171 - }
172 - }
79 +function clhf_headercode(){
80 + // runs in the header
81 + global $clhf_header_script_sync, $clhf_header_script_async;
82 + $vwo_id = get_option('vwo_id');
83 + $code_type = get_option('code_type');
84 + if($vwo_id){
85 + if($code_type == 'SYNC')
86 + echo str_replace('VWO_ID', $vwo_id, $clhf_header_script_sync); // only output if options were saved
87 + else {
88 + $settings_tolerance = get_option('settings_tolerance');
89 + $library_tolerance = get_option('library_tolerance');
90 + $clhf_header_script_async = str_replace('VWO_ID', $vwo_id, $clhf_header_script_async);
91 + $clhf_header_script_async = str_replace('SETTINGS_TOLERANCE', $settings_tolerance, $clhf_header_script_async);
92 + echo str_replace('LIBRARY_TOLERANCE', $library_tolerance, $clhf_header_script_async);
93 + }
94 + }
173 95 }
174 -
175 96 //------------------------------------------------------------------------//
176 97 //---Page Output Functions------------------------------------------------//
177 98 //------------------------------------------------------------------------//
178 99 // options page
179 -function vwo_clhf_plugin_options() {
180 - //Set value for checkbox by default
181 - $ignore_js_options = get_option('ignore_js');
182 - $show_ignore_js = $ignore_js_options;
183 - if( $ignore_js_options === false ) {
184 - // nothing is set, so apply the default here
185 - $show_ignore_js = 1;
186 - update_option('ignore_js', '1');
187 - }
188 -
189 - echo '<div class="wrap">';?>
190 - <h2>VWO</h2>
191 - <p>You need to have a <a href="https://vwo.com/">VWO</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>
100 +function clhf_plugin_options() {
101 + echo '<div class="wrap">';?>
102 + <h2>Visual Website Optimizer</h2>
103 + <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:</p>
192 104 <form method="post" action="options.php">
193 105 <?php settings_fields( 'clhf_vwo_options' ); ?>
194 106 <table class="form-table">
195 107 <tr valign="top">
@@ -195,18 +107,14 @@
195 107 <tr valign="top">
196 108 <th scope="row">Your VWO Account ID</th>
197 109 <td><input type="text" name="vwo_id" value="<?php echo get_option('vwo_id'); ?>" /></td>
198 110 </tr>
199 - <tr valign="top">
200 - <th scope="row">No. of Heatmap Clicks</th>
201 - <td><input type="number" name="vwo_clicks" value="<?php echo get_option('vwo_clicks') ? get_option('vwo_clicks'):10 ; ?>" min="3"/></td>
202 - </tr>
203 111 <tr valign="top">
204 112 <th scope="row">Code (default: Asynchronous)</th>
205 113 <td>
206 114 <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&nbsp;&nbsp;&nbsp;
207 115 <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
208 - &nbsp;<a href="https://vwo.com/blog/asynchronous-code" target="_blank">[Help]</a>
116 + &nbsp;<a href="http://visualwebsiteoptimizer.com/split-testing-blog/asynchronous-code" target="_blank">[Help]</a>
209 117 </td>
210 118 </tr>
211 119 <tr valign="top" id='asyncOnly1' <?php if(get_option('code_type')=='SYNC') echo "style='display:none;'" ?>>
212 120 <th scope="row">Settings Timeout</th>
@@ -213,18 +121,10 @@
213 121 <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>
214 122 </tr>
215 123 <tr valign="top" id='asyncOnly2' <?php if(get_option('code_type')=='SYNC') echo "style='display:none;'" ?>>
216 124 <th scope="row">Library Timeout</th>
217 - <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>
125 + <td style="vertical-align: middle;"><input type="text" name="library_tolerance" value="<?php echo get_option('library_tolerance')?get_option('library_tolerance'):1500; ?>" />ms (default: 1500)</td>
218 126 </tr>
219 - <tr valign="top" id='asyncOnly3' <?php if(get_option('code_type')=='SYNC') echo "style='display:none;'" ?>>
220 - <th scope="row">Use Existing jQuery</th>
221 - <td style="vertical-align: middle;"><input type="checkbox" name="use_existing_jquery" value="1" <?php if(get_option('use_existing_jquery') == true) echo "checked"; ?>/>Yes</td>
222 - </tr>
223 - <tr valign="top">
224 - <th scope="row">Skip Deferred Execution</th>
225 - <td style="vertical-align: middle;"><input type="checkbox" name="ignore_js" value="1" <?php if($show_ignore_js == true) echo "checked"; ?>/>Yes</td>
226 - </tr>
227 127 </table>
228 128
229 129 <script type="text/javascript">
230 130 function selectCodeType() {
@@ -234,53 +134,27 @@
234 134
235 135 if(code_type == 'ASYNC') {
236 136 document.getElementById('asyncOnly1').style.display = 'table-row';
237 137 document.getElementById('asyncOnly2').style.display = 'table-row';
238 - document.getElementById('asyncOnly3').style.display = 'table-row';
239 138 }
240 139 else {
241 140 document.getElementById('asyncOnly1').style.display = 'none';
242 141 document.getElementById('asyncOnly2').style.display = 'none';
243 - document.getElementById('asyncOnly3').style.display = 'none';
244 142 }
245 143 }
246 144 </script>
247 145 <p class="submit"><input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /></p>
248 - <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 VWO account.</p>
146 + <p>Your Account ID (a number) can be found in <i>Settings</i> area (top-right) after you <a href="https://v2.visualwebsiteoptimizer.com">login</a> into your Visual Website Optimizer account.</p>
249 147 <?php
250 148 echo '</div>';
251 149 }
252 150
253 -function vwo_clhf_warn_nosettings(){
151 +function clhf_warn_nosettings(){
254 152 if (!is_admin())
255 153 return;
256 154
257 155 $clhf_option = get_option("vwo_id");
258 156 if (!$clhf_option || $clhf_option < 1){
259 - echo "<div id='vwo-warning' class='updated fade'><p><strong>VWO 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>";
157 + 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>";
260 158 }
261 159 }
262 -
263 -
264 -add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'vwo_clhf_add_plugin_page_settings_link');
265 -/**
266 - * Function to add Settings Links on Plugin page
267 - * @param array $links
268 - * @return string
269 - */
270 -function vwo_clhf_add_plugin_page_settings_link( $links ) {
271 - $links[] = '<a href="' .
272 - admin_url( 'options-general.php?page=clhf_vwo_options' ) .
273 - '">' . __('Settings') . '</a>';
274 - return $links;
275 -}
276 -
277 -function disable_vwo_in_divi_builder(){
278 - if (has_action('wp_head', 'vwo_clhf_headercode') && function_exists('et_core_is_fb_enabled') && et_core_is_fb_enabled()){
279 - remove_action('wp_head', 'vwo_clhf_headercode', 1);
280 - }
281 - return;
282 -}
283 -
284 -add_action('wp_head', 'disable_vwo_in_divi_builder', 0);
285 -
286 160 ?>