More fixes to Popularity Contest

I posted a link a while back on how to fix the Popularity Contest plugin for WordPress 2.5. However, when converting this site back to WordPress, I found it doesn’t (completely) work if you haven’t previously installed the plugin.

The initial solution

Change line 59 of the popularity-contest.php file from:

require('../../wp-blog-header.php');

To:

require('../wp-blog-header.php');

If the needed tables (wp_ak_popularity_options and wp_ak_popularity) are not already in the database, the plugin will either not activate or show a SQL error. I haven’t dug too deeply into why the plugin is still unable to create the needed tables.

The patched solution

Pramudita posted on how to just add the tables manually using phpMyAdmin (or whatever you use to manage your database). However, copy and pasting the code from Pramudita’s site did not work on my database.

The final solution

I ended up exporting the tables from a WordPress database where Popularity Contest had previously been installed and used the generated SQL to create the needed tables in my new WordPress database.

-- 
-- Table structure for table `wp_ak_popularity`
-- 

CREATE TABLE `wp_ak_popularity` (
  `post_id` int(11) NOT NULL default '0',
  `total` int(11) NOT NULL default '0',
  `feed_views` int(11) NOT NULL default '0',
  `home_views` int(11) NOT NULL default '0',
  `archive_views` int(11) NOT NULL default '0',
  `category_views` int(11) NOT NULL default '0',
  `single_views` int(11) NOT NULL default '0',
  `comments` int(11) NOT NULL default '0',
  `pingbacks` int(11) NOT NULL default '0',
  `trackbacks` int(11) NOT NULL default '0',
  `last_modified` datetime NOT NULL default '0000-00-00 00:00:00',
  KEY `post_id` (`post_id`)
) TYPE=MyISAM;

-- 
-- Table structure for table `wp_ak_popularity_options`
-- 

CREATE TABLE `wp_ak_popularity_options` (
  `option_name` varchar(50) NOT NULL default '',
  `option_value` varchar(50) NOT NULL default ''
) TYPE=MyISAM;

Once I added the two tables with the SQL above, I was able to go into the WP admin and activate the plugin.

NOTE

Use this code at your own risk. Make sure to back up any databases that you are working with prior to trying any of these changes!