<,php

/*
* Plugin Name: Official StatCounter Plugin
* Version: 2.0.6
* Plugin URI: http://statcounter.com/
* Description: Adds the StatCounter tracking code to your blog.
To get setup: 1) Activate this plugin 2) Enter your StatCounter Project ID and Security Code in the options page.
* Author: Aodhan Cullen
* Author URI: http://statcounter.com/
*/

// Defaults, etc.
// the last ‘false’ should make these constants case sensitive
define(“key_sc_project”, “sc_project”, false);
define(“key_sc_position”, “sc_position”, false);
// legacy problem with sc_security naming
define(“key_sc_security”, “key_sc_security”, false);
define(“sc_project_default”, “0” , false);
define(“sc_security_default”, “” , false);
define(“sc_position_default”, “footer”, false);

// Create the default key and status
add_option(key_sc_project, sc_project_default);
add_option(key_sc_security, sc_security_default);
add_option(“sc_invisible”, “0”);

// Create a option page for settings
add_action(‘admin_menu’ , ‘add_sc_option_page’ );
add_action( ‘admin_menu’, ‘statcounter_admin_menu’ );
add_action(‘wp_head’, ‘addToTags’);

function statcounter_admin_menu() {
$hook = add_submenu_page(‘index.php’, __(‘StatCounter Stats’), __(‘StatCounter Stats’), ‘publish_posts’, ‘statcounter’, ‘statcounter_reports_page’);
add_action(“load-$hook”, ‘statcounter_reports_load’);
$hook = add_submenu_page(‘plugins.php’, __(‘StatCounter Admin’), __(‘StatCounter Admin’), ‘manage_options’, ‘statcounter_admin’, ‘sc_options_page’);
}

function statcounter_reports_load() {
add_action(‘admin_head’, ‘statcounter_reports_head’);
}

function statcounter_reports_head() {
,>

<,php } function statcounter_reports_page() { $sc_project = get_option(key_sc_project); if($sc_project==0) { $sc_link = '//statcounter.com/'; } else { $sc_link = '//statcounter.com/p'.$sc_project.'/,source=wordpress'; } echo '‘;

}

// Hook in the options page function
function add_sc_option_page() {
global $wpdb;
add_options_page(‘StatCounter Options’, ‘StatCounter’, “manage_options”, basename(__FILE__), ‘sc_options_page’);
}

function sc_options_page() {
// If we are a postback, store the options
if ( isset( $_POST[‘info_update’] ) && check_admin_referer( ‘update_sc_project_nonce’, ‘sc_project_nonce’ ) ) {

// Update the Project ID
$sc_project = trim($_POST[key_sc_project]);
if ($sc_project == ”) {
$sc_project = sc_project_default;
}
update_option(key_sc_project, $sc_project);

// Update the Security ID
$sc_security = trim($_POST[key_sc_security]);
if ($sc_security ==”) {
$sc_security = sc_security_default;
}
update_option(key_sc_security, $sc_security);

// Update the position
$sc_position = $_POST[key_sc_position];
if (($sc_position != ‘header’) && ($sc_position != ‘footer’)) {
$sc_position = sc_position_default;
}

update_option(key_sc_position, $sc_position);

// Force invisibility
$sc_invisible = $_POST[‘sc_invisible’];
if ($sc_invisible == 1) {
update_option(‘sc_invisible’, “1”);
} else {
update_option(‘sc_invisible’, “0”);
}

// Give an updated message
echo “

StatCounter options updated

“;
}

// Output the options page
,>

<,php wp_nonce_field( 'update_sc_project_nonce', 'sc_project_nonce' ); ,>

<,php if (get_option( key_sc_project ) == "0") { ,>

StatCounter Plugin has been activated, but will not be enabled until you enter your Project ID and Security Code.

<,php } ,>

Using StatCounter

StatCounter is a free web traffic analysis service, which provides summary stats on all your traffic and a detailed analysis of your last 500 page views. This limit can be increased by upgrading to a paid service.

To activate the StatCounter service for your WordPress site:

  • Sign Up with StatCounter or add a new project to your existing account
  • The installation process will detect your WordPress installation and provide you with your Project ID and Security Code

StatCounter Options

<,php $checked = ""; if(get_option('sc_invisible')==1) { $checked = "checked"; } echo "n”;
,>

<,php } $sc_position = get_option(key_sc_position); if ($sc_position=="header") { add_action('wp_head', 'add_statcounter'); } else { add_action('wp_footer', 'add_statcounter'); } // The guts of the StatCounter script function add_statcounter() { global $user_level; $sc_project = get_option(key_sc_project); $sc_security = get_option(key_sc_security); $sc_invisible = 0; $sc_invisible = get_option('sc_invisible'); if ( ( $sc_project > 0 )
) {
,>


<,php if($sc_invisible==1) { if($protocol == "http:") { echo "n“;
} else if ($protocol == “https:”){
echo “n“;
}
},>

Leave a Reply

Your email address will not be published. Required fields are marked *

*