Quick Debugging Trick in WordPress

I always found it a pain when writing new plugins/themes in wordpress to have to turn on or off the WP_DEBUG flag to get errors to show. Plus often times I will be working on a site that others are also viewing or working on, so turning on the flag would disrupt their work. A really simple solution to this problems was to wrap a define statement for the WP_DEBUG flag in an if statement. For example:


if ($_GET['debug'] == 1) {
define("WP_DEBUG", 1);
}
else {
define("WP_DEBUG", 0);
}

The beauty of the code is that you can trigger debugging easily by adding ?debug=1 onto your uri. This saves you from having to change the wp-config.php file, as well as solves the issue of multiple users/developers.

Note this should only be done on a development site. Having this on a live WordPress install could open up your site to be more easily exploiting as you are giving your attackers access to the notifications, warnings and errors.

WordPress Vim Syntax Highlighting

Lately I have been doing a lot more work in WordPress. I primarily code in Vim, and it always bugged me there was no syntax highlighting for WordPress in Vim (or at least that I could find), so I decided to write one. I started off pulling all the functions from this page: http://codex.wordpress.org/Function_Reference. However I found this page to be pretty incomplete, so I continued to add functions to the file as I went along.

I decided to release the file to the public in case anyone is looking for WordPress syntax highlighting. Note, by no means is this file complete, but is a good base. Feel free to contact me to fill in any functions I am missing.

Find it on Github

To install, download and place in your .vim/syntax/ directory. Then load by running in vim:

:set syn=wordpress

Or place something like the following in your .vimrc file:

autocmd BufEnter *.php :set syn=wordpress