Archive for the 'Wordpress' Category

My first lesson in PHP/Wordpress plugin development

Recently I had released a WordPress plugin - Google Blog Search Preview. I had tested it over two webhosting providers and everything seemed perfect. But within a week of release, I was getting reports of this plugin failing on certain installations. Well, it turns out that I had coded my plugins in PHP5.

The error was,

Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’ in /home/brodopr/public_html/brodo/wp-content/plugins/jj_gblogsearch.php on line 15

Unfortunately many sites still run WordPress on PHP4. The biggest problem is that object oriented features in PHP is very different between version 4 and 5. For example, the static keyword is not available in PHP 4 which I was using in my plugins!

So the first lesson in WordPress plugin development - Test your plugins in both PHP 4 and PHP 5 installations! WAMP server even has a plugin which allows you to switch between PHP4 and PHP5. So that was easy!

I have released version 1.1 of Google Blog Search Preview  which works on PHP4 and PHP5. You can download it here. Many thanks to Carlo and Len for reporting this problem.

Releasing Google Page Rank plugin 1.0 for Wordpress

Google Page Rank Today I am releasing my second plugin for WordPress - The WP Google Page Rank Display 1.0.  You can use this to show off your Google Page Rank in the WordPress blog. This is superior to other plugins out there due to two major reasons,

1. Page Rank value is cached for 24 hours and hence means minimum load on Google servers and on your blog.

2. There are no external dependencies for this plugin.

Google Page Rank indicates the value of your site assigned by Google search engine. It varies from 0 to 10. For example, http://www.google.com has a Page Rank of 10. Higher page rank means higher traffic from Google search engine.

For more details on the Google Page Rank Plugin and for downloads please visit the plugin page. If you have any comments, suggestions or bug reports please contact me.

Wordpress Plugin - Google Blog Search Preview

I do most of my programming during weekends. This weekend I decided to write a WordPress plugin. I also wanted to improve my recently acquired PHP skills.

WordPress dashboard displays incoming links from Technorati. This is very useful since it lets you know who are discussing about your blog (not all have trackbacks enabled). But sometimes not all links are visible on Technorati. So I supplement it by doing a “link search” on Google Blog Search.

