Fixing Counterize

Counterize is a fairly popular plug-in which gives you Google Analytics type of reports from within WordPress and offers a quick way to see how site traffic is trending and what pages are getting hit.

Counterize

Version 2.14.1 of Counterize was released last year and since then there has been no further development. Unfortunately Counterize contains a number of serious bugs which can have a significant effect on the performance of your site over time.

The issues relate to the plug-in activation code. It hooks the WordPress plug-in system in such a way to effectively re-install itself every time ANY plug-in is activated. Worse, because of bugs, the plug-in will create a new index in the large wp-counterize table everytime a plug-in is installed.

It will continue creating indexes until MySQL’s limit of 64 indexes is reached, when a database error will be generated. By this time, the maintenance of all those indexes has the potential to severely degrade the performance of the site, particularly on a shared server.

Yet another bug may cause a database error to be received when activating any plug-in.

The following fixes are required:

1. In plugins/counterize/counterize.php

Replace these lines

1069: include("counterize_install.php");
1070: $install = (basename($_SERVER['SCRIPT_NAME']) == 'plugins.php' && isset($_GET['activate']));
1071: if ($install)
1072: {
1073:   counterize_install();
1074: }

with
register_activation_hook(dirname(__FILE__).'/counterize_install.php','counterize_install');

2. In plugins/counterize/counterize-install.php

On lines 175 and 181 replace "$minorVersion" with $MinorVersion

Replace this line
183: $sql = "UPDATE `".counterize_logTable()."` set IP=MD5(IP);" ;
with
183: $sql = "UPDATE `".counterize_logTable()."` set IP=substr(md5(IP),1,16);";

Applying The Fixes

While the changes above fix the bugs, the Counterize plug-in should be de-activated and then re-activated to ensure the plug-in is set to the correct version.

Finally, use your regular database manager (eg phpMyAdmin) to edit the structure of the wp_counterize table. This table should have just two indexes: key and timestamp. All multiple timestamp indexes should be deleted (ie, timestamp_2. etc).

This entry was posted in Plug-in, Wordpress and tagged .

2 Responses to Fixing Counterize

  1. MacBoy says:

    Hello,

    Thanks for catching all those problems with Counterize!

    Perhaps you should fork the plugin and maintain it with all those improvements?

    Or is there another plugin that you’d recommend?

    Thanks and keep up the great posts!

    (please send me an email if you reply)

    — MacBoy

  2. Harrie S says:

    Hoi, thx alot.

    In my case the two indexes are called PRIMARY on field id and TIMESTAMP.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>