Monthly Archives: November 2010

WordPress – Easy debug mode

When things go wrong, you can always use the super useful WordPress debug tool, WP_DEBUG.

By default, you have to paste a line of code in your wp-config.php to make the debug mode available.

By if you need to easily access the debug mode even when your site is live, you should edit your wp-config.php file and replace

define('WP_DEBUG', true);

by:

if ( isset($_GET['debug']) && $_GET['debug'] == 'debug')
  define('WP_DEBUG', true);

Once done, simply add a GET parameter to the url of the page you’d like to debug, as shown below:

http://www.whileifblog.com/about?debug=debug

Of course, for obvious security reasons you should replace the name debug by a random word of your choice so no one will ever see your site in debug mode.

PHP – Use Ternary Operators

The benefit of the ternary operator is debatable (there’s only one, by the way). Here is a line of code from an audit we performed recently:

<?php

	$host = strlen($host) > 0 ? $host : htmlentities($host);

?>

The ternary operator may be fine for one-liners, prototypes, and templates, but we strongly believe that an ordinary conditional statement is almost always better. PHP is descriptive and verbose. We think code should be, too.

Jquery – Shorthand for the ready event

A small tip this one but you can save a few characters by using shorthand for the $(document).ready function.

Instead of this…

$(document).ready(function (){
  // your code
});

You can do this…

$(function (){
   // your code
});