Everyday learning’s as a web developer

One of the good (and also bad) things in being a web developer is that you have to constantly keep (un)learning. Every time I learn a new trick (like changing the default editor in Ubuntu or searching Google efficiently) or get struck due to some bug or wired behavior, I used to document it here, so that I can refer to it later and also for that fact that it might be helpful for others who are searching for the same problem in Google.

Recently I found one such wired behavior in WordPress while retrieving the categories of a post. I wrote about it and almost forgot about it till I received a comment from a person called kaigou

Insert OMFG or variant thereof, about twenty times, at two in the morning. I’ve been fighting with WP all day to get it to do what I want, and the WP docs have been useless — maybe it’s just that most folks don’t really get into really doing wacky things like nested loops and whatnot, I suppose. I was about to give up when behold, the power of google dropped your post on my screen and NOW IT WORKS. I feel like a keyboard mash is due, or buying you a virtual drink, or SOMETHING. May have to settle for quietly dancing around the house in glee, given that it is two in the morning when most non-geeky souls are quietly abed. But not me! Must celebrate your awesomeness for helping me finally getting it to work! Thank you!!!

It was really a very nice feeling to know that you can make someone from the other side of the globe dance at 2 in the morning. 🙂

This comment has given me the much needed motivation to document the day-to-day learning’s of being a web developer. So guys, from now on, if I spend more than 5 minutes on fixing something I will document it here. I also strongly urge you guys to do the same thing in your blogs and if you don’t have a blog then you are always welcomed as a guest writer here 😉

Posted in Random/Personal, Web Programming | Tagged , , | 1 Comment

Bulk Delete 0.3

I have fixed a bug in my Bulk Delete WordPress Plugin, which deleted drafts in a particular category even if only posts were selected. Thanks to one review for reporting it.

If you want to only delete posts in a category and not drafts, then you need to update to the latest version.

You can download the latest version from the Plugins home page. I have also uploaded the Plugin to the official directory to make your update process painless.

I am working on other features for the Plugin like deleting posts waiting for pending reviews etc. So stay tuned 🙂

Posted in Plugin Releases | Tagged , , | 3 Comments

IE 8.1 will support Firefox extensions

Update: Well guys, it’s time to reveal that the following post was my entry to April fool’s day. This post has been a hit and atleast a handful of people believed it. So guys, happy April Fool’s day to everyone 🙂

Yes, you read it correctly. IE 8.1 (code named Eagle Eyes) is going to support Firefox extensions. Smashing Magazine has a screenshot to prove it. The first time I came to know about it, I got goosebumps. (Yes really)

If this is true (and I believe it is), then this is the final nail in Firefox’s coffin. The only reason why I continue to use Firefox is because of it’s extensions.
Firefox has become too bloated due to it’s monolithic architecture and had become a huge memory hog. I checked my task manager as I am writing this post and you get the proof. This is with just 5 tabs open.

The major advantage Firefox had over other browsers is it’s huge list of third-party addons. But it cannot rest on it for long. Unless Firefox solves the issue with memory leaks, and comes up with some cool innovation, they cannot retain their market share. Let’s see how Firefox overcomes this new threat from IE.

firefox-memory-leaks

In addition to supporting Firefox Addons, IE 8.1 also has other cool features like Multiple Browser Rendering Engine Options, Server-side code decompiler, Website Skins etc.

On a related note, even Google’s chrome is going to support third-party extentions. Matt cutts has a tutorial which explains that steps that you need to follow to create extentions for Chrome.

Posted in Web Programming | Tagged , , , , | 4 Comments

Matt, it’s your fault

I was browsing the WordPress official Plugin repository and I came across this error message. It trickled my funny bone and I took a screenshot.

wordpress-error-message
So now I know, if something goes wrong in Plugin repository it is Matt’s fault 🙂

PS: By the way, a page refresh solved the issue and things were working fine after that.

Posted in WordPress | Tagged , , , | 2 Comments

oAuth support in Twitter and WordPress 2.8

After waiting for more than two years, Twitter has finally enabled support for oAuth to all developers using its API. It’s a great move and it’s a win-win situation both for the developers and also for Twitter users. Going forward, the Twitter third-party developers need not ask Twitter users for their username and password.

