/**
  * Initialize variables and actions
  */
 public static function init()
 {
     // Load all the settings
     self::$options = get_option('power_stats_options', array());
     if (empty(self::$options)) {
         self::$options = self::init_options();
         // Save WP Power Stats options in the database
         add_option('power_stats_options', self::$options, '', 'no');
     } else {
         self::$options = array_merge(self::init_options(), self::$options);
     }
     // Allow other plugins to edit the options
     self::$options = apply_filters('power_stats_options', self::$options);
     // Set DB connection
     self::$wpdb = $GLOBALS['wpdb'];
     // Hook a DB clean-up routine to the daily cron job
     add_action('power_stats_purge', array(__CLASS__, 'power_stats_purge'));
     // Set the options' hash for tracking changes in the options
     self::$options_hash = md5(serialize(self::$options));
     // Include and initialize vendor libraries
     if (!class_exists('Browser') && !class_exists('UserAgent') && !class_exists('BrowserDetection')) {
         require_once POWER_STATS_DIR . '/admin/vendor/browser-os/Browser.php';
     }
     if (!class_exists('Mobile_Detect')) {
         require_once POWER_STATS_DIR . '/admin/vendor/mobile-detect/Mobile_Detect.php';
     }
     require_once POWER_STATS_DIR . '/admin/vendor/search-terms/SearchEngines.php';
     require_once POWER_STATS_DIR . '/admin/vendor/search-terms/Countries.php';
     require_once POWER_STATS_DIR . '/admin/vendor/tabgeo_country_v4/tabgeo_country_v4.php';
     self::$vendors['browser'] = new Browser($_SERVER['HTTP_USER_AGENT']);
     self::$vendors['device'] = new Mobile_Detect();
     // Add the server and client-side tracker
     if (self::$options['tracker_active'] == 'yes' && (!is_admin() || is_admin() && self::$options['ignore_admin_pages'] == 'no')) {
         // Add additional custom exclusion filters
         $track_filter = apply_filters('power_stats_filter_pre_tracking', true);
         $action_to_hook = is_admin() ? 'admin_init' : 'wp';
         // Hook the tracker script
         if ($track_filter) {
             add_action($action_to_hook, array(__CLASS__, 'power_stats_enqueue_tracking_script'), 15);
             if (self::$options['track_users'] == 'yes') {
                 add_action('login_enqueue_scripts', array(__CLASS__, 'power_stats_enqueue_tracking_script'), 10);
             }
         }
     }
     // Update the options before shutting down
     add_action('shutdown', array(__CLASS__, 'power_stats_save_options'));
 }
 /**
  * Support for WP MU network activations
  */
 public static function new_blog($blog_id)
 {
     switch_to_blog($blog_id);
     self::init_environment();
     restore_current_blog();
     PowerStats::$options = get_option('power_stats_options', array());
 }