Wednesday, August 6, 2008

Could This Be A Hot Solution To My Flickr Post Problem?

flickr_wordpress_post_hack.jpgIf you're a Flickr user, and want to post photos to your blog, you know there is no way to add categories or tags to the post. There could be a plug-in solution, but I couldn't find it. Seriously, I looked for a long time. If there is one that does what I'm proposing, please let me know and I will update this post and back out what I've done.

This solution isn't for the faint of heart. And I'm not 100% sure how secure it is. But I know for a fact it works just like I want. Here is the scenario and my hack:

1. Create a new WordPress user for Flickr posts. Doesn't matter what you call it. Just make sure it has posting rights.
2. Add you blog, or modify and existing entry, in your Flickr account. How to do this is beyond the scope of my explanation.
3. Use the new WordPress user you created in step one in your Flickr blog settings.
4. Modify you xmlrpc.php file that sits in your WordPress root folder, with the below code. It would be in the same place as wp-config.php.

Here is where it gets a little hairy. Find the line which has this code snippet. Mine starts on line 1578, but yours may differ. It's in the function mw_newPost($args):

if (is_array($catnames)) {

foreach ($catnames as $cat) {

$post_category[] = get_cat_ID($cat);

}

}

Just above the code on line 1578, add this code snippet:

if ( $user_login == '*NEW_USER_NAME*' ) {

$catnames[] = '*CATEGORY*';

$tags_input[] = '*TAG1*';

$tags_input[] = '*TAG2*';

}

Save the file. Flickr gives you the ability to create a test post. I would recommend you do that before calling it good. Make SURE to remove any entries in the Settings/Writing/Update Services box before testing or your test post will show up in your RSS feed and anywhere else that you ping a new post.

Now, when you post from Flickr, using the correct WordPress user, you should have an entry in the category you choose, with the tags you want. You can add as many tags, or even categories as you like.

Again, there may be a more elegant solution that I haven't found, but for now this solves my problem. I suppose you could use this for any outside service that uses XMLRPC to post to your blog.

I'm also interested in hearing about potential security issues with this solution.

Photo courtesy of poolie.
Share this article

4 comments:

  1. I've suggested to Flickr that they pass the tags that are on the photo to WordPress. Not sure if it will happen, but at least one person over there has been told about it :-)

    ReplyDelete
  2. I'm using this (thanks BTW!) but when I do I get the category of Uncategorized instead of photoblock. (the tag gets added fine)

    /* added for flickr

    if ( $user_login == 'flickr' ) {

    $catnames[] = ‘photoblog’;

    $tags_input[] = ‘flickr’;
    }


    added for flickr */

    ReplyDelete
  3. @nolageek I can see that now. I'm having the same problem. Not sure why, I'll look at it and post a fix. Thanks for the heads up.

    ReplyDelete
  4. I had the same problem as nolageek, because I was using the category slug (photoblog) rather than the category name (Photo Blog). Posts to the category now.

    ReplyDelete

 
Copyright © 2003 - 2014 Thom Allen Weblog • All Rights Reserved.