For the uninitiated, oAuth is an open protocol for online authentication. It enables a user who stores information such as a password on a particular Web site to then authorize yet another site to access that data, all the while not sharing the user’s identity with that site.

To give you a real-world non-technical example, it is like a car valet key, given to a parking assistant. Valet key unlike the original key, will have lot of restrictions like you cannot drive beyond few kilometers or cannot go beyond a particular speed etc.

In a similar move, WordPress 2.8 will also enable support for oAuth. Will Norris, has published an article explaining how oAuth is planned to be implemented in WordPress 2.8. There are yet some limitations (oAuth libraries need PHP5) but it’s a great start.

If you are a WordPress Plugin author of any Plugin that hooks into authentication then you may have to change your Plugin code to support oAuth.

I am really excited about the support for oAuth in Twitter and WordPress. I need to play with them a little once I get some free time. 🙂

Posted in API's/Mashup, WordPress | Tagged , , | 4 Comments

WordPress Plugin Readme File Generator

After writing some WordPress Plugins recently, I found that it takes a lot of effort to generate the Readme file for each of them.

For the uninitiated, readme file is a text file which has meta information about the Plugin and is usually bundled with the Plugin. Readme files for WordPress Plugins are very important, especially if you are planning to upload them to the official repository. WordPress follows a standard for the readme file so that the official repository can parse the meta information present in the file and render it like shown in the below screenshot.

bulk-delete-wordpress-plugin

The official Plugin repository has a sample readme file and also a validator. The readme file should have some tags and the text should be specified in the markdown format.

I was looking for ways to automate the process of generating these readme files and didn’t find a solution. So I created my own 🙂

You can find the WordPress Plugin readme file generator in my projects page and you can use it to generate the readme file for your WordPress Plugins too. 🙂

Try it out guys and let me know if you want any other feature to be added to it.

Posted in WordPress | Tagged , , , | 3 Comments

Evangelizing jQuery

Regular readers of this blog will know that I am great fan of jQuery. Recently I am thinking of evangelizing jQuery at work and convince people who take up decision to make jQuery as the default JavaScript framework to be used across the organization.

The following is the list of advantages/benefits which I have prepared so far. 

  • Light weight and has a very small footprint.
  • Browser abstraction – jQuery provides browser abstraction and is hightly optimized for each individual browser.
  • Excellent Plugin architecture – jQuery has an excellent Plugin architecture and you can find a jQuery Plugin for anything that you want to do.
  • Speed – When compared with other libraries, jQuery is much faster.
  • Less code == Less mistakes == better performance.
  • Active development community – It has a very active development community headed by John Resig
  • Backed by major organizations like Microsoft and Nokia. Microsoft had integrated it with the latest version of ASP.NET
  • Very small learning curve.
  • Chaining well suited for designers since it uses selectors based on CSS Selectors.
  • Excellent Documentation for all methods and selectors.
  • jQuery UI – Provides ready made themable GUI components.

Let me know if you could think of any addition to this list. Thanks 🙂

Posted in JavaScript/jQuery | Tagged , | 8 Comments

Year End Stats for 2008

Well guys, I just realized that I didn’t publish my year end stats for 2008, like how I did for 2007. So without much dealy (just after two months 😉 ), here is my year end stats for 2008.

Number of posts

number-of-posts

When number of posts is concerned, you could see that when compared with 2007, I have improved. Thanks to the pledge that I took in 2008, the number of posts has increased. This is one area where I should improve a lot more. So guys expect more mosts in 2009 😉

Number of comments

number-of-comments

When compared with 2007, the number of comments has increased slightly. It was 220 in 2007 and in 2008 it is 267. But it does not include the comments I get in Twitter or FriendFeed. (I should find some way to include them too). I should also start engaging the readers more. So my dear readers, start talking more and you could make me happy 😉

Average number of characters in posts

avg-length-of-posts

For the past three years I am pretty much consistent in the length of my blog posts, which is around 2000 characters per post. This suits the style of my posts and I guess I will stick with this for 2009 too.

Total number of characters in posts

total-length-of-posts

