Tag Archives: Bug

Adding additional account to Android phone and buying paid apps in India

After paid apps were introduced in Android market for Indian users, I wanted to buy a couple of them. But it took me a couple of days to do it, because of a variety of related and un-related issues. I thought of documenting it here, so that it would be useful for others who are facing the same problem.

The first issue that I faced was that, I have associated my phone with my Google App account and not a regular gmail account. Because of this, I was not able to use Google Checkout to buy paid apps. To fix this, I was supposed to add another Google account that has Google checkout enabled.

The second issue is that, there is some bug in android which doesn’t allow you to add additional accounts. The symptom of this bug is that you will get a error message which says “You don’t have a network connection”, even though you are connected through wifi or gprs. It took me a couple of days to figure out that it is a bug. Searching the internet revealed, that this bug is found across devices and across Android OS versions. I really wonder why Google has not fixed it yet.

Anyways, after searching sometime, I found out a relatively easy fix. You can try to add the account using the Youtube app. The following are the steps to do that.

  • Open up your Youtube app
  • Select menu –> My account and then click Add Account. Enter the new email address
  • Go back to your home screen and then select Menu -> Settings -> Accounts & sync
  • Set sync settings there and put in the password when prompted

Now you can go to the Market app and start buying paid apps. 🙂

Posted in Android/Java | Tagged , , , | 4 Comments

Making Yahoo Pipes feed work in wp-o-matic

Recently I was playing with wp-o-matic WordPress Plugin using a feed from Yahoo pipes. For the uninitiated, wp-o-matic is a WordPress Plugin which enables you to create new posts automatically from RSS or Atom feeds and Yahoo pipes is an interactive feed aggregator and manipulator.

After configuring everything, wp-o-matic kept on saying “0 posts fetched”, even though there were some posts in the feed generated by Yahoo pipes. After some research, I found out that I was not the only one facing this issue and there seems to be a bug in wp-o-matic which breaks feed urls having ampersand (&) character.

After digging into the code further, I found out the url is HTML encoded and stored in the database and is not decoded while retrieved. This occurs in the addCampaignFeed() function at line 1011 in the wpomatic.php file.

function addCampaignFeed($id, $feed)
    global $wpdb;
    $simplepie = $this->fetchFeed($feed, true);
    $url = $wpdb->escape($simplepie->subscribe_url());
    // code continues

In the above code, the function $simplepie->subscribe_url() returns the html encoded url. So to fix this, we have to pass the url to the htmlspecialchars_decode function. So to fix the bug we have to use the below code.

function addCampaignFeed($id, $feed)
    global $wpdb;
    $simplepie = $this->fetchFeed($feed, true);
    $url = $wpdb->escape(htmlspecialchars_decode($simplepie->subscribe_url()));
    // code continues

I have also notified the Plugin author about this and hopefully should be fixed soon, till then you can use the above code change if you are using feed from Yahoo pipes.

Posted in WordPress | Tagged , , | 21 Comments

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

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) {

Will print

    [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);

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

PHP 4, WordPress 2.5 and BBPress 0.9

I just found a bug in WordPress 2.5, which is exposed when it is run in PHP 4.3.11. I thought of detailing about it here so that it will be useful for others who are seeking solution for the similar problem.

Recently I was trying to integrate WordPress and BBPress to make them share a single database and cookie. The advantage of this integration is that a logged in user can share the session between WordPress and BBPress.

Right now the latest version of BBPress is 0.9 and it can be integrated only with WordPress 2.5. Only BBPress 1.0 (which is in alpha) can be integrated with WordPress 2.7. There is an excellent tutorial by _ck_ which explains the reasons behind this and it also has a step by step guide to integrate them.

I tested this integration in my test server running PHP 5 and was able to do it within minutes. But when I tried to do it in another server running PHP 4.3.11, it was not working. After lot of head banging and hair picking, I found out that there is a bug in WordPress 2.5, which does not allow you to share the cookie with BBPress 0.9 under PHP 4.

The following is the technical detail about the bug. If you are not technically inclined, you can safely skip it. You only need to remember that you cannot integrate WordPress 2.5 and BBPress 0.9 in PHP 4, you have to use WordPress 2.5.1

Well for the brave hearts here is the explanation. 🙂

In both WordPress and BBPress, the function wp_hash() is used to generate the hash, which is required to encrypt the cookie.

In WordPress 2.5, the function wp_hash() is defined in wp-includes/pluggable.php file as

function wp_hash($data) {
    $salt = wp_salt();

    if ( function_exists('hash_hmac') ) {
        return hash_hmac('md5', $data, $salt);
    } else {
        return md5($data . $salt);

It checks whether the function hash_hmac()is present. If not it generates the hash using the function md5(). The problem is that hash_hmac() is present only in PHP 5 and WordPress includes a copy of hash_hmac() function in the wp-includes/compat.php file for backward compatibility.

But in BBPress, wp_hash() function is defined in bb-includes/pluggable.php as

function wp_hash($data) {
    $salt = wp_salt();

    return hash_hmac('md5', $data, $salt);

This bug is present in WordPress 2.5 and will only affect servers running PHP 4. So if you are running PHP 4 and want to integrate WordPress and BBPress, then you have to use WordPress 2.5.1 and not 2.5.

Hope this explanation saves some hair for someone somewhere, doing something similar. 🙂

Posted in WordPress | Tagged , , , | 1 Comment