How to Fix the Democracy Plugin n Problem

I noticed during a recent WordPress upgrade, the Democracy Plugin started adding an extra "n" each time you saved the post:

Democracy Plugin n Problem

Here's how to fix the problem:

(1) With a text editor, open "democracy.php" – it's located in the democracy subfolder in the plugin folder.

(2) Locate the line below (around line number 331):

return preg_replace('/{democracy[\w\W\s^}]*?}/', '\n<div>\\0</div>', $content);

(3) Change the last set of single quotes into double quotes:

return preg_replace('/{democracy[\w\W\s^}]*?}/', "\n<div>\\0</div>", $content);

That's it. That should take care of the Democracy Plugin's extra n problem.

CoolPlayer, Brian's Threaded Comments and WordPress 2.3.1

Hello everyone. I'm back. First, I want to apologize for the two false alarms (via RSS/email) in the last two weeks. The first false alarm was caused by switching the IP address of this blog with my EDA Blog. For some reason, the IP switch triggered FeedBurner into thinking there was a new post when there wasn't. That's why you saw a bunch of stuff for my EDA Blog (FeedBurner used the old IP for iZachy, which was really mapping to EDA Blog). The second false alarm occurred when I reactivated my plugins after upgrading to WordPress 2.3.1. My guess is that the Better Feed plugin triggered FeedBurner. You might want to leave that plugin activated for your next WordPress upgrade.

As I mentioned previously, I upgraded to WordPress 2.3.1 (from WP 2.2.2) recently using my WordPress upgrade process. After upgrading, all of my plugins worked except for the Crawl Page and Brian's Threaded Comments plugins. One of my readers mentioned that CoolPlayer did not work with WordPress 2.3.1. I can assure you that is not the case. Both CoolPlayer 9.0 and 9.3 worked with WordPress 2.3.1. However, I had to hit the browser reload button after I upgraded from CoolPlayer 9.0 to 9.3 before the plugin worked correctly.

I could never get the Crawl Page 1.00 plugin to work, but I did get Brian's Threaded Comments plugin to work with WordPress 2.3.1. After upgrading to WP 2.3.1, I got a 404 error whenever I tried to leave a comment. The fix for this problem is actually fairly simple. You just need to enter "wp-comments-post.php" in the custom box on the threaded comments admin page (Options => Threaded Comments):

Brian's Threaded Comments

WordPress 2.3.1 breaks a lot of plugins. You should check around to be sure your plugins work before upgrading. At the bottom of this post, I listed plugins that I use that work with WordPress 2.3.1. If you are using an older version of the Google XML Sitemaps plugin (I was using 2.7.1), you should upgrade to the latest version (currently 3.0.2.1). The new version works with WP 2.1+ and has a bunch of new features. It's a big improvement on already nice plugin.

Plugins that work with WordPress 2.3.1:

  • Akismet 2.0.2
  • Audio player 1.2.3
  • Better Feed 1.1
  • Brian's Threaded Comments 1.5.12
  • Contact Form ][ 2.0.13
  • CoolPlayer 9.3 (CoolPlayer 9.0 also works)
  • Democracy 2.0.1
  • FeedBurner FeedSmith 2.3
  • Google XML Sitemaps 3.0.2.1
  • Head META Description R1.1.2
  • Related Posts 2.02
  • Similar Posts 2.3.6
  • Simple Recent Comments 0.1.2
  • Smart Update Pinger 2.0
  • Spam Karma 2 2.3 rc3
  • Unfancy Quote 2.0
  • WordPress Database Backup 2.1.5

Hack for RSS Feed Ads

I've been playing with the Better Feed WordPress plugin to insert ads in my RSS feed. As I mentioned previously, it's fairly easy to add a text footer or graphics ad into your feed. However, if you want to rotate between multiple ads, then you need to hack the plugin. Read on to find out how.

You will need to find the following line in the Better Feed plugin (if you have not added a footer or modified the plugin, it's around line #101):

$content .= wp_ozh_betterfeed_detokenize($wp_ozh_betterfeed['footer']);

I'm going to call it the "footer" line. Once you have found the "footer" line, you will need to add a block of code above that line. Something like:

[block of code]
$content .= wp_ozh_betterfeed_detokenize($wp_ozh_betterfeed['footer']);

I have put together three sets of block codes that you can use. Select the one that best suits your needs.

Block 1 – Alternate ads
This code block is for alternating ads in your feed. For instance, post #1 will show "Ad-B", post #2 will show "Ad-A", post #3 will show "Ad-B" again, post #4 will show "Ad-A" again, etc. Here's the block to insert above the "footer" line:

if ($id % 2 == 0 ) {
  $ad = "Ad-A";
} else {
  $ad = "Ad-B";
}
$content .= $ad;

Block 2a – Rotate between four ads
[2007.03.10 note: The random number generator used in this block can cause old posts to show up as "updated" in Bloglines. If you don't want this to happen, use Block 2b instead.]
This code block is for displaying one of four ads in your feed. For instance, post #1 will show either "Ad-C" or "Ad-D", post #2 will show either "Ad-A" or "Ad-B", post #3 will show either "Ad-C" or "Ad-D" again, post #4 will show either "Ad-A" or "Ad-B" again, etc. Here's the block to insert above the "footer" line:

if ($id % 2 == 0) {
  $num = rand(1,2);
  if ($num == 1) {
    $ad = "Ad-A";
  } else {
    $ad = "Ad-B";
  }
} else {
  $num = rand(1,2);
  if ($num == 1) {
    $ad = "Ad-C";
  } else {
    $ad = "Ad-D";
  }
}
$content .= $ad;

Block 2b – Rotate between four ads
[Added on 2007.03.10]
This code block is for displaying one of four ads. It's like the block of code above, but it uses the timestamp of the post instead of a random number generator. It shouldn't change an old post to "updated" in Bloglines. Here's the block to insert above the "footer" line:

$num = get_post_time('s');
if ($id % 2 == 0) {
  if ($num < 30) {
    $ad = "Ad-A";
  } else {
    $ad = "Ad-B";
  }
} else {
  if ($num < 30) {
    $ad = "Ad-C";
  } else {
    $ad = "Ad-D";
  }
}
$content .= $ad;

Block 3 – Display an ad for every 3rd, 6th, and 9th post
I use this code block for my news site. I write over 20 posts a day on that site and it would look too commercial if I ran a RSS ad in every post. This block of code will display an ad for every 3rd, 6th, and 9th post. Here's the block to insert above the "footer" line:

$ad3 = "Ad-A";
$ad6 = "Ad-B";
$ad9 = "Ad-C";
$num = substr ($id, -1);
switch ($num)
{
  case 3:
    $content .= $ad3;
    break;
  case 6:
    $content .= $ad6;
    break;
  case 9:
    $content .= $ad9;
    break;
}

You will need to replace "Ad-A", "Ad-B", "Ad-C", and "Ad-D" with the html code for your ads. Keep in mind that the code is already using double quotes. So, you will either need to use single quotes or omit the quotes in your html code for your ads. For instance:

$ad = "<p align=center><a href=http://www.embeddedstar.com/careers/><img src=http://edageek.com/adimages/jobs468.gif border=0></a></p>";

As you can see, I didn't use any quotes between the double quotes above.

One other note. WordPress assigns post id numbers in the order you saved them. The id numbers can get out of order if you don't publish your posts in the same order you saved them. This may cause the ads to appear to display out of sequence (ie – the same ad displaying two times in a roll). That is not the case.

free creative and multimedia magazines

Upgrading to WordPress 2.1 Tip

I upgraded to WordPress 2.1 recently and I want to share a tip. I uncompressed the new WP 2.1 files into a new directory. I name it wordpress2.1 then I upload the entire new directory to my server. When I was ready to switch to the new version, I jus renamed the current wordpress directory to something like wordpress2.07. Then I renamed the new version to match the name of my official wordpress directory (ie – wordpress). This way, I have a clean install and I still have the old version to cut back to if something went wrong.

If you look at the WordPress upgrade instructions, it'll tell you to delete certain files and don't delete certain files. Seems kinda of messy to me. Below are the steps I took. Keep in mind my situation will be different from your setup, so you will need to modify the steps to suit your needs.

  1. Download and extract WP 2.1 to a new directory named wordpress2.1
  2. Back up the database by using the WordPress backup plugin or phpMyAdmin
  3. I made a change to template-functions-post.php in the old version of WordPress to alter the behavior of the more tag, so I had to make the change in the new version. In WP 2.1, I had to make the change in a new file called post-template.php.
  4. Copy the following files from the old WordPress directory to the new directory:
    • wp-config.php (it's in the root wordpress directory)
    • plugins (except Akismet because WP 2.1 comes with a new version of Akismet)
    • theme files
  5. Deactivate the plugins (don't forget to write down special codes, like the Akismet api key, in case you need to re-enter them after you re-activate the plugins)
  6. Rename the old wordpress directory (ie: wordpress –> wordpress2.07)
  7. Rename the new wordpress directory (ie: wordpress2.1 –> wordpress)
  8. Run the upgrade script (load …/wordpress/wp-admin/upgrade.php in the browser)
  9. Reactive the plugin one by one

Remember, the above steps are for my situation. You will need to look at the WordPress upgrade instructions and modify the above steps for your setup.

free eWeek