Twitter updater


UPDATE: Please head on over to the new home of my plugin: TWITTERUPDATER.COM this post here will not be updated any longer!!!

So, I found this cool plugin posting updates to twitter once you wrote a new blog post (or edited an old one). It’s pretty nice and can be found on the authors, Victoria Chan, site here (v1.1).

Jonathan Dingman then released an update adding tinyurl support (v2.0) which can be found here.

I just edited this v2.0 and replaced the tinyurl-support with support for the new url-shortening service ZZ.GD which results in even shorter short-urls saving more space in the tweet in case a post title is longer…

My new version (v2.07.1) can be found here (please read edits below for more information!!!): Twitter Updater v2.07.1

Known Issues:

  • None atm

Feature requests:

  • Possibility to include post’s category in tweet

Installation:
1. Download the plugin (see above link.)
2. Unzip the compressed file to your hard drive.
3. Upload the “twitter_updater” folder to your wp-content/plugins folder.
4. Browse to the Plugins page under wp-admin and activate the plugin.
5. Setting the options: Browse to Manage->Twitter Updater.
6. On this page, you can set any options you would like to.
7. IMPORTANT: Make sure you enter your Twitter username and password, then click on “save login”
8. That’s it! Now your Twitter.com status will be updated every time you publish a new post.

Edit (July 15th 2008): Just a quick note…the recent release of WP 2.6 has messed something up. While the plugin continues to work fine in WP version 2.5.1 and older, it keeps firing two updates (one with an invalid zz.gd-short-url) in WP 2.6. I’m going to investigate…stand by for news…and hopefully a quick fix.

Edit #2 (July 15th 2008): I’ve identified the culprit…WP2.6 uses post-revisions (saving multiple instances of the post using autosave)…hence the multi-tweet…working on a fix now…

Edit #3 (July 15th 2008): It’s indeed the post-revisions thing, but the quick workaround I tried (disabling post revisions after all) has had some major side-effects (namely edits of posts were not saved anymore)…so I really need to address this issue by checking the post status and ignoring revisions…fix probably coming tomorrow…for the time being please just manually delete the first auto-tweet.

Edit #4 (July 17th 2008): Sorry about the delay, but my computer fried itself today, so I had no time to fix it yet…exciting news forthcoming…as hopefully the fix…stay tuned.

Edit #5 (July 17th 2008): This little plugin has it’s own twitter source parameter now…so it’ll say “from Ingoal’s Twitter Update” instead of “from web” from now on…you can grab the latest version, version 2.02 above…version 2.03 with the bugfix (double-tweet) is still forthcoming…

Edit #6 (July 22nd 2008): Sorry about the delay…but I had something else going on, so it took me a while to write the fix. I deleted some of the options, from now on out you’ll have the update choice to auto-twitter when posting a new post (with or without link using zz.gd) and auto-twittering when editing old posts…that’s it. Compatible to WordPress version 2.6! So if you’re running WP 2.6, please update to version 2.03!!! …and if you’re running WP 2.5.1 or older, please continue to use version 2.02!!! Hat tip to microkid for his hint about identifying WordPress post revisions and auto-saves!!!

Edit #7 (July 27th 2008): Fixed the post-title issue. In the prior version post titles were truncated if they included an ampersand ( & )…this is fixed now…please update.

Edit #8 (July 29th 2008): Introduced alternative method to retrieve the shorturl from zz.gd (using curl)…please update if you had problems (error message, empty shorturl) and make sure you have a look at the twitter updater page (manage) -> check the new checkbox! If you didn’t have problems you don’t need to do anything…

Edit #9 (August 04th 2008): Introduced a cascading in the shorturl generation. After zz.gd was down the last two days due to server issues, ppl using the plugin were stuck with empty shorturls. To rectify that situation and keep it from happening in the future the cascade of zz.gd — tinyurl.com was introduced. If zz.gd is down, the shorturl will be generated using tinyurl.com. Other cascades might be added in the future, but for now, this one seems to be more than enough.

Edit #10 (October 18th 2008): So…Marco “Saphod” Luthe put up a modded version of the 2.06 version that fixes the future post (and save post) issues. I took the liberty to rename his modded version 2.06 to version 2.07 and I’m officially releasing it here. Thanks again Marco! All you users and readers out there feel free to drop by his site to thank him for the fix…and happy tweeting/twittering….

