/** * 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()); }
$obj_role->add_cap('wp_power_stats_view'); } } else { PowerStatsAdmin::$faulty_fields[] = __('some roles in "Statistics View Roles" were not found', 'wp-power-stats'); } } else { // Remove the capability from all roles foreach ($wp_roles->roles as $role) { $role = get_role(strtolower($role['name'])); $role->remove_cap('wp_power_stats_view'); } PowerStats::$options['view_roles'] = ''; } if (!empty($_POST['options']['admin_roles'])) { // Make sure all the entered roles exist $role_array = PowerStats::string_to_array(strtolower($_POST['options']['admin_roles'])); $role_not_found = false; foreach ($role_array as $index => $role) { // get the role object $obj_role = get_role($role); if ($obj_role === null) { $role_not_found = true; } } // All entered roles are valid if (!$role_not_found) { // Remove the capability from all roles foreach ($wp_roles->roles as $role) { $role = get_role(strtolower($role['name'])); $role->remove_cap('wp_power_stats_admin'); }