options = Config::get_options(); add_action( 'init', array( $this, 'init' ) ); if ( is_admin() ) { # add 'Settings' link to the plugin list (applicable only when in admin area) add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 ); # see, if user provided Google tracking code... add warning if applicable if ( !isset( $this->options['GoogleID'] ) || ( $this->options['GoogleID'] == '' ) ) { add_action( 'admin_notices', array( $this, 'admin_notices' ) ); } } # now serve the google code if user provided any if ( $this->options['GoogleID'] != '' ) { add_action( 'wp_loaded', array( $this, 'wp_loaded' ) ); } } public function init() { load_plugin_textdomain( Config::TEXT_DOMAIN, false, PLUGIN_BASE ); } public function wp_loaded() { global $current_user; # first of all, we may assume that we've got proper Google tracking ID provided. # let's see if we should attach it to the page and where # user is in admin area and we need to hide google code in admin area if ( is_admin() && ( $this->options['HideInAdmin'] == '1' ) ) { return; } # user is logged-in (we can determine user's ID) and we need to hide if for logged users if ( ( $current_user->ID != 0 ) && ( $this->options['HideForLogged'] == '1' ) ) { return; } # ok, we may show the google code... let's find out where... if ( is_admin() ) { if ( $this->options['IntoFooter'] == '1' ) { # in footer add_action( 'admin_footer', array( $this, 'admin_footer' ), 99999 ); } else { # in
add_action( 'admin_head', array( $this, 'admin_head' ), 99999 ); } } else { if ( $this->options['IntoFooter'] == '1' ) { # in footer add_action( 'wp_footer', array( $this, 'wp_footer' ), 99999 ); } else { # in add_action( 'wp_head', array( $this, 'wp_head' ), 99999 ); } } } public function throw_google_code() { echo " "; } public function wp_footer() { $this->throw_google_code(); } public function wp_head() { $this->throw_google_code(); } public function admin_footer() { $this->throw_google_code(); } public function admin_head() { $this->throw_google_code(); } public function admin_notices() { global $pagenow, $current_user; if ( ( $pagenow == 'index.php' ) && ( !get_user_meta( $current_user->ID, Config::IGNORE_NOTICE ) ) ) { echo ''; printf( __( 'Please remember to setup Google Tracking ID in order to use Google Analytics Head plugin.', Config::TEXT_DOMAIN ), 'options-general.php?page=' . Config::OPTION_SLUG ); echo '