Edit #11 (November 1st 2008):Corrected tinyurl api url, so that if you’re using tinyurl instead of zz.gd you’re getting the correct short-url…

104 thoughts on “Twitter updater

  1. Hi,

    thanks for the mod, however i’m still getting the same problem.

    All my post are appearing as http://tinyurl/…. While the link is correct it does not seem to show the title of my blog post.

    Any help on this would be great.

    Thanks much!!
    AJ

  2. Sascha: Well, as they offer an api, it would be no problem to rewrite…but as the domain-name extension is >4 I’m not keen on using it…if you want to have that support, just rewrite the code yourself please.

    AJ: Can you give me your twitter-name? Then I can have a look…thank you.

  3. Pingback: Ingoal’s Insight… » Blog Archive » My own twitter source parameter

  4. Loaded the 2.03 update to my WP 2.6 this morning, then posted a new blog entry and got the following error:

    Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home/.alan/jkopp/garagepunk.com/wp-content/plugins/twitter_updater/twitter_updater.php on line 87

    Warning: file_get_contents(http://zz.gd/api-create.php?url=http://www.garagepunk.com/2008/07/23/mystery-action-32/) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/.alan/jkopp/garagepunk.com/wp-content/plugins/twitter_updater/twitter_updater.php on line 87

    Warning: Cannot modify header information – headers already sent by (output started at /home/.alan/jkopp/garagepunk.com/wp-content/plugins/twitter_updater/twitter_updater.php:87) in /home/.alan/jkopp/garagepunk.com/wp-includes/pluggable.php on line 770

    When I checked Twitter, the update was posted but there was no URL. Help?

    Thanks!

  5. Kopper: Well, the first warning says it all url file-access is not compatible with your server…the only way this could work then is if I rewrote the plugin to use curl instead…on another note: did you have the prior version running (with WP 2.5.1) or is this the first install?

    Andy: Good hint…I’ll get to it when I find the time…

  6. The prior version was working fine in WP 2.5.1, no problems at all. Then I upgraded to WP 2.6 and it started double-posting, so then I switched to your update and now I’m getting that error each time and the tweets are posting without URLs, so I have to logon to Twitter manually, DELETE the bad tweet, get the shortened URL from tinyurl.com, and post an update myself. I won’t be doing this for long, I’m afraid, before I just deactivate the plugin entirely.

  7. Another thing I’ve noticed is that if you have an ampersand ( & ) in your post title that the tweet gets cut off right before it. In other words, something like “Get Drunk & Play Records” (the name of one of our podcasts) gets shortened to “Get Drunk ” and nothing after that is included in the update. So you might want to alter this to allow for special characters.

  8. Hi there again kopper and thanks for your feedback. As for your problem

    1.) The error: that doesn’t make sense, there was nothing altered in or around the line that is quoted in the error message, which leads me to believe that the server configuration has been altered (knowingly or due to an update or something)…this error is thrown because the parameter “allow-url-fopen” is off in the php settings…so the only alternative would be to use another way to get to the shortened url (e.g. via curl)…I would have to write an alternative version for this…

    2.) The escaping of characters…jeez…why can’t ppl just have normal titles ;) …but seriously, I’m on it…new release coming soon…

    3.) “I won’t be doing this for long, I’m afraid, before I just deactivate the plugin entirely.” – Well…too bad…this isn’t one of my main projects, so I’ll get to it, when I get to it…if that’s not fast enough (usually under a week from report to fix)…then I can’t help it…it’s not like you payed for this or something ;)

  9. Pingback: Twitter updater fixed | SaigonNezumi.com

  10. Thanks for the update. It resolved my double posting headache.

    Can I remove ZZ.GD from the plugin update? I prefer to use my domain.

    Thanks again for a great fix.

  11. Hi there Kevin…no doubt…you can edit as you please, it’s a free web…although we like if “our” solution is used ;)

  12. Love this plugin, have you considered listing it in WordPress’ plugin directory so users are automatically notified of updates in the WP Admin panel? :)

  13. Microkid: Thanks :)

    Nicki: Good idea…I shall do that soonish…

  14. Pingback: Cómo actualizar a Wordpress 2.6 en Rafael Monge y otros males

  15. I’m getting the same error as kopper posted above (except line 87 is line 100 in my case) using 2.0.4 with WP 2.6. I had “Link title to blog” checked, which produced this:

    Published RouteBuddy To Go for your iPhone ( ) on bioneural.net

    I assume the “()” is where the link should be?

  16. Hi Bruce,

    yeah, that’s where the short-url should be…could you check the parameter in your php server config please (as commented above – “allow-url-fopen” )…chances are that this parameter is off…and that’s causing the error.

    There are basically two ways to “fix” this…

    1.) turn the option on…
    2.) get another version of the plugin which uses another method to get the shorturl (e.g. curl) – this would require me to rewrite the plugin to use curl…(implying that curl is available on your server)…

    I’m def thinking about doing it…maybe with an option in the admin-panel to switch between the methods (depending on your server config, if “standard” works – fine, if not – switch to alternative version)…this way there would be no seperate branches…hmm…stay tuned…

  17. (Ding! Lightbulb comes on) Ah yes Ingoal, that makes sense. Back in ’06 I was trying to get an old plugin working and my then host Dreamhost told me:

    We’ve purposely disabled URL access to php system functions (such as copy() open() etc.) because of security and performance problems. We have replaced it with cURL

    I’m now with (mt) who take the same approach. So your “Might not work on some hosts!” is more like “Will not work on most hosts!”.

    Although I could edit php.ini to enable ‘allow_url_fopen’ I don’t want to open my server to code injection attacks. The (mt) article mentions $_SERVER[‘DOCUMENT_ROOT’] as a possible alternative to allow_url_fopen (aside from cURL); is this something worth looking into (my PHP is rudimentary I’m afraid)?

    Meantime I’m wondering if simply unchecking “Link title to blog” will allow me to continue using this version (without the PHP warnings) to send linkless updates. Guess I’ll have to blog something to find out ;-)

  18. Bruce: Either that or you update to the new version (v2.05) which I just hacked…make sure you visit the twitter updater manage page and check the alternative short url retrieval box…that way it’ll use curl instead of fopen to retrieve the shorturl…hopefully that will solve your problem (and anyone else’s for that matter)… :)

  19. Great; the cURL option in 2.05 embeds the ZZ.GD URL without throwing errors when fopen is disabled. Pat yourself on the back Ingoal :)

  20. Good to see that it works fine :)

    Now off to fix the comment error here on ingoal.info…sigh ;)

    Edit: Done, it was an out of date plugin (namely Sitemap Generator)…so the comment issue is fixed now :)

  21. Great plug-in. I tried a couple of these, and yours is the best. One of the others conflicts with one of the other scripts in my theme.

    How hard would it be to incorporate the Category into the tweet? I would like for mine to say “Charles posted to design: Name of Post Here”.

    I wish I knew php…. Let me know!

  22. Hi there Charles…and thanks, I’m glad that you like the plugin. As for the category: well, it wouldn’t be that hard I guess – just another parameter – BUT that being said, it’s going to be trickier when there is more than one category associated with the post…in that case a construct of “Custom text Category Post-title shorturl” will certainly be too long for the 140 characters…so I’m unsure if that’s really a good option…

    I think I should start a request-list to see what ppl would love to see and then I can see for myself if and when I’m going to implement those requests…

  23. Hi there,
    great job.
    My problem with double tweeting is solved.
    But I have another question.
    In my website ( http://www.parsnewz.com/blog ) I use three languages and for Tweeter it makes sense to update only English posts.
    Have you any idea how to switch other posts off to be updated automatically, maybe something like IF statement in php code?
    Thanks.

  24. Hi there and thanks. As for the switching off non-english updates…hmm…I’ll have to think about that…

  25. Ingoal, nice plugin idea you have here. I’v installed it and i’m having a few problems with it. I’m using WordPress 2.6 and version 2.06 of your plugin.

    Basically it is not posting to twitter everytime i make a blog post, i dont make my blog post go live as soon as i’ve written it, it goes live at a later date, could this be the problem?

    Also when i save my twitter username and password, is it normal for the password field to be blank once saved?

    Many thanks, David.

  26. Hi David. Well, it should handle scheduled posts just fine (although I didn’t do any extended testing since version v2.04)…are you sure the tweet isn’t fired once the scheduled post appears?

    As for the twitter login details: hmm, not really, it should display the password as a line of black dots…

    Sidenote: could you please write a test-post (that appears immediately) and check if the tweet is posted…if that’s not the case this issue is unrelated to scheduled posting and may show “problems” with the plugin install…

  27. Hi Ingoal. Many thanks for your reply. It’s for my Playstation blog over at TalkPlayStation.com. I’ll do a test now.

  28. Ok, i’ve done an extensive test and it seems to be a problem with the plugin saving my password. I went into the code in twitter_updater_manage.php and manually input my password into the value=”” field, but for security reason i cannot allow this.

    http://twitter.com/talkplaystation

    Is there anything you can do? Thanks, David.

  29. Sorry about all the comments. I’ve fixed my problem by adding update_option(‘twitterpw’, $_POST[‘twitterpw’]); to twitter_updater_manage.php.

    Around line 31-32. This has now fixed the problem and is working for me.

    Thanks again.

  30. No problem…

    Hmmm, weird, you’re the first to report this problem…worked so far on all my blogs and it seems on the others’ blogs as well…hmmm…

    Side note: So you replaced the “encrypted” with this “cleartext” one, right? Hmm, so maybe there’s a problem with the base_64 encoding on your server…who knows, tough to say…but as long as this solution works for you, it’s fine with me :)

  31. Ingoal, thats exactly what i did and then i called the php in the value=””.

    The plugin is working fine now apart from one thing is that when i schedule a post to go live at a later date it posts it to twitter when i click publish instead of posting it at the future date.

    Thanks, David.

  32. Okay, that’ll have to go on the “it’s not a bug, it’s a feature”-list for the moment ;)

  33. Hi again,
    I’ve posted above because of preventing non-english updates.
    Can I Update only a certain category?
    Can I put a code something like
    “if((publish)&&(in_category(3))){ twit(); } ” ?
    P.s. it is just a thinking.
    Thanks

  34. Well, not a bad idea and something along those lines might work…although nowadays the category id must be retrieved from the terms/term_taxonomy/term_relationships tables…so the function would have to be a little more sophisticated in the background than you might think….unless there is a standard-function for that (which I didn’t check yet), I’ll have a look an let you know…but it could take a while…

    Edit: *lol* now I see that the function you’ve mentioned really is a standard function of wordpress…my bad…so if you’ve got the category id, this should work….can you edit it on your own or do you need help?

  35. Hi,
    Thanks for reply so soon.
    Well I need help cause I don’t know where to put the code.
    I tried to change the line 103 in twitter_updater.php
    to:
    “if($_POST[‘publish’] == ‘Publish’ ) && (in_category(10){” .
    But it did’nt work.

  36. I’ll have a look tomorrow…my first question is though: are you sure that category 10 is the right one (where did you get that info? from the db)….

  37. Hi,
    “in_category(any_number)” is made by WordPress and in my case number 10 ist Headlines( my Category at my news Website).
    Categories begin by 0 and goes on. It depens on how many Categories you have.
    I would like to update all News wich I make as in category Headlines to twitter.
    I hope I could make me understanding.

  38. *lol* I know how categories are used in wordpress…I was just wondering where you had that information from (probably the admin-panel -> manage categories, right?)…

    Anyway…I think the thing is that in_category works only for posts that already have a category assigned (e.g. that are already saved)…so I’m not totally sure if that function will really help in the process. What you could try though is saving the post before publishing it…let’s see if that makes any difference, if not I’ll have to dig around a little, which I won’t have time for today…

  39. Pingback: Twitter Updater for Wordpress

  40. Hi there Marco…hope you enjoy the plugin…

    As for the scheduled post thing – I’m on to it, but I didn’t have the time to really work on the plugin the last few days/weeks…just watch this spot…

  41. Hey there, I installed the plugin today and replaced “save_post” with “publish_post” and it seems to work well so far. Nice.

    The only problem is that a ” in the title is shown as \” which has to do with masking those special characters before they are written to the database, I guess. I think the title string needs a “stripslash” before sending it to Twitter. But as I am not a pro and do not know enough about the plugin, I’ll leave this to the pros and hope there’ll be an update soon. :-)

  42. Hey: and why not implement several URL-shortening-services and let the user decide which one to take, like zz.gd, rurl.org, tinyurl.com etc.

    Just an idea… :-)

  43. Yeah I heard that one before and it’ll be in one of the future releases…side note: for now it’ll be zz.gd though, which is not only one of the shortest ones but obviously one of my own sites, so I like the push in traffic…no secret there ;)

  44. > which is not only one of the shortest ones but
    > obviously one of my own sites, so I like the
    > push in traffic…no secret there

    yeah, understandable :-)

    well, and if it works as well: why not.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.