| @@ -1,135 +1,306 @@ | ||
| 1 | 1 | <?php |
| 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/">Visual Website Optimizer</a> for more details. | |
| 6 | -Author: Wingify | |
| 7 | -Version: 2.7 | |
| 8 | -visual-website-optimizer.php | |
| 9 | -Author URI: https://wingify.com | |
| 2 | +/** | |
| 3 | + * | |
| 4 | + * Plugin Name: VWO | |
| 5 | + * Plugin URI: https://vwo.com/ | |
| 6 | + * 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. | |
| 7 | + * Author: VWO | |
| 8 | + * Version: 4.3 | |
| 9 | + * visual-website-optimizer.php | |
| 10 | + * Author URI: https://vwo.com/ | |
| 11 | + * | |
| 12 | + * @package VWO | |
| 13 | + * @author VWO | |
| 14 | + * @version 4.3 | |
| 15 | + **/ | |
| 10 | 16 | |
| 11 | -This relies on the actions being present in the themes header.php and footer.php | |
| 12 | -* header.php code before the closing </head> tag | |
| 13 | -* wp_head(); | |
| 14 | -* | |
| 15 | -*/ | |
| 17 | +/** | |
| 18 | + * Generate Common Code | |
| 19 | + * | |
| 20 | + * @param integer $vwo_clicks integer. Defaults to 10. | |
| 21 | + */ | |
| 22 | +function get_vwo_clhf_script_common_code( $vwo_clicks = 10 ) { | |
| 23 | + ob_start(); | |
| 24 | + // @codingStandardsIgnoreStart | |
| 25 | + ?> | |
| 26 | + <!-- Start VWO Common Smartcode --> | |
| 27 | + <script <?php echo vwo_clhf_ignore_js_attr(); ?> type='text/javascript'> | |
| 28 | + var _vwo_clicks = <?php echo esc_html( $vwo_clicks ); ?>; | |
| 29 | + </script> | |
| 30 | + <!-- End VWO Common Smartcode --> | |
| 31 | + <?php | |
| 32 | + // @codingStandardsIgnoreEnd | |
| 33 | + $script_code = ob_get_clean(); | |
| 34 | + return $script_code; | |
| 35 | +} | |
| 16 | 36 | |
| 17 | -//------------------------------------------------------------------------// | |
| 18 | -//---Config---------------------------------------------------------------// | |
| 19 | -//------------------------------------------------------------------------// | |
| 37 | +/** | |
| 38 | + * Get ignore js field setting | |
| 39 | + * | |
| 40 | + * @return bool boolean | |
| 41 | + */ | |
| 42 | +function get_vwo_clhf_ignore_js() { | |
| 43 | + $ignore_js = get_option( 'ignore_js' ); | |
| 44 | + $ignore_js = ( '1' === $ignore_js ) ? true : false; | |
| 45 | + return $ignore_js; | |
| 46 | +} | |
| 20 | 47 | |
| 21 | -$clhf_header_script_sync = ' | |
| 22 | -<!-- Start Visual Website Optimizer 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 Visual Website Optimizer Code --> | |
| 36 | -'; | |
| 48 | +/** | |
| 49 | + * Get ignore js script attribute value | |
| 50 | + * | |
| 51 | + * @return string Returns script attribute value | |
| 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" nowprocket'; | |
| 58 | + } | |
| 59 | + return $js_attr; | |
| 60 | +} | |
| 37 | 61 | |
| 38 | -$clhf_header_script_async = ' | |
| 39 | -<!-- Start Visual Website Optimizer 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 Visual Website Optimizer Asynchronous Code --> | |
| 49 | -'; | |
| 62 | +/** | |
| 63 | + * Generate Synchronous Code | |
| 64 | + * | |
| 65 | + * @param int $vwo_id integer. Defaults to 0. | |
| 66 | + * @return string string for sync script. | |
| 67 | + */ | |
| 68 | +function get_vwo_clhf_script_sync_code( $vwo_id = 0 ) { | |
| 69 | + ob_start(); | |
| 70 | + // @codingStandardsIgnoreStart | |
| 71 | + ?> | |
| 72 | + <!-- Start VWO Smartcode --> | |
| 73 | + <script <?php echo vwo_clhf_ignore_js_attr(); ?> src="https://dev.visualwebsiteoptimizer.com/lib/<?php echo esc_html( $vwo_id ); ?>.js"></script> | |
| 74 | + <!-- End VWO Smartcode --> | |
| 75 | + <?php | |
| 76 | + // @codingStandardsIgnoreEnd | |
| 77 | + $sync_script = ob_get_clean(); | |
| 78 | + return $sync_script; | |
| 79 | +} | |
| 50 | 80 | |
| 81 | +/** | |
| 82 | + * Generate Asynchronous Code | |
| 83 | + * | |
| 84 | + * @param int $vwo_id integer. | |
| 85 | + * @param int $settings_tolerance integer. | |
| 86 | + * @param int $library_tolerance integer. | |
| 87 | + * @param bool $use_existing_jquery boolean. | |
| 88 | + * @return string String for async script. | |
| 89 | + */ | |
| 90 | +function get_vwo_clhf_script_async_code( $vwo_id, $settings_tolerance, $library_tolerance, $use_existing_jquery ) { | |
| 91 | + ob_start(); | |
| 92 | + // @codingStandardsIgnoreStart | |
| 93 | + ?> | |
| 94 | + <!-- Start VWO Async SmartCode --> | |
| 95 | + <link rel="preconnect" href="https://dev.visualwebsiteoptimizer.com" /> | |
| 96 | + <script <?php echo vwo_clhf_ignore_js_attr(); ?> type='text/javascript' id='vwoCode'> | |
| 97 | + /* Fix: wp-rocket (application/ld+json) */ | |
| 98 | + window._vwo_code || (function () { | |
| 99 | + var account_id=<?php echo esc_html( $vwo_id ); ?>, // replace 1 with ${accountId} in release string | |
| 100 | + version=2.1, | |
| 101 | + settings_tolerance=<?php echo esc_html( $settings_tolerance ); ?>, | |
| 102 | + library_tolerance=<?php echo esc_html( $library_tolerance ); ?>, | |
| 103 | + use_existing_jquery=<?php echo ( $use_existing_jquery ) ? 'true' : 'false'; ?>, | |
| 104 | + hide_element='body', | |
| 105 | + hide_element_style='opacity:0 !important;filter:alpha(opacity=0) !important;background:none !important', | |
| 106 | + /* DO NOT EDIT BELOW THIS LINE */ | |
| 107 | + 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(){if(performance.getEntriesByName('first-contentful-paint')[0]){return''}return typeof cc.hE==='string'?cc.hE:hide_element},getVersion:function(){return version},finish:function(e){if(!f){f=true;var t=d.getElementById('_vis_opt_path_hides');if(t)t.parentNode.removeChild(t);if(e)(new Image).src='https://dev.visualwebsiteoptimizer.com/ee.gif?a='+account_id+e}},finished:function(){return f},addScript:function(e){var t=d.createElement('script');t.type='text/javascript';if(e.src){t.src=e.src}else{t.text=e.text}d.getElementsByTagName('head')[0].appendChild(t)},load:function(e,t){var i=this.getSettings(),n=d.createElement('script'),r=this;t=t||{};if(i){n.textContent=i;d.getElementsByTagName('head')[0].appendChild(n);if(!w.VWO||VWO.caE){stT.removeItem(cK);r.load(e)}}else{var o=new XMLHttpRequest;o.open('GET',e,true);o.withCredentials=!t.dSC;o.responseType=t.responseType||'text';o.onload=function(){if(t.onloadCb){return t.onloadCb(o,e)}if(o.status===200){_vwo_code.addScript({text:o.responseText})}else{_vwo_code.finish('&e=loading_failure:'+e)}};o.onerror=function(){if(t.onerrorCb){return t.onerrorCb(e)}_vwo_code.finish('&e=loading_failure:'+e)};o.send()}},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;if(this.hide_element()!=='body'){t=d.createElement('style');var i=this.hide_element(),n=i?i+this.hide_element_style():'',r=d.getElementsByTagName('head')[0];t.setAttribute('id','_vis_opt_path_hides');v&&t.setAttribute('nonce',v.nonce);t.setAttribute('type','text/css');if(t.styleSheet)t.styleSheet.cssText=n;else t.appendChild(d.createTextNode(n));r.appendChild(t)}else{t=d.getElementsByTagName('head')[0];var n=d.createElement('div');n.style.cssText='z-index: 2147483647 !important;position: fixed !important;left: 0 !important;top: 0 !important;width: 100% !important;height: 100% !important;background: white !important;';n.setAttribute('id','_vis_opt_path_hides');n.classList.add('_vis_hide_layer');t.parentNode.insertBefore(n,t.nextSibling)}var o='https://dev.visualwebsiteoptimizer.com/j.php?a='+account_id+'&u='+encodeURIComponent(d.URL)+'&vn='+version;if(w.location.search.indexOf('_vwo_xhr')!==-1){this.addScript({src:o})}else{this.load(o+'&x=true')}}};w._vwo_code=code;code.init();})(); | |
| 108 | + </script> | |
| 109 | + <!-- End VWO Async SmartCode --> | |
| 110 | + <?php | |
| 111 | + // @codingStandardsIgnoreEnd | |
| 112 | + $async_script = ob_get_clean(); | |
| 113 | + return $async_script; | |
| 114 | +} | |
| 51 | 115 | |
| 52 | -//------------------------------------------------------------------------// | |
| 53 | -//---Hook-----------------------------------------------------------------// | |
| 54 | -//------------------------------------------------------------------------// | |
| 55 | -add_action( 'wp_head', 'vwo_clhf_headercode',1 ); | |
| 116 | +// ------------------------------------------------------------------------// | |
| 117 | +// ---Hook-----------------------------------------------------------------// | |
| 118 | +// ------------------------------------------------------------------------// | |
| 119 | +add_action( 'wp_head', 'vwo_clhf_headercode', 1 ); | |
| 56 | 120 | add_action( 'admin_menu', 'vwo_clhf_plugin_menu' ); |
| 57 | 121 | add_action( 'admin_init', 'vwo_clhf_register_mysettings' ); |
| 58 | -add_action( 'admin_notices','vwo_clhf_warn_nosettings'); | |
| 122 | +add_action( 'admin_notices', 'vwo_clhf_warn_nosettings' ); | |
| 59 | 123 | |
| 60 | 124 | |
| 61 | -//------------------------------------------------------------------------// | |
| 62 | -//---Functions------------------------------------------------------------// | |
| 63 | -//------------------------------------------------------------------------// | |
| 125 | +// ------------------------------------------------------------------------// | |
| 126 | +// ---Functions------------------------------------------------------------// | |
| 127 | +// ------------------------------------------------------------------------// | |
| 64 | 128 | // options page link |
| 129 | + | |
| 130 | +/** | |
| 131 | + * Generate a function comment for the given function body. | |
| 132 | + * | |
| 133 | + * @throws Exception Description of exception. | |
| 134 | + * @return void | |
| 135 | + */ | |
| 65 | 136 | function vwo_clhf_plugin_menu() { |
| 66 | - add_options_page('Visual Website Optimizer', 'VWO', 'create_users', 'clhf_vwo_options', 'vwo_clhf_plugin_options'); | |
| 137 | + add_options_page( 'Visual Website Optimizer', 'VWO', 'create_users', 'clhf_vwo_options', 'vwo_clhf_plugin_options' ); | |
| 67 | 138 | } |
| 68 | 139 | |
| 69 | -// whitelist settings | |
| 70 | -function vwo_clhf_register_mysettings(){ | |
| 71 | - register_setting('clhf_vwo_options','vwo_id','intval'); | |
| 72 | - register_setting('clhf_vwo_options','code_type'); | |
| 73 | - register_setting('clhf_vwo_options','settings_tolerance','intval'); | |
| 74 | - register_setting('clhf_vwo_options','library_tolerance','intval'); | |
| 140 | +/** | |
| 141 | + * Register the settings for the VWO options. | |
| 142 | + * | |
| 143 | + * @return void | |
| 144 | + */ | |
| 145 | +function vwo_clhf_register_mysettings() { | |
| 146 | + register_setting( 'clhf_vwo_options', 'vwo_id', 'intval' ); | |
| 147 | + register_setting( 'clhf_vwo_options', 'code_type' ); | |
| 148 | + register_setting( 'clhf_vwo_options', 'vwo_clicks' ); | |
| 149 | + register_setting( 'clhf_vwo_options', 'ignore_js', 'boolval' ); | |
| 150 | + register_setting( 'clhf_vwo_options', 'settings_tolerance', 'intval' ); | |
| 151 | + register_setting( 'clhf_vwo_options', 'library_tolerance', 'intval' ); | |
| 152 | + register_setting( 'clhf_vwo_options', 'use_existing_jquery', 'boolval' ); | |
| 75 | 153 | } |
| 76 | 154 | |
| 77 | -//------------------------------------------------------------------------// | |
| 78 | -//---Output Functions-----------------------------------------------------// | |
| 79 | -//------------------------------------------------------------------------// | |
| 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; | |
| 155 | +// ------------------------------------------------------------------------// | |
| 156 | +// ---Output Functions-----------------------------------------------------// | |
| 157 | +// ------------------------------------------------------------------------// | |
| 91 | 158 | |
| 92 | - $library_tolerance = get_option('library_tolerance'); | |
| 93 | - if(!is_numeric($library_tolerance)) $library_tolerance = 2500; | |
| 94 | 159 | |
| 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); | |
| 160 | +/** | |
| 161 | + * Generates the action vwo_clhf_headercode function. | |
| 162 | + * | |
| 163 | + * @throws Exception Description of exception. | |
| 164 | + * @return void | |
| 165 | + */ | |
| 166 | +function vwo_clhf_headercode() { | |
| 167 | + // Runs in the header. | |
| 168 | + $vwo_id = get_option( 'vwo_id' ); | |
| 169 | + $code_type = get_option( 'code_type' ); | |
| 170 | + | |
| 171 | + if ( $vwo_id ) { | |
| 172 | + if ( empty( get_option( 'vwo_clicks' ) ) ) { | |
| 173 | + update_option( 'vwo_clicks', '10' ); | |
| 98 | 174 | } |
| 175 | + $vwo_clicks = get_option( 'vwo_clicks' ); | |
| 176 | + | |
| 177 | + // Common script code. | |
| 178 | + // @codingStandardsIgnoreLine | |
| 179 | + echo get_vwo_clhf_script_common_code( $vwo_clicks ); | |
| 180 | + | |
| 181 | + if ( 'SYNC' === $code_type ) { | |
| 182 | + // Sync script code. | |
| 183 | + // @codingStandardsIgnoreLine | |
| 184 | + echo get_vwo_clhf_script_sync_code( $vwo_id ); | |
| 185 | + } else { | |
| 186 | + | |
| 187 | + $settings_tolerance = get_option( 'settings_tolerance' ); | |
| 188 | + if ( ! is_numeric( $settings_tolerance ) ) { | |
| 189 | + $settings_tolerance = 2000; | |
| 190 | + } | |
| 191 | + | |
| 192 | + $library_tolerance = get_option( 'library_tolerance' ); | |
| 193 | + if ( ! is_numeric( $library_tolerance ) ) { | |
| 194 | + $library_tolerance = 2500; | |
| 195 | + } | |
| 196 | + | |
| 197 | + $use_existing_jquery = get_option( 'use_existing_jquery' ); | |
| 198 | + $use_existing_jquery = ( '1' === $use_existing_jquery ) ? true : false; | |
| 199 | + | |
| 200 | + // Async script code. | |
| 201 | + // @codingStandardsIgnoreLine | |
| 202 | + echo get_vwo_clhf_script_async_code( $vwo_id, $settings_tolerance, $library_tolerance, $use_existing_jquery ); | |
| 203 | + } | |
| 99 | 204 | } |
| 100 | 205 | } |
| 101 | -//------------------------------------------------------------------------// | |
| 102 | -//---Page Output Functions------------------------------------------------// | |
| 103 | -//------------------------------------------------------------------------// | |
| 206 | + | |
| 207 | +// ------------------------------------------------------------------------// | |
| 208 | +// ---Page Output Functions------------------------------------------------// | |
| 209 | +// ------------------------------------------------------------------------// | |
| 104 | 210 | // options page |
| 211 | + | |
| 212 | + | |
| 213 | +/** | |
| 214 | + * Generates the options page for the VWO plugin. | |
| 215 | + * | |
| 216 | + * @throws Exception Description of exception. | |
| 217 | + * @return void | |
| 218 | + */ | |
| 105 | 219 | function vwo_clhf_plugin_options() { |
| 106 | - echo '<div class="wrap">';?> | |
| 107 | - <h2>Visual Website Optimizer</h2> | |
| 108 | - <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> | |
| 220 | + // Set value for checkbox by default. | |
| 221 | + $ignore_js_options = get_option( 'ignore_js' ); | |
| 222 | + $show_ignore_js = $ignore_js_options; | |
| 223 | + if ( false === $ignore_js_options ) { | |
| 224 | + // Nothing is set, so apply the default here. | |
| 225 | + $show_ignore_js = 1; | |
| 226 | + update_option( 'ignore_js', '1' ); | |
| 227 | + } | |
| 228 | + | |
| 229 | + echo '<div class="wrap">'; | |
| 230 | + ?> | |
| 231 | + <h2>VWO</h2> | |
| 232 | + <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> | |
| 109 | 233 | <form method="post" action="options.php"> |
| 110 | 234 | <?php settings_fields( 'clhf_vwo_options' ); ?> |
| 111 | 235 | <table class="form-table"> |
| 112 | - <tr valign="top"> | |
| 113 | - <th scope="row">Your VWO Account ID</th> | |
| 114 | - <td><input type="text" name="vwo_id" value="<?php echo get_option('vwo_id'); ?>" /></td> | |
| 115 | - </tr> | |
| 116 | 236 | <tr valign="top"> |
| 117 | - <th scope="row">Code (default: Asynchronous)</th> | |
| 118 | - <td> | |
| 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 | |
| 120 | - <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 | |
| 121 | - <a href="https://vwo.com/blog/asynchronous-code" target="_blank">[Help]</a> | |
| 122 | - </td> | |
| 123 | - </tr> | |
| 124 | - <tr valign="top" id='asyncOnly1' <?php if(get_option('code_type')=='SYNC') echo "style='display:none;'" ?>> | |
| 125 | - <th scope="row">Settings Timeout</th> | |
| 126 | - <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> | |
| 127 | - </tr> | |
| 128 | - <tr valign="top" id='asyncOnly2' <?php if(get_option('code_type')=='SYNC') echo "style='display:none;'" ?>> | |
| 129 | - <th scope="row">Library Timeout</th> | |
| 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> | |
| 131 | - </tr> | |
| 237 | + <th scope="row">Your VWO Account ID</th> | |
| 238 | + <td><input type="text" name="vwo_id" value="<?php echo esc_html( get_option( 'vwo_id' ) ); ?>" /></td> | |
| 239 | + </tr> | |
| 240 | + <tr valign="top"> | |
| 241 | + <th scope="row">No. of Heatmap Clicks</th> | |
| 242 | + <td><input type="number" name="vwo_clicks" value="<?php echo get_option( 'vwo_clicks' ) ? esc_html( get_option( 'vwo_clicks' ) ) : 10; ?>" min="3"/></td> | |
| 243 | + </tr> | |
| 244 | + <tr valign="top"> | |
| 245 | + <th scope="row">Code (default: Asynchronous)</th> | |
| 246 | + <td> | |
| 247 | + <input style="vertical-align: text-top;" type="radio" onclick="selectCodeType();" name="code_type" id="code_type_async" value="ASYNC" | |
| 248 | + <?php | |
| 249 | + if ( get_option( 'code_type' ) !== 'SYNC' ) { | |
| 250 | + echo 'checked';} | |
| 251 | + ?> | |
| 252 | + /> Asynchronous | |
| 253 | + <input style="vertical-align: text-top;" type="radio" onclick="selectCodeType();" name="code_type" id="code_type_sync" value="SYNC" | |
| 254 | + <?php | |
| 255 | + if ( get_option( 'code_type' ) === 'SYNC' ) { | |
| 256 | + echo 'checked';} | |
| 257 | + ?> | |
| 258 | + /> Synchronous | |
| 259 | + <a href="https://vwo.com/blog/asynchronous-code" target="_blank">[Help]</a> | |
| 260 | + </td> | |
| 261 | + </tr> | |
| 262 | + <tr valign="top" id='asyncOnly1' | |
| 263 | + <?php | |
| 264 | + if ( get_option( 'code_type' ) === 'SYNC' ) { | |
| 265 | + echo "style='display:none;'";} | |
| 266 | + ?> | |
| 267 | + > | |
| 268 | + <th scope="row">Settings Timeout</th> | |
| 269 | + <td style="vertical-align: middle;"><input type="text" name="settings_tolerance" value="<?php echo get_option( 'settings_tolerance' ) ? esc_html( get_option( 'settings_tolerance' ) ) : 2000; ?>" />ms (default: 2000)</td> | |
| 270 | + </tr> | |
| 271 | + <tr valign="top" id='asyncOnly2' | |
| 272 | + <?php | |
| 273 | + if ( get_option( 'code_type' ) === 'SYNC' ) { | |
| 274 | + echo "style='display:none;'";} | |
| 275 | + ?> | |
| 276 | + > | |
| 277 | + <th scope="row">Library Timeout</th> | |
| 278 | + <td style="vertical-align: middle;"><input type="text" name="library_tolerance" value="<?php echo get_option( 'library_tolerance' ) ? esc_html( get_option( 'library_tolerance' ) ) : 2500; ?>" />ms (default: 2500)</td> | |
| 279 | + </tr> | |
| 280 | + <tr valign="top" id='asyncOnly3' | |
| 281 | + <?php | |
| 282 | + if ( get_option( 'code_type' ) === 'SYNC' ) { | |
| 283 | + echo "style='display:none;'";} | |
| 284 | + ?> | |
| 285 | + > | |
| 286 | + <th scope="row">Use Existing jQuery</th> | |
| 287 | + <td style="vertical-align: middle;"><input type="checkbox" name="use_existing_jquery" value="1" | |
| 288 | + <?php | |
| 289 | + if ( get_option( 'use_existing_jquery' ) === '1' ) { | |
| 290 | + echo 'checked';} | |
| 291 | + ?> | |
| 292 | + />Yes</td> | |
| 293 | + </tr> | |
| 294 | + <tr valign="top"> | |
| 295 | + <th scope="row">Skip Deferred Execution</th> | |
| 296 | + <td style="vertical-align: middle;"><input type="checkbox" name="ignore_js" value="1" | |
| 297 | + <?php | |
| 298 | + if ( '1' === $show_ignore_js ) { | |
| 299 | + echo 'checked';} | |
| 300 | + ?> | |
| 301 | + />Yes</td> | |
| 302 | + </tr> | |
| 132 | 303 | </table> |
| 133 | 304 | |
| 134 | 305 | <script type="text/javascript"> |
| 135 | 306 | function selectCodeType() { |
| @@ -139,27 +310,69 @@ | ||
| 139 | 310 | |
| 140 | 311 | if(code_type == 'ASYNC') { |
| 141 | 312 | document.getElementById('asyncOnly1').style.display = 'table-row'; |
| 142 | 313 | document.getElementById('asyncOnly2').style.display = 'table-row'; |
| 314 | + document.getElementById('asyncOnly3').style.display = 'table-row'; | |
| 143 | 315 | } |
| 144 | 316 | else { |
| 145 | 317 | document.getElementById('asyncOnly1').style.display = 'none'; |
| 146 | 318 | document.getElementById('asyncOnly2').style.display = 'none'; |
| 319 | + document.getElementById('asyncOnly3').style.display = 'none'; | |
| 147 | 320 | } |
| 148 | 321 | } |
| 149 | 322 | </script> |
| 150 | - <p class="submit"><input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /></p> | |
| 151 | - <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> | |
| 152 | -<?php | |
| 153 | - echo '</div>'; | |
| 323 | + <p class="submit"><input type="submit" class="button-primary" value="<?php echo esc_html( 'Save Changes' ); ?>" /></p> | |
| 324 | + <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> | |
| 325 | + <?php | |
| 326 | + echo '</div>'; | |
| 154 | 327 | } |
| 155 | 328 | |
| 156 | -function vwo_clhf_warn_nosettings(){ | |
| 157 | - if (!is_admin()) | |
| 158 | - return; | |
| 329 | +/** | |
| 330 | + * Displays a warning message if VWO settings are not configured. | |
| 331 | + * This function checks if the user is an admin and if the VWO ID option is set. If the user is not an admin or | |
| 332 | + * the VWO ID option is not set, it displays a warning message. | |
| 333 | + * | |
| 334 | + * @throws Exception Description of exception. | |
| 335 | + * @return void | |
| 336 | + */ | |
| 337 | +function vwo_clhf_warn_nosettings() { | |
| 338 | + if ( ! is_admin() ) { | |
| 339 | + return; | |
| 340 | + } | |
| 159 | 341 | |
| 160 | - $clhf_option = get_option("vwo_id"); | |
| 161 | - if (!$clhf_option || $clhf_option < 1){ | |
| 162 | - 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>"; | |
| 163 | - } | |
| 342 | + $clhf_option = get_option( 'vwo_id' ); | |
| 343 | + if ( ! $clhf_option || $clhf_option < 1 ) { | |
| 344 | + 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>"; | |
| 345 | + } | |
| 164 | 346 | } |
| 165 | -?> | |
| 347 | + | |
| 348 | + | |
| 349 | +add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'vwo_clhf_add_plugin_page_settings_link' ); | |
| 350 | + | |
| 351 | +/** | |
| 352 | + * Function to add Settings Links on Plugin page | |
| 353 | + * | |
| 354 | + * @param array $links Array of links. | |
| 355 | + * @return array | |
| 356 | + */ | |
| 357 | +function vwo_clhf_add_plugin_page_settings_link( $links ) { | |
| 358 | + $links[] = '<a href="' . | |
| 359 | + admin_url( 'options-general.php?page=clhf_vwo_options' ) . | |
| 360 | + '">' . __( 'Settings' ) . '</a>'; | |
| 361 | + return $links; | |
| 362 | +} | |
| 363 | + | |
| 364 | +/** | |
| 365 | + * Disables VWO in Divi Builder. | |
| 366 | + * | |
| 367 | + * @throws Exception Description of exception. | |
| 368 | + * @return void | |
| 369 | + */ | |
| 370 | +function disable_vwo_in_divi_builder() { | |
| 371 | + if ( has_action( 'wp_head', 'vwo_clhf_headercode' ) && function_exists( 'et_core_is_fb_enabled' ) && et_core_is_fb_enabled() ) { | |
| 372 | + remove_action( 'wp_head', 'vwo_clhf_headercode', 1 ); | |
| 373 | + } | |
| 374 | +} | |
| 375 | + | |
| 376 | +add_action( 'wp_head', 'disable_vwo_in_divi_builder', 0 ); | |
| 377 | + | |
| 378 | +?> | |