Your Second Life online status on a WordPress widget, take three [UPDATED AGAIN]

I’ve been postponing this literally for… years. On the very first weeks after I started blogging about Second Life, I wanted people to look at my blog and see if I was online in SL or not. It would be a very simple way to promote the cool way that Second Life allowed us to interact with external sites. Back then, we just had XML/RPC, and you had to email the XML/RPC channel that SL had generated for your object, and save the channel ID to disk. Complicated! Specially because when the sim rebooted I’d get a new channel ID by email and had to remember to manually update the blog.

But this was a really simple thingy, which I had hardcoded on my former blog software. Then I switched to WordPress. This meant a few more tweaks, but it was manageable. After a few years, Linden Lab introduced HTTPRequest, which at least allowed us to contact a web server from in-world; this made the code simpler, because it could be fully automated. My previous version was available on this article.

Still, this was rather stupid. You had to hack your theme (the original code predated WordPress widgets) or use something like Samsarin PHP to embed some PHP on a widget — which is nice, but, well, not for the casual blogger. No, what needed to be done was a plugin for WordPress.

I’m ashamed to admit that I have postponed learning how to do WordPress widgets for ages… every time I learned a bit of the arcane art of writing WordPress plugins, the code changed ever so slightly, and I quickly tired of hunting from an up-to-date tutorial. In any case, nobody used the online status thingy anyway, or close to nobody, so I really didn’t care much… it was more about an exercise in plugin writing than anything else.

Well, today I answered to some messages on my old 2007 article; and I thought, I shouldn’t be postponing this any longer. So, well, here it is — my first ever working plugin, in Very Early Pre-Alpha Release 🙂

[UPDATE] You can download the plugin from Online Status inSL WordPress Plugin or simply search for the plugin on the WP admin page under Plugins > Add New.

[UPDATED AGAIN] Version 1.0 is out! It replaces XML-RPC with the more performance-conscious HTTP-in (less bottlenecks). Instead of writing the permanent URL for the in-world object on an external file (which can be messy) it uses the WordPress built-in “options” mechanism. This will hit the database, so to prevent massive hits, it just updates the status every minute or so (in-world, the script also caches the results so that the sim isn’t affected much). Oliver Szondi suggested allowing multiple avatars and multiple widgets, so this is also possible under 1.0 (I’ve tested it and found a few minor bugs, but it sort of works!). You can also style the output, since the widget now emits div’s and span’s to make it easier to change the CSS.

Sadly, this also means that you will have to replace all your in-world scripts 🙁 I believe that I won’t need to change them in future versions, though. So, if you have installed 0.9 or 0.9.1, your blog should now get the latest version automatically, thus immediately breaking all your status reports. Sorry about that! I’m afraid it was unavoidable, and I’m happier by knowing that 1.X will have far less impact on LL’s infrastructure.

And you get the (updated) installation instructions here.

[MORE UPDATES!] Thanks to Puitia, who found a lot of nasty bugs, and most specially Celebrity Trollop, version 1.3.0 is a complete redesign (again!) of the communications protocol. Now, instead of having each widget individually calling the in-world objects as before (which, as Puitia pointed out, made the page very slow to load), Celebrity suggested to let the in-world object just post a status update to the blog whenever necessary. Most of the time, after all, you’re either online or offline, and only when there is a change a new request to update the status is sent (and this is done in the background, without any effect on the page loading). This means that the widget will be much less time on the “status unknown” configuration; communications are kept to a minimum but are actually faster at picking up online status changes; widgets can be more efficiently cached; and, as a side effect, I fixed a bug with the shortcodes, which would not work if there was no widget displayed on the page. Whew! Thanks to the patient testers for so much hard work figuring out strange bugs and proposing new changes. I certainly learned a lot!

Installing

The usual caveats apply… do as many backups as you can, make sure you test it out on a blog which you aren’t afraid to blow up, and so forth 🙂 I just tested it so far on two blog setups, both running from Dreamhost; one has PHP 5.2, the other PHP 5.3; one runs WP 3.0.5, the other 3.1-RC4. It worked on both on the first try, but your mileage might vary, and I’ll be more than delighted to see on your comments if you managed to get it work for you, or, if you found out about a serious bug, please let me know!

For version 1.0, I promise to get rid of XML/RPC and just use two-way HTTP, which is far less laggier. 🙂 (And yes, it’s easy to do — easier, in fact — but I just wanted to start from something that already worked). Done! 🙂

No, I haven’t stopped developing this plugin 🙂 I still have a few ideas on what to do next, and only then I’ll move to the next one. Here are a few, but feel free to comment to suggest more:

  • Fix a serialisation bug which only occurs with multiple widgets for multiple avatars. This has been hard to track since it doesn’t always pop up. Also, a refresh always clears the error. Tricky! Fixed. I was using an obsolete syntax for saving options.
  • Add a new page where you can see what settings have been saved, and delete/refresh them, one by one. Currently, the settings are merely dumped to the admin page, so that you can have an idea which avatars have in-world objects bound to them, and what information has been collected. Fixed. Now there is a whole new panel to deal with this.
  • Add (optional) links to web profiles (easy to do). Done!
  • Get users’ profile picture and add some fancy CSS to allow you to visually show your status on your blog. A picture is usually worth a thousand words! Done! SL Profile Pictures are added to everything: admin panel, widgets, and shortcodes, and are optional.
  • Put a teleport SLURL to the place where the in-world object is. This will allow it to be used, say, on a shop or something. The in-world script might also do the reverse, i. e. allow visitors to touch on the prim and it’ll show the blog. Partially done. SLURLs are, for the moment, just on the admin panel, to allow WP admins to log in and fix the objects easily. Widgets don’t have them yet. For shortcodes this might be impossible or very tricky to do.
  • Put pre-packaged “online status indicators” from SL Marketplace. As the lines of code grow, it starts getting hard for non-technically-minded residents to copy & paste a whole lot of code to an in-world script!
  • Allow people on the blog click on the online status indicator widget and send IMs to the user (easy to do as well, but it might require a bit of fancy JS on the blog — and, of course, a new in-world script). The hardest part will be to deal with abuse; ideally, IMs should only be sent from registered users to prevent spam. Ha! That’s tough! But thanks to Oliver Szondi for the suggestion.
  • Add tags so that you can embed the online status on a post or page. E.g. something like offline would be replaced by, say, Gwyneth Llewelyn is online in Second Life in the text of that page/post. That’s a pretext for me to learn how embedded tags work in WordPress. Thanks to Oliver Szondi for that suggestion! Done! Shortcodes even allow embedding the SL profile picture and have an optional link to the SL Web Profile page.
  • Support OpenSimulator 🙂 I haven’t tried it out, but it should actually work! Thus, if you have the habit of switching grids all the time, since you can now create multiple widgets, people could figure out where you are by looking at your blog, and eventually IM you to the “right” grid. I’ll have to see how well HTTP-in is supported on OpenSim right now, because in theory you might not need to change anything in the code. In theory…!

On the forge:

  • SL Marketplace widget which will present images from your shop on SL Marketplace, if you have them 🙂 Very tricky since LL doesn’t offer any API with webservices for that.

CC BY 4.0 Your Second Life online status on a WordPress widget, take three [UPDATED AGAIN] by Gwyneth Llewelyn is licensed under a Creative Commons Attribution 4.0 International License.

About Gwyneth Llewelyn

I'm just a virtual girl in a virtual world...

One Pingback/Trackback

  • Pingback: Figuring out your online status, revisited | Gwyn's Home()

  • Mayze

    Would it be possible to port this over to Joomla? I’ve been looking high and low and cannot find anything like this 🙁 I just recently switched my blog from wordpress to Joomla and it sucks to have lost this, as i used it on my wordpress config

  • To put it bluntly: no. I utterly despise Joomla in all its incarnations, I have had the worst nightmares in my life doing maintenance work on two clients who were conned into using Joomla (and still suffer daily because of their websites), and I refuse to write a single line of code towards that project, except to bring it to its knees and let people go on with their lives in a better way 🙂

    You’re quite welcome to look at the code (it’s free, it’s open source, no strings attached) and try to port it on your own, though. Good luck!

  • Mayze Draconia

    ah ok, no problem .. kinda makes me want to switch back to wordpress after reading that though, haha.

  • Hehe. It shows how much I hate Joomla, doesn’t it? You know, when I started using it, I thought, “oh well, it’s not so bad as I thought, this might be worth the trouble after all”. The apparent simplicity of the backoffice is misleading, it will backfire, and when it happens… you’re doomed.

    Unless you use Akeeba Backup extensively 🙂

  • Mayze Draconia

    I actually just installed akeeba backup today and I’m running it daily via cron .. but yeah, ill give joomla a trial run and see how it goes. If things go not so well it’s back to wordpress for me. I’ll have a look at the code for the online status widget, although I’m not great at editing code, will see what i can manage lol.

    Thank you for the help 🙂