Development Archives

  1. 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…

  2. 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!

  3. 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…

  4. 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…

  5. 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…

  6. 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…

  7. 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…

  8. 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.

  9. 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…

  10. Ahead of My Time

    This past weekend I’ve been on East Coast time (in North Carolina). This is the third time in the past few months I’ve been on East Coast time for a few days. I kind of like being 2 hours ahead of local time at the office. For one thing, the stream of email is merely…

  11. Above the Fold

    For everyone who believes their entire website has to be “above the fold”, here’s the thing: people know how to scroll a web page. Don’t believe me? Believe Apple.

  12. Advice on Mitigating Piracy

    I received an email asking my advice about how to deal with software piracy when selling downloadable PHP applications. Here is my (slightly edited) response: It boils down to a choice between which is more important: making things easier for paying customers making it harder for people to use without paying Once you decide which…

  13. Using WordPress Transients with External Data

    The transients feature of WordPress is a very useful tool for local data cache when pulling from a remote data source (web service/API). A typical workflow goes something like this: Get remote data. Store it locally as transient data with a timeout. Once the data times out, get remote data again. That’s the basics and…