Simple WordPress plugin debugging
I’d like to present simplest way I know to debug WordPress plugins. It is a method I was using developing plugin to cloak URL‘s described earlier.
Below You can find the most minimalistic example plugin code possible – all it does is log REQUEST_URI to our debug file located at wp-content/plugins/debug. Row by row. Dirty and simple – and the most important – it does not require us to switch our WordPress to debug mode.
Plugin consists of three parts – plugin description header, debugging function and hook to main function which is executed right before page is rendered.
< ?php
/* Plugin Name: test Plugin URI: Description: Version: Author: Author URI: */
?>
< ?php
function debug($msg)
{
$fp = fopen('wp-content/plugins/debug', 'a');
fwrite($fp, $msg."\n");
fclose($fp);
}
function main()
{
debug($_SERVER['REQUEST_URI']);
}
add_action('init', 'main');
?>
Of course the most important part of the code is debug function which stores results we need to verify to our debug file.
