Advertisement
amereservant

WordPress Browser Detection Plugin suggestion

Aug 30th, 2011
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Activate Scheduled Events
  4.  *
  5.  * This adds all scheduled events for the theme to run via WP Cron.
  6.  *
  7.  * @param   void
  8.  * @return  void
  9.  * @access  private
  10.  */
  11. function _browscap_activate_schedules()
  12. {
  13.     if( !wp_next_scheduled('_browscap_check_browscap') )
  14.     {
  15.         wp_schedule_event(time(), 'daily', '_browscap_check_browscap');
  16.     }
  17. }
  18. add_action('wp', '_browscap_activate_schedules');
  19.  
  20. /**
  21.  * Check for new Browscap version
  22.  *
  23.  * This theme uses {@link http://browsers.garykeith.com/ Browscap} to check for browser <br>
  24.  * support and browser details.  By having the latest version of Browscap, we can be <br>
  25.  * sure we can detect the latest versions of browsers with up-to-date information.
  26.  *
  27.  * This function is added as a scheduled event to run every day and check for a new version.
  28.  *
  29.  * @param   void
  30.  * @return  void
  31.  * @access  private
  32.  */
  33. function _browscap_check_for_new_browscap()
  34. {
  35.     // Only check remote version number if the browscap version is current
  36.     if( get_option('_browscap_ver_is_current') )
  37.     {
  38.         // Retrieve the current version number from the browscap website
  39.         $version = wp_remote_fopen('http://browsers.garykeith.com/versions/version-number.asp');
  40.        
  41.         // Get local browscap version
  42.         if( version_compare(PHP_VERSION, '5.3.0') >= 0 )
  43.             $brows = parse_ini_file(BROWSECAP_FILE, true, INI_SCANNER_RAW);
  44.         else
  45.             $brows = parse_ini_file(BROWSECAP_FILE, true);
  46.        
  47.         $local_version = $brows['GJK_Browscap_Version']['Version'];
  48.         $rversion      = get_option('browscap_remote_version');
  49.         if($version != $local_version)
  50.         {
  51.             update_option('_browscap_ver_is_current', 0);
  52.             update_option('browscap_remote_version', $version);
  53.         }
  54.         elseif( $rversion )
  55.             update_option('browscap_remote_version', $version);
  56.     }
  57. }
  58. add_action('_browscap_check_browscap', '_browscap_check_for_new_browscap');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement