init(); $this->init_vars(); } /** * Initiate plugin. * * @return void */ function init() { add_action( 'init', array( &$this, 'load_plugin_textdomain' ), 0 ); add_action( 'init', array( &$this, 'enable_admin_tracking' ) ); add_action( 'init', array( &$this, 'handle_page_requests' ) ); add_action( 'admin_menu', array( &$this, 'admin_menu' ) ); add_action( 'network_admin_menu', array( &$this, 'network_admin_menu' ) ); add_action( 'wp_head', array( &$this, 'tracking_code_output' ) ); } /** * Initiate variables. * * @return void */ function init_vars() { global $wpdb; $this->domain = $wpdb->get_var( "SELECT domain FROM {$wpdb->site}" ); /* Set plugin directory path */ $this->plugin_dir = WP_PLUGIN_DIR . '/' . str_replace( basename(__FILE__), '', plugin_basename(__FILE__) ); /* Set plugin directory URL */ $this->plugin_url = WP_PLUGIN_URL . '/' . str_replace( basename(__FILE__), '', plugin_basename(__FILE__) ); } /** * Loads the language file from the "languages" directory. * * @return void */ function load_plugin_textdomain() { load_plugin_textdomain( $this->text_domain, null, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } /** * Add Google Analytics options page. * * @return void */ function admin_menu() { $network_settings = get_site_option( $this->options_name ); /* If Supporter enabled but specific option disabled, disable menu */ if ( !is_super_admin() && function_exists('is_supporter') && !empty( $network_settings['supporter_only'] ) && !is_supporter() ) { return; } else { add_submenu_page( 'options-general.php', 'Google Analytics', 'Google Analytics', 'manage_options', 'google-analytics', array( &$this, 'output_site_settings_page' ) ); } } /** * Add network admin menu * * @access public * @return void */ function network_admin_menu() { add_submenu_page( 'settings.php', 'Google Analytics', 'Google Analytics', 'manage_network', 'google-analytics', array( &$this, 'output_network_settings_page' ) ); } /** * Enable admin tracking. * * @return void */ function enable_admin_tracking() { $network_settings = get_site_option( $this->options_name ); if ( !empty( $network_settings['track_admin'] ) ) add_action( 'admin_head', array( &$this, 'tracking_code_output' ) ); } /** * Google Analytics code output. * * @return void */ function tracking_code_output() { $network_settings = get_site_option( $this->options_name ); $site_settings = get_option( $this->options_name ); /* Unset tracking code if it matches the root site one */ if ( isset( $network_settings['tracking_code'] ) && isset( $site_settings['tracking_code'] ) && $network_settings['tracking_code'] == $site_settings['tracking_code'] ) { unset( $site_settings['tracking_code'] ); } ?> options_name, $network_settings ); wp_redirect( add_query_arg( array( 'page' => 'google-analytics', 'dmsg' => urlencode( __( 'Changes were saved!', $this->text_domain ) ) ), 'settings.php' ) ); exit; } elseif ( wp_verify_nonce( $_POST['_wpnonce'], 'submit_settings' ) ) { $settings['tracking_code'] = trim( $_POST['site_tracking_code'] ); $settings['track_pageload'] = $_POST['track_pageload']; update_option( $this->options_name, $settings ); wp_redirect( add_query_arg( array( 'page' => 'google-analytics', 'dmsg' => urlencode( __( 'Changes were saved!', $this->text_domain ) ) ), 'options-general.php' ) ); exit; } } } /** * Network settings page * * @access public * @return void */ function output_network_settings_page() { /* Get settings */ $network_settings = get_site_option( $this->options_name ); ?>
text_domain ); ?>
sign up for Analytics, set up a new account and copy the tracking code you receive (it\'ll start with "UA-") into the box above and press "Save" - it can take several hours before you see any stats, but once it is you\'ve got access to one heck of a lot of data!', $this->text_domain ); ?>
this Google help site.', $this->text_domain ); ?>