If you are developing a plugin on WordPress, you will need to debug your code as you go.
To enable debugging, go to your wp-config.php file.
Find the line…
define('WP_DEBUG', false);
Replace the line above with the following…
// Turns WordPress debugging on define('WP_DEBUG', true); // Tells WordPress to log everything to the /wp-content/debug.log file define('WP_DEBUG_LOG', true); // Doesn't force the PHP 'display_errors' variable to be on define('WP_DEBUG_DISPLAY', false); // Hides errors from being displayed on-screen @ini_set('display_errors', 0);
Now you all warnings and errors will show up in the /wp-content/debug.log file, including WordPress warnings of deprecated functions.
You can write directly to this log from your plugin using the error_log()
function.
Typically…
//output some debug string error_log( 'this works yo' ); //output some array/object error_log( print_r( $some_obj_or_array, 1 ) );
Kudos to this post. It has some good plugin development tips, including how to enable debugging on WordPress.
Filed under: Code, Guides Tagged: debugging techniques, php, plugin, wordpress