What if I display the Google Blog Search incoming links also on the WordPress dashboard? Hence this plugin! This plugin uses rss library of WordPress. I wanted to do Ajax, but there isn’t any “native” support for Ajax in WordPress :(

Do checkout Google Blog Search Preview Plugin!

Linking to localhost?

Ever wondered how many people are linking to localhost files from their websites or blogs? Today, I found out an easy way to get the latest localhost linkers!

I installed wordpress locally and was testing it using the URL http://localhost/. The incoming links section of the Wordpress dashboard showed the following blogs which are linking to localhost. Very funny!

Localhost linking!

If you check your localhost installation, you might find my blog as well! Pretty neat way to get more traffic - eh?

Hiding sub categories in Wordpress - a quick hack

Here is a quick hack to hide sub categories in Wordpress. This has the added advantage that even though sub categories are not visible, they will still get crawled by search engines. For example, the categories you see on the right are only the root categories.

All you have to do is to add the following line to the Wordpress stylesheet.

.children { display: none; }

This works because the secondary level categories have “children” as the style class.

Backing up your Wordpress installation on Dreamhost

I did a complete backup of this Wordpress blog yesterday. There isn’t much written, but loosing my blog entries is not something I am looking forward to! It is very important to backup your blog. I will give some reasons if you are not convinced.

First, this blog is hosted on Dreamhost. Recently many problems have been cropping up with dreamhost such as router disaster or network disaster or something like that. You never know when they will have a disk failure and it turns out that their backup tape/disk is unusable!

Secondly, Wordpress is not very secure if the recent events are any indication. The Wordpress 2.1.1 was modified by some deranged cracker. So it is quite possible that there are problems in Wordpress 2.1.2 also and if some nutcase decides to hack your site? Boom!!! - all your posts are gone..

How to backup my Wordpress blog hosted on Dreamhost?

The backup process involves two things. Backing up your blog database and backing Wordpress files which includes theme files modified by you. You must backup both.

Backing up Wordpress database - Backing up Wordpress database is very simple in Wordpress 2.1+. In earlier versions you need to install backup plugin. In Wordpress 2.1+ you can find export option under manage as shown below,

Backing up Wordpress 2.1+

Backing up Wordpress files including customized theme files - My host is dreamhost and I will explain how the Wordpress file backup can be done very quickly. If you use Windows explorer and try to copy everything, it can even take hours! This is because the dreamhost installation contains hundreds of themes you don’t use and also transferring thousands of files over FTP is very slow.

Here is a quick backup solution. Connect to the Dreamhost shell using Putty (A secure shell client). Go to your Wordpress installation folder and type the following command.

zip -r backupall.zip *

This will create a single zip named backupall.zip which contains everything. Now this can be quickly copied to your system!

Fighting comment spam in a Wordpress blog

We all are used to email spam. I get around 100 spam mails daily in my Gmail account. Thankfully most of these are identified as spam by Gmail and gets moved to spam folder automatically.

When I started this blog, I never thought that spam would be a major issue. Initially I haven’t added any comment moderation. Within a week, I started seeing spam comments mostly related to pharmacy and drugs. I started manually deleting spam and soon I realized it is not going to work.

In Wordpress, under options->discussion, there are a couple of spam fighting measures available. I enabled comment moderation which automatically puts a comment in moderation queue if it contains 2 or more links. I have also enabled common spam word protection. This means that any comment which contains words in this list will be automatically put into moderation queue.

The solved the problem for a few more days. Then I noticed that I have over 100 comments to moderate. Now sorting through 100 comments to find a genuine comment is not something you would cherish!

Wordpress provides something called comment blacklist. If any of the words in this list is part of the comment, the comment will be nuked. It will not appear in moderation queue. So I analyzed few spam comments and added the common words into the comment black list.

I had hoped that these measures would solve the spam problem. Soon I realized that I was too optimistic. I started getting a lot of comments and it contained black listed words with spelling mistakes! For example, the word viagra will appear as viegra or something similar.

Looking at the spam comments I noticed that all of them are coming from a set of specific IP addresses. So what I needed was a way to blacklist IP addresses.

In Wordpress, under manage->files you can see the .htaccess file. This can be used to block a specific set of IP addresses. So I added the following entries in this file (Substitute the actual IP address instead of 127.0.0.1)

order allow,deny
deny from 127.0.0.1
allow from all

So today, I have no comments to moderate. Thank god! :)

Notes

1. There are sophisticated spam fighting tools such as the Akismet which is distributed. I am yet to use it.
2. It is better to disable trackbacks. Tools such as trackback submitter is widely used by spammers.

Wordpress 2.1 upgradation and theme compatibility

This blog is powered by Wordpress blogging software installed on a dreamhost machine. Dreamhost is an employee owned Web hosting service and is popular with bloggers. Dreamhost offers “one click installs” for a lot of Web applications and Wordpress is one of them.

Within a week of Wordpress 2.1 release, Dreamhost has enabled an auto upgrade link! With a single click I could upgrade my existing Wordpress 2.0.5 installation to Wordpress 2.1. Before upgrading, I did take a backup of my blog (there was nothing much in it :)), but the upgrade went through without any issues.

But then I noticed that there were some database errors under the category link. First I thought it was due to some error in the upgrade script. But looking closer, I found that the problem was with theme I was using! Interestingly, Wordpress 2.1 release broke a lot of themes out there and mine was one of them. It was to be expected since 2.1 release had major changes.

And hence I switched to the typoxp theme. It appears to be an ideal 3 column theme for a “text heavy” blog.