Last active
December 14, 2015 12:09
-
-
Save nerrad/5084101 to your computer and use it in GitHub Desktop.
#Detect browser message (WP based sites)
This is a function I created for Event Espresso to detect older versions of browsers being used to view the site and displaying a message when out of date (according to our requirements). It uses the `wp_check_browser_version()` function WordPress makes available. I've also added some things to not includ…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This function just checks the incoming browser and will display a message if it's out of date. We save transients for the user-agents so we don't need to ping the WordPress api on every request. | |
* | |
* @return string html formatted message for user | |
*/ | |
function show_browser_message() { | |
//let's include the file that will has the wp function we need. | |
require_once( ABSPATH . 'wp-admin/includes/dashboard.php' ); | |
$browser_info = wp_check_browser_version(); | |
$ie_required = '9.0'; | |
$msg = ''; | |
$search_engines_bots = 'Google|Yahoo|msnbot|bingbot'; | |
if ( preg_match("/$search_engines_bots/", $_SERVER['HTTP_USER_AGENT']) > 0 ) | |
return; //get out this is most likely a search engine so we don't need to show browser message. | |
if ( isset($_SERVER['HTTP_X_GOOG_SOURCE']) ) | |
return; //this is supposed to to work for google + (see http://code.google.com/p/google-plus-platform/issues/detail?id=178) | |
//first let's handle ie separately from all the others b/c it's the biggest pain | |
if ( $browser_info['name'] == 'Internet Explorer' && $browser_info['version'] < $ie_required ) { | |
$msg .= 'It appears that you are using Internet Explorer ' . $browser_info['version'] . ' which is <strong>NOT</strong> supported and you may experience difficulty viewing or interacting with our website. For best results, feel free to use the latest <a href="http://www.microsoft.com/windows/internet-explorer">Internet Explorer</a>, <a href="http://www.firefox.com/">Firefox</a>, or <a href="http://www.google.com/chrome">Google Chrome</a> browser.'; | |
} else if ( $browser_info['name'] == 'Internet Explorer' && ( $browser_info['version'] == $ie_required || ( $browser_info['version'] > $ie_required && $browser_info['version'] < '10.0' ) ) ) { | |
$msg .= 'It appears that you are using Internet Explorer ' . $browser_info['version'] . ' which is supported on our website. However, there have been reports of customers having problems making purchases with this version. For best results, feel free to use the latest <a href="http://www.microsoft.com/windows/internet-explorer">Internet Explorer</a>, <a href="http://www.firefox.com/">Firefox</a>, or <a href="http://www.google.com/chrome">Google Chrome</a> browser.'; | |
} else if ( $browser_info['upgrade'] && $browser_info['name'] !== 'Internet Explorer' ) { | |
$msg .= 'It appears you are using an older version of ' . $browser_info['name'] . '. More than likely there will be parts of our website that won\'t work as expected for you using this browser. We suggest upgrading to the latest version <a href="' . $browser_info['update_url'] . '">here</a>.'; | |
} | |
if ( !empty($msg) ) { | |
$msg .= ' See <a href="http://eventespresso.com/faqs/supported-web-browsers/">this page</a> regarding supported web browsers for all our products.'; | |
$msg = '<div id="pue_s2custom-renewal-msg-section" class="pue_s2custom-renewal-msg-section"><p>' . $msg . '</p></div>'; | |
} | |
echo $msg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment