settings menu */ add_action('admin_menu', array($this, 'add_to_settings_menu')); } /* * Save default settings upon plugin activation */ function add_default_options() { //if options already exists then return early if (get_option('asga_options')) return; $defaults = array( 'plugin_ver' => ASGA_PLUGIN_VER, 'ga_id' => '', 'js_location' => 1, //header 'js_priority' => 20, //default is 20 'log_404' => 0, 'log_search' => 0, 'ua_enabled' => 1, //UA is enabled by default 'displayfeatures' => 0, 'ga_ela' => 0, 'anonymise_ip' => 0, 'ga_domain' => '' ); global $wp_roles; //store roles as well foreach( $wp_roles->roles as $role => $role_info ) { $defaults=array_merge($defaults,array('ignore_role_' . $role=>0)); } update_option('asga_options',$defaults); } /*register our settings, using WP setting api*/ function ASGA_admin_init() { register_setting('asga_plugin_options', $this->option_name, array($this,'ASGA_validate_options')); } /** * Adds a 'Settings' link for this plugin on plugin listing page * @return array Links array */ function add_plugin_actions_links($links, $file) { if (current_user_can('manage_options')) { $build_url= add_query_arg('page', $this->plugin_slug, 'options-general.php'); array_unshift( $links, sprintf('%s', $build_url, __('Settings')) ); } return $links; } /* * Adds link to Plugin Option page + do related stuff */ function add_to_settings_menu() { $page_hook_suffix =add_submenu_page('options-general.php', 'Ank Simplified GA', 'Ank Simplified GA', 'manage_options', $this->plugin_slug, array($this, 'ASGA_Options_Page')); /*add help stuff via tab*/ add_action( "load-$page_hook_suffix", array( $this, 'add_help_menu_tab' ) ); /*we can load additional css/js to our option page here */ } /** * Callback Function to handle and validate the form data * * @param array $in - POST array * @returns array - Validated array */ function ASGA_validate_options($in) { $out = array(); //always store plugin version to db $out['plugin_ver'] = ASGA_PLUGIN_VER; //start handle form data // Get the actual tracking ID if (preg_match('#UA-[\d-]+#', $in['ga_id'], $matches)) $out['ga_id'] = $matches[0]; else $out['ga_id'] = ''; //warn user that the entered id is not valid if (empty($out['ga_id']) || $out['ga_id'] === '') { add_settings_error('asga_options', 'ga_id', 'Your GA tracking ID seems invalid.'); } $out['js_location'] = absint($in['js_location']); $out['js_priority'] = absint($in['js_priority']); $out['ga_domain'] = esc_attr($in['ga_domain']); $checkbox_items = array('ua_enabled', 'anonymise_ip', 'displayfeatures', 'ga_ela', 'log_404', 'log_search'); global $wp_roles; foreach ($wp_roles->roles as $role => $role_info) { $checkbox_items[] = 'ignore_role_' . $role; } foreach ($checkbox_items as $checkbox_item) { if (isset($in[$checkbox_item]) && '1' == $in[$checkbox_item]) $out[$checkbox_item] = 1; else $out[$checkbox_item] = 0; } return $out; } /** * Function will print our option page form * @initiated by add_submenu_page */ function ASGA_Options_Page() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } ?>
Developed by- Ankur Kumar | Fork on GitHub
Do you have a Google Analytics Account ?
'.
'In order to use this plugin you need to gave a Google Analytics Account. Create an account here. It is FREE.
'.
'How do i find my Google Analytics ID ?
'.
'Please check out this link
'.
'How do i view my stats ?
'.
'Login to Google Analytics Account with your Gmail ID to view stats.'.
'
Things to remember
'.
'
Need more information ?
'.
'A brief FAQ is available on plugin's official website. '.
'OR click here for more.
'.
'Support is only available on WordPress Forums, click here to ask anything about this plugin.
'.
'You can also browse the source code of this plugin on GitHub. '.
'
Quick Links
' . '' . '' ); } } //end class //init this class global $ASGA_Admin_Class; $ASGA_Admin_Class= new ASGA_Admin_Class();