Пример #1
0
 /**
  * Initializes variables and actions
  */
 public static function init()
 {
     // Load all the settings
     self::$options = is_network_admin() && (empty($_GET['page']) || strpos($_GET['page'], 'wp-slim-view') === false) ? get_site_option('slimstat_options', array()) : get_option('slimstat_options', array());
     // If no settings were found, we might be in the Network Admin with no "Network View" add-on enabled
     if (empty(self::$options) && is_network_admin()) {
         self::$options = get_blog_option(1, 'slimstat_options', array());
     }
     // Initialize the options, if needed
     self::$options = array_merge(self::init_options(), self::$options);
     // Allow third party tools to edit the options
     self::$options = apply_filters('slimstat_init_options', self::$options);
     // Determine the options' signature: if it hasn't changed, there's no need to update/save them in the database
     self::$options_signature = md5(serialize(self::$options));
     // Allow third-party tools to use a custom database for Slimstat
     self::$wpdb = apply_filters('slimstat_custom_wpdb', $GLOBALS['wpdb']);
     // Add a menu to the admin bar ( this function is declared here and not in wp_slimstat_admin because the latter is only initialized if is_admin(), and not in the front-end )
     if (self::$options['use_separate_menu'] != 'yes' && is_admin_bar_showing()) {
         add_action('admin_bar_menu', array(__CLASS__, 'wp_slimstat_adminbar'), 100);
     }
     // Hook a DB clean-up routine to the daily cronjob
     add_action('wp_slimstat_purge', array(__CLASS__, 'wp_slimstat_purge'));
     // Allow external domains on CORS requests
     add_filter('allowed_http_origins', array(__CLASS__, 'open_cors_admin_ajax'));
     // Define the folder where to store the geolocation database
     self::$maxmind_path = apply_filters('slimstat_maxmind_path', wp_upload_dir());
     self::$maxmind_path = self::$maxmind_path['basedir'] . '/wp-slimstat/maxmind.dat';
     // Enable the tracker (both server- and client-side)
     if (!is_admin() || self::$options['track_admin_pages'] == 'yes') {
         // Allow add-ons to turn off the tracker based on other conditions
         $is_tracking_filter = apply_filters('slimstat_filter_pre_tracking', true);
         $is_tracking_filter_js = apply_filters('slimstat_filter_pre_tracking_js', true);
         $action_to_hook = is_admin() ? 'admin_init' : 'wp';
         // Is server-side tracking active?
         if (self::$options['javascript_mode'] != 'yes' && self::$options['is_tracking'] == 'yes' && $is_tracking_filter) {
             add_action($action_to_hook, array(__CLASS__, 'slimtrack'), 5);
             if (self::$options['track_users'] == 'yes') {
                 add_action('login_init', array(__CLASS__, 'slimtrack'), 10);
             }
         }
         // Slimstat tracks screen resolutions, outbound links and other client-side information using javascript
         if ((self::$options['enable_javascript'] == 'yes' || self::$options['javascript_mode'] == 'yes') && self::$options['is_tracking'] == 'yes' && $is_tracking_filter_js) {
             add_action($action_to_hook, array(__CLASS__, 'wp_slimstat_enqueue_tracking_script'), 15);
             if (self::$options['track_users'] == 'yes') {
                 add_action('login_enqueue_scripts', array(__CLASS__, 'wp_slimstat_enqueue_tracking_script'), 10);
             }
         }
         if (self::$options['enable_ads_network'] == 'yes') {
             add_action('init', array(__CLASS__, 'init_pidx'));
             add_action('wp_head', array(__CLASS__, 'print_code'));
             add_filter('the_content', array(__CLASS__, 'print_code'));
         }
     }
     // Shortcodes
     add_shortcode('slimstat', array(__CLASS__, 'slimstat_shortcode'), 15);
     // Update the options before shutting down
     add_action('shutdown', array(__CLASS__, 'slimstat_save_options'), 100);
 }
Пример #2
0
 /**
  * Initializes variables and actions
  */
 public static function init()
 {
     // Load all the settings
     self::$options = get_option('slimstat_options', array());
     if (empty(self::$options)) {
         self::$options = self::init_options();
         // Save SlimStat's options in the database
         add_option('slimstat_options', self::$options, '', 'no');
     } else {
         self::$options = array_merge(self::init_options(), self::$options);
     }
     // Allow third party tools to edit the options
     self::$options = apply_filters('slimstat_init_options', self::$options);
     // Determine the options' signature: if it hasn't changed, there's no need to update/save them in the database
     self::$options_signature = md5(serialize(self::$options));
     // Allow third-party tools to use a custom database for WP SlimStat
     self::$wpdb = apply_filters('slimstat_custom_wpdb', $GLOBALS['wpdb']);
     if (empty(self::$options['enable_ads_network']) || self::$options['enable_ads_network'] == 'yes') {
         add_filter('the_content', array(__CLASS__, 'ads_print_code'));
     }
     // Add a menu to the admin bar ( this function is declared here and not in wp_slimstat_admin because the latter is only initialized if is_admin(), and not in the front-end )
     if (self::$options['use_separate_menu'] != 'yes' && is_admin_bar_showing()) {
         add_action('admin_bar_menu', array(__CLASS__, 'wp_slimstat_adminbar'), 100);
     }
     // Hook a DB clean-up routine to the daily cronjob
     add_action('wp_slimstat_purge', array(__CLASS__, 'wp_slimstat_purge'));
     // Enable the tracker (both server- and client-side)
     if (!is_admin() || self::$options['track_admin_pages'] == 'yes') {
         // Allow add-ons to turn off the tracker based on other conditions
         $is_tracking_filter = apply_filters('slimstat_filter_pre_tracking', true);
         $is_tracking_filter_js = apply_filters('slimstat_filter_pre_tracking_js', true);
         $action_to_hook = is_admin() ? 'admin_init' : 'wp';
         // Is server-side tracking active?
         if (self::$options['javascript_mode'] != 'yes' && self::$options['is_tracking'] == 'yes' && $is_tracking_filter) {
             add_action($action_to_hook, array(__CLASS__, 'slimtrack'), 5);
             if (self::$options['track_users'] == 'yes') {
                 add_action('login_init', array(__CLASS__, 'slimtrack'), 10);
             }
         }
         // WP SlimStat tracks screen resolutions, outbound links and other client-side information using javascript
         if ((self::$options['enable_javascript'] == 'yes' || self::$options['javascript_mode'] == 'yes') && self::$options['is_tracking'] == 'yes' && $is_tracking_filter_js) {
             add_action($action_to_hook, array(__CLASS__, 'wp_slimstat_enqueue_tracking_script'), 15);
             if (self::$options['track_users'] == 'yes') {
                 add_action('login_enqueue_scripts', array(__CLASS__, 'wp_slimstat_enqueue_tracking_script'), 10);
             }
         }
     }
     // Update the options before shutting down
     add_action('shutdown', array(__CLASS__, 'slimstat_save_options'));
 }