Wednesday, July 28, 2010

Wordpress Shortcodes

Haven't done much work with Wordpress before, but a few of our current contracts have required us to dig in pretty deeply. Wordpress is impressive in how it can hide the guts from the users and authors while letting us get at the back end to tweak and make updates.

One of the features we thought was missing was some way to do simple text replacement for pieces of text or html that repeat in a lot of places. We spent our time Googling for things like wordpress macro, wordpress text replace, auto-complete and others. We found lots of plug-ins but none were really what we wanted or were not certified to work with the versions of Wordpress our clients are using.

Then we stumbled across the proper vocabulary word: shortcode! Wordpress has a whole api and everything. Basically though, a shortcode is just a php function that returns some value when called. Another little function call to add_shortcode placed in the functions.php file is all that is required to set them up.

The best part is that for most Wordpress themes, the functions.php file can be edited from the administrator interface. So, we don't need access to our client's server or ftp. This will make maintenance much easier in the future.

Here is a simple example:
First we have the function we want
function TA_address(){
return '<a href = "http://www.tyreeapps.com">Visit our website for good times</a>';
}

Then just below that in the functions.php file we add our shortcode to Wordpress' master list

add_shortcode('TAwebsite','TA_address');


Now we can enter our new shortcode [TAwebsite] into our Wordpress pages wherever we want to have our website address. We can enter this from the regular blog post or page editor. We don't even have to switch over to the html view. And perhaps the best part of the whole deal...we can change the string that the shortcode returns in one place and it instantly changes across our whole website.

So, if there is a piece of code you need on EVERY page of your site, edit the template file. If there is a piece of code you need at the same place on every page, look at the widgets and menus. If there is a piece of code that you need a lot but not everywhere, then a shortcode might be just the ticket.

It is important to note that if your shortcode is named the same as another shortcode bad things will happen. Best practice is to prepend your shortcodes with some identifier (like "TA" for mine) that is unlikely to be used by other people. The more we use open source stuff, the more we're realizing the importance of getting to the habit of adding an identifier to ALL functions and other broadly scoped objects.
Shortcodes can do much more than just text replacement. Here is a nice list of some more advanced usages.

Quality Control


We know that paying attention to each detail is difficult. Missing a mistake is a downside of the Apple App Store process. This mistake will take the owners about 5 seconds to fix, but will take a recompile, resubmit, update cycle to get deployed....weeks.

It's unfortunate that this is one of the very first images that any new user of the application will see after they download.

When we see things like this, it makes us EVEN MORE paranoid about polishing every last detail of our own applications. There's a fine line between polishing and goldplating though. It's tough not to cross it.

Tuesday, July 27, 2010

Adapting AudioStreamer for TapLynx

Matt Gallagher has made a cool library that does audio streaming. We have adapted his library for use with the TapLynx framework and released it on github. You can get your own copy of the library at github.
The TapLynx framework lets someone with limited programming experience produce professional applications for use in the Apple App store. A TapLynx based application can be controlled by changing settings in a single .plist file. This file can be local to the application or hosted on a remote web server.

The AudioStreamer adaptation is mostly controlled from settings in the NGConfig.plist that controls the rest of a TapLynx application. Modifications to the UI can be made by editing a single .xib file (TAStreamingPlayer.xib).
If the plugin is fed a single mp3 feed it will open a basic player and let the user listen to the stream. Per the design of the underlying AudioStreamer library, the soundfile can be either a continuous stream or of a finite duration.

If the plugin is
fed an array of streams, it will present the user with a picker view so that they can choose among the streams.

Instructions for loading the plugin and installing it within your TapLynx application can be found in the readme that is in the github.com repository. There is also a sample plist file to show how the array of streams needs to be formatted.

This has been a fun project for us and we will post a few of the interesting things we learned while working on it over the next few days. Please enjoy the library and use it in your projects. Tyree Apps would love attribution either on your website or your blog. We are also happy to engage in projects to customize the plugin or to create other custom plugins for hire.