Development Archives

  1. Modernizr.touch and BlackBerry Browsers

    If you’re using Moderinzr to detect browser support for touch events, be aware that non-touch BlackBerry devices claim to support touch events. As you might expect, the touch events are pretty much impossible to trigger on a non-touch device. I worked around this by making the check for touch vs. non-touch browsers also test for…

  2. Custom Fields vs. Taxonomies

    For years I’ve used custom fields (post meta) in WordPress as a primary storage area for misc. data about specific posts (including pages, custom post types, etc.). Recently, I’ve realized that I should be using custom taxonomies instead of custom fields in a variety of situations. Custom fields are still the right choice for misc.…

  3. Where to Host WordPress Code?

    I talked to a number of developers about at this year’s WordCamp SF about where best to publish WordPress code as a developer. We definitely want to use the SVN repositories on WordPress.org so that released plugins can be easily available to the community, but there is very little developer community there. We’ve also used…

  4. WordPress Filter for Pingbacks

    My team and I have been working on a plugin to enable a better UI for post formats in the WordPress admin (more on this later, but feel free to grab the code and play with it). One of the things we’ve done is standardize on some custom field names for various bits of data…

  5. WordPress GUIDs Must Be URLs

    If you are customizing the GUID value of a post in WordPress, make sure you maintain the format of the GUID as a valid URL format. There are security checks on the value that enforce the URL format. If you pass in a UUID as the GUID value when creating a post, your value will…

  6. Reminder: Post Formats are a Taxonomy

    If you hook in to get_the_terms and try to make a get_post_format() call within your callback without first removing your filter, you’re going to get an infinite loop (perhaps a seg fault). Good times!

  7. Use $content_width to Set Width of oEmbeds in WordPress

    If you want resulting oEmbed code to scale to a specific size (width) in WordPress, you can do this really easily by setting the $content_width global variable before calling your oEmbed processing. Example: global $wp_embed, $content_width; $content_width = ’600′; // set to desired width $string_with_embedded_content = $wp_embed->autoembed($string_with_oembed_url); I only recently ran across this feature (just…

  8. Detecting Lightboxed Pages in WordPress Admin

    When you want inject something into the WordPress admin, you might not think to account for pages that load inside lightboxes (plugin updates, media upload, etc.). Generally, you don’t want to add your JS/CSS/etc. to these pages. To check for this type of page load, you can check for the IFRAME_REQUEST constant. View the code…

  9. WordPress Code Snippet to Detect “Main” Loop

    Cribbed from the WP-Hackers list, the following sample code should give you a good way to test if the current “in the loop” action is within the main loop or a different loop: function main_loop_test($query) { global $wp_the_query; if ($query === $wp_the_query) { echo “main loop”; } } add_action(‘loop_start’, ‘main_loop_test’); Thanks Nacin and Konrad. This…

  10. Passthrough File Download Tip

    At some point you’re going to need to do the following in your web app: Receive a request to download a file. Authenticate the user/validate the request using some information stored in a database. Upon successful authentication/validation, deliver the file to the requestor (but deny access to the general public). This is a pretty standard…

  11. SimpleMath

    I have to do basic arithmetic on a fairly regular basis. My tool of choice for the last few years has been LeanCalc. It does the job well for the most part, but it doesn’t ignore non 0-9 characters, I would commonly use it to calculate a percentage of a dollar value. I’d paste in…

  12. Developer Expectations

    Old developers are wary of frameworks and assume something about them will end up biting them in the end; they are wary of using features they haven’t created. Young developers assume that frameworks and tools work, use them without hesitation, and are surprised when things go wrong. The truth, as usual, rests somewhere in between.

  13. Samsung Galaxy Tab User Agent

    If you’re trying to sniff the Samsung Galaxy Tab, here is the current User Agent string1: Mozilla/5.0 (Linux; U; Android 2.2; en-us; SCH-I800 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 It looks like SCH-I800 may be the best thing to look for. Would it have killed them to add “Android Tablet (7 inch)” in…