| @@ -1,13 +1,13 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: VWO |
| 4 | 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: 3.3 | |
| 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/">Visual Website Optimizer</a> for more details. | |
| 6 | +Author: Wingify | |
| 7 | +Version: 2.8 | |
| 8 | 8 | visual-website-optimizer.php |
| 9 | -Author URI: https://vwo.com/ | |
| 9 | +Author URI: https://wingify.com | |
| 10 | 10 | |
| 11 | 11 | This relies on the actions being present in the themes header.php and footer.php |
| 12 | 12 | * header.php code before the closing </head> tag |
| 13 | 13 | * wp_head(); |
| @@ -17,71 +17,38 @@ | ||
| 17 | 17 | //------------------------------------------------------------------------// |
| 18 | 18 | //---Config---------------------------------------------------------------// |
| 19 | 19 | //------------------------------------------------------------------------// |
| 20 | 20 | |
| 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 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 | -} | |
| 21 | +$clhf_header_script_sync = ' | |
| 22 | +<!-- Start VWO Code --> | |
| 23 | +<script type=\'text/javascript\'> | |
| 24 | +var _vis_opt_account_id = VWO_ID; | |
| 25 | +var _vis_opt_protocol = ((\'https:\' == document.location.protocol) ? \'https://\' : \'http://\'); | |
| 26 | +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>\'); | |
| 27 | +</script> | |
| 28 | +<script type=\'text/javascript\'> | |
| 29 | +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>\'); } | |
| 30 | +</script> | |
| 31 | +<script type=\'text/javascript\'> | |
| 32 | +if(typeof(_vis_opt_settings_loaded) == "boolean" && typeof(_vis_opt_top_initialize) == "function"){ _vis_opt_top_initialize(); | |
| 33 | +vwo_$(document).ready(function() { _vis_opt_bottom_initialize(); }); } | |
| 34 | +</script> | |
| 35 | +<!-- End VWO Code --> | |
| 36 | +'; | |
| 38 | 37 | |
| 39 | -/** | |
| 40 | - * Generate Synchronous Code | |
| 41 | - * @param type $vwo_id integer | |
| 42 | - * @return type string | |
| 43 | - */ | |
| 44 | -function get_vwo_clhf_script_sync_code($vwo_id = 0) { | |
| 45 | - ob_start(); | |
| 46 | - ?> | |
| 47 | - <!-- Start VWO Smartcode --> | |
| 48 | - <script src="https://dev.visualwebsiteoptimizer.com/lib/<?php echo $vwo_id ?>.js"></script> | |
| 49 | - <!-- End VWO Smartcode --> | |
| 50 | - <?php | |
| 51 | - $sync_script = ob_get_clean(); | |
| 52 | - return $sync_script; | |
| 53 | -} | |
| 38 | +$clhf_header_script_async = ' | |
| 39 | +<!-- Start VWO Asynchronous Code --> | |
| 40 | +<script type=\'text/javascript\'> | |
| 41 | +var _vwo_code=(function(){ | |
| 42 | +var account_id=VWO_ID, | |
| 43 | +settings_tolerance=SETTINGS_TOLERANCE, | |
| 44 | +library_tolerance=LIBRARY_TOLERANCE, | |
| 45 | +use_existing_jquery=false, | |
| 46 | +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(); | |
| 47 | +</script> | |
| 48 | +<!-- End VWO Asynchronous Code --> | |
| 49 | +'; | |
| 54 | 50 | |
| 55 | -/** | |
| 56 | - * Generate Asynchronous Code | |
| 57 | - * @param type $vwo_id integer | |
| 58 | - * @param type $settings_tolerance integer | |
| 59 | - * @param type $library_tolerance integer | |
| 60 | - * @param type $use_existing_jquery string | |
| 61 | - * @return type string | |
| 62 | - */ | |
| 63 | -function get_vwo_clhf_script_async_code($vwo_id = 0, $settings_tolerance, $library_tolerance, $use_existing_jquery) { | |
| 64 | - ob_start(); | |
| 65 | -?> | |
| 66 | - <!-- Start VWO Async Smartcode --> | |
| 67 | - <script type='text/javascript'> | |
| 68 | - window._vwo_code = window._vwo_code || (function(){ | |
| 69 | - var account_id= <?php echo $vwo_id ?>, | |
| 70 | - settings_tolerance= <?php echo $settings_tolerance ?>, | |
| 71 | - library_tolerance= <?php echo $library_tolerance ?>, | |
| 72 | - use_existing_jquery= <?php echo ($use_existing_jquery) ? 'true' : 'false'; ?>, | |
| 73 | - is_spa=1, | |
| 74 | - hide_element='body', | |
| 75 | - /* DO NOT EDIT BELOW THIS LINE */ | |
| 76 | - f=false,d=document,code={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(){ | |
| 77 | - window.settings_timer=setTimeout('_vwo_code.finish()',settings_tolerance);var a=d.createElement('style'),b=hide_element?hide_element+'{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);this.load('https://dev.visualwebsiteoptimizer.com/j.php?a='+account_id+'&u='+encodeURIComponent(d.URL)+'&f='+(+is_spa)+'&r='+Math.random());return settings_timer; }};window._vwo_settings_timer = code.init(); return code; }()); | |
| 78 | - </script> | |
| 79 | - <!-- End VWO Async Smartcode --> | |
| 80 | - <?php | |
| 81 | - $async_script = ob_get_clean(); | |
| 82 | - return $async_script; | |
| 83 | -} | |
| 84 | 51 | |
| 85 | 52 | //------------------------------------------------------------------------// |
| 86 | 53 | //---Hook-----------------------------------------------------------------// |
| 87 | 54 | //------------------------------------------------------------------------// |
| @@ -101,52 +68,37 @@ | ||
| 101 | 68 | |
| 102 | 69 | // whitelist settings |
| 103 | 70 | function vwo_clhf_register_mysettings(){ |
| 104 | 71 | register_setting('clhf_vwo_options','vwo_id','intval'); |
| 105 | - register_setting('clhf_vwo_options','code_type'); | |
| 106 | - register_setting('clhf_vwo_options','vwo_clicks'); | |
| 72 | + register_setting('clhf_vwo_options','code_type'); | |
| 107 | 73 | register_setting('clhf_vwo_options','settings_tolerance','intval'); |
| 108 | 74 | register_setting('clhf_vwo_options','library_tolerance','intval'); |
| 109 | - register_setting('clhf_vwo_options','use_existing_jquery','boolval'); | |
| 110 | 75 | } |
| 111 | 76 | |
| 112 | 77 | //------------------------------------------------------------------------// |
| 113 | 78 | //---Output Functions-----------------------------------------------------// |
| 114 | 79 | //------------------------------------------------------------------------// |
| 115 | -function vwo_clhf_headercode() { | |
| 116 | - // runs in the header | |
| 117 | - $vwo_id = get_option('vwo_id'); | |
| 118 | - $code_type = get_option('code_type'); | |
| 119 | - | |
| 120 | - if ($vwo_id) { | |
| 121 | - if(empty(get_option('vwo_clicks'))){ | |
| 122 | - update_option('vwo_clicks', '10' ); | |
| 123 | - } | |
| 124 | - $vwo_clicks = get_option('vwo_clicks'); | |
| 125 | - //common script code | |
| 126 | - echo get_vwo_clhf_script_common_code($vwo_clicks); | |
| 127 | - if ($code_type == 'SYNC') { | |
| 128 | - //sync script code | |
| 129 | - echo get_vwo_clhf_script_sync_code($vwo_id); // only output if options were saved | |
| 130 | - } else { | |
| 80 | +function vwo_clhf_headercode(){ | |
| 81 | + // runs in the header | |
| 82 | + global $clhf_header_script_sync, $clhf_header_script_async; | |
| 83 | + $vwo_id = get_option('vwo_id'); | |
| 84 | + $code_type = get_option('code_type'); | |
| 85 | + if($vwo_id){ | |
| 86 | + if($code_type == 'SYNC') | |
| 87 | + echo str_replace('VWO_ID', $vwo_id, $clhf_header_script_sync); // only output if options were saved | |
| 88 | + else { | |
| 89 | + $settings_tolerance = get_option('settings_tolerance'); | |
| 90 | + if(!is_numeric($settings_tolerance)) $settings_tolerance = 2000; | |
| 131 | 91 | |
| 132 | - $settings_tolerance = get_option('settings_tolerance'); | |
| 133 | - if (!is_numeric($settings_tolerance)) | |
| 134 | - $settings_tolerance = 2000; | |
| 92 | + $library_tolerance = get_option('library_tolerance'); | |
| 93 | + if(!is_numeric($library_tolerance)) $library_tolerance = 2500; | |
| 135 | 94 | |
| 136 | - $library_tolerance = get_option('library_tolerance'); | |
| 137 | - if (!is_numeric($library_tolerance)) | |
| 138 | - $library_tolerance = 2500; | |
| 139 | - | |
| 140 | - $use_existing_jquery = get_option('use_existing_jquery'); | |
| 141 | - $use_existing_jquery = ($use_existing_jquery == 1) ? true : false; | |
| 142 | - | |
| 143 | - //async script code | |
| 144 | - echo get_vwo_clhf_script_async_code($vwo_id, $settings_tolerance, $library_tolerance, $use_existing_jquery); | |
| 145 | - } | |
| 146 | - } | |
| 95 | + $clhf_header_script_async = str_replace('VWO_ID', $vwo_id, $clhf_header_script_async); | |
| 96 | + $clhf_header_script_async = str_replace('SETTINGS_TOLERANCE', $settings_tolerance, $clhf_header_script_async); | |
| 97 | + echo str_replace('LIBRARY_TOLERANCE', $library_tolerance, $clhf_header_script_async); | |
| 98 | + } | |
| 99 | + } | |
| 147 | 100 | } |
| 148 | - | |
| 149 | 101 | //------------------------------------------------------------------------// |
| 150 | 102 | //---Page Output Functions------------------------------------------------// |
| 151 | 103 | //------------------------------------------------------------------------// |
| 152 | 104 | // options page |
| @@ -160,12 +112,8 @@ | ||
| 160 | 112 | <tr valign="top"> |
| 161 | 113 | <th scope="row">Your VWO Account ID</th> |
| 162 | 114 | <td><input type="text" name="vwo_id" value="<?php echo get_option('vwo_id'); ?>" /></td> |
| 163 | 115 | </tr> |
| 164 | - <tr valign="top"> | |
| 165 | - <th scope="row">No. of Heatmap Clicks</th> | |
| 166 | - <td><input type="number" name="vwo_clicks" value="<?php echo get_option('vwo_clicks') ? get_option('vwo_clicks'):10 ; ?>" min="3"/></td> | |
| 167 | - </tr> | |
| 168 | 116 | <tr valign="top"> |
| 169 | 117 | <th scope="row">Code (default: Asynchronous)</th> |
| 170 | 118 | <td> |
| 171 | 119 | <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 |
| @@ -180,12 +128,8 @@ | ||
| 180 | 128 | <tr valign="top" id='asyncOnly2' <?php if(get_option('code_type')=='SYNC') echo "style='display:none;'" ?>> |
| 181 | 129 | <th scope="row">Library Timeout</th> |
| 182 | 130 | <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> |
| 183 | 131 | </tr> |
| 184 | - <tr valign="top" id='asyncOnly3' <?php if(get_option('code_type')=='SYNC') echo "style='display:none;'" ?>> | |
| 185 | - <th scope="row">Use Existing jQuery</th> | |
| 186 | - <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> | |
| 187 | - </tr> | |
| 188 | 132 | </table> |
| 189 | 133 | |
| 190 | 134 | <script type="text/javascript"> |
| 191 | 135 | function selectCodeType() { |
| @@ -195,14 +139,12 @@ | ||
| 195 | 139 | |
| 196 | 140 | if(code_type == 'ASYNC') { |
| 197 | 141 | document.getElementById('asyncOnly1').style.display = 'table-row'; |
| 198 | 142 | document.getElementById('asyncOnly2').style.display = 'table-row'; |
| 199 | - document.getElementById('asyncOnly3').style.display = 'table-row'; | |
| 200 | 143 | } |
| 201 | 144 | else { |
| 202 | 145 | document.getElementById('asyncOnly1').style.display = 'none'; |
| 203 | 146 | document.getElementById('asyncOnly2').style.display = 'none'; |
| 204 | - document.getElementById('asyncOnly3').style.display = 'none'; | |
| 205 | 147 | } |
| 206 | 148 | } |
| 207 | 149 | </script> |
| 208 | 150 | <p class="submit"><input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /></p> |
| @@ -219,20 +161,5 @@ | ||
| 219 | 161 | if (!$clhf_option || $clhf_option < 1){ |
| 220 | 162 | 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>"; |
| 221 | 163 | } |
| 222 | 164 | } |
| 223 | - | |
| 224 | - | |
| 225 | -add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'vwo_clhf_add_plugin_page_settings_link'); | |
| 226 | -/** | |
| 227 | - * Function to add Settings Links on Plugin page | |
| 228 | - * @param array $links | |
| 229 | - * @return string | |
| 230 | - */ | |
| 231 | -function vwo_clhf_add_plugin_page_settings_link( $links ) { | |
| 232 | - $links[] = '<a href="' . | |
| 233 | - admin_url( 'options-general.php?page=clhf_vwo_options' ) . | |
| 234 | - '">' . __('Settings') . '</a>'; | |
| 235 | - return $links; | |
| 236 | -} | |
| 237 | - | |
| 238 | 165 | ?> |