This represents the total number of characters that I have typed in this blog(except those removed by backspace 😉 ). Compared with 2007, I have typed more. If I succeed in my aim to write more posts in 2009, with still keeping the average length consistent, then in 2009 I will type more. Let’s see what I achieve at the end of 2009. 🙂

And this sums up my year end stats for 2008. In a nutshell, I want to

  • Write more posts
  • Engage users more
  • Keep the average lenght of posts consistent.

Let’s see how I keep it up in 2009. 🙂

<shameless self promotion>I have created these wonderful graphs using my year end stats WordPress Plugin. If you run a WordPress blog then you can also generate these graphs by downloading my year end stats WordPress Plugin.</shameless self promotion>

Posted in Random/Personal | Tagged , , | 3 Comments

Retrieving the categories of a blog post in WordPress

While writing my Bulk Move WordPress Plugin, I faced a unique bug. I was breaking my head for nearly two days to find out the correct way to retrieve the categories of a blog post in WordPress. I thought of documenting it here so that I know where I can search for it in future, when I need it and also it might help other WordPress developers who are hunted by the same bug.

Let me try to explain what I was trying to do, why it failed and finally how I rectified it.

Well I was trying to retrieve all the blog posts which satisfy a certain condition and then loop through them and assign them to a new category.

I was using the following code to retrieve the blog posts which satisfied a certain condition. Note that that I am using the built-in WordPress API as much as possible and not directly querying the database. This is one of the good coding practices for writing WordPress Plugins.

$my_query = new WP_Query;
$posts = $my_query->query(array('category__in'=>array($cat_id1, $cat_id2), 'post_type'=>'post', 'nopaging'=>'true'));

Now the variable $posts will have an array of post objects. You can loop through them using foreach.

foreach ($posts as $post) {
    print_r($post);
}

Will print

Array
(
    [ID] => 33
    [post_author] => 1
    [post_date] => 2009-01-19 08:32:41
    [post_date_gmt] => 2009-01-19 08:32:41
    [post_content] => Test from Sudar...
    [post_title] => Sudar Test
    [post_category] => 0
    [post_excerpt] =>
    [post_status] => publish
    [comment_status] => open
    [ping_status] => open
    [post_password] =>
    [post_name] => sudar-test
    [to_ping] =>
    [pinged] =>
    [post_modified] => 2009-02-04 17:54:10
    [post_modified_gmt] => 2009-02-04 17:54:10
    [post_content_filtered] =>
    [post_parent] => 0
    [guid] => http://sudarmuthu.com/?p=33
    [menu_order] => 0
    [post_type] => post
    [post_mime_type] =>
    [comment_count] => 0
)

If you look into the post object, you will see a column called post_category. I was trying to retrieve the category/categories of the blog post by reading this variable. But to my horror, I was getting only zero as value in this variable.

After some hours of hair pulling, I posted about this in the WP-hackers mailing list. It was only then I came to know that post_category is deprecated and we have to use other functions to retrieve the categories to which a blog post belongs to.

So the correct way to retrieve the category/categories is

foreach ($posts as $post) {
    $post_cats = wp_get_post_categories($post->ID);
}

$post_cats will be an array of category ids to which the blog post belongs.

So this is the complete code which you use to retrieve the list of categories to which a blog post belongs.

I didn’t know the fact that the post_category was deprecated and I learned it the hard way 😉

Even though the post_category field is deprecated it is not entirely useless. It can be used while updating a blog post.

Let’s say that you want to move a blog post from one category to another. In this case you can set the array containing the category ids to post_category field and pass it to the wp_update_post () function. Code snippet below

foreach ($posts as $post) {
    $new_cats = array(5,10);
    wp_update_post(array('ID'=>$post->ID,'post_category'=>$new_cats));
}

Whew!! Finally I know how the correct way to retrieve the categories to which a blog post belong to. 😉

Posted in WordPress | Tagged , | 25 Comments

WordPress 2.7.1 Released

WordPress 2.7.1 has been released and I just updated this blog.

It is a maintanence release for WordPress 2.7 and the official WordPress development blog reports that this release has fixes for around 68 tickets. Some of these tickets are bug fixes and therefore it is a recommended upgraded.

Since no new features have been introduced, this release should not break any of your Plugins or themes.

Posted in WordPress | Tagged | Leave a comment