Debugging / Logging
I good way to debug your application is to have a debug service run in the background while coding your WP app. To able to log, make sure you have these two lines in wp-config.php:
define( 'WP_DEBUG', true );
define('WP_DEBUG_LOG', true);
Then go to the /wp-content folder and run command tail -f debug.log
. This will create an empty debug.log This file is git ignored, so it won't be commited. Any warning, errors or log messages will be displayed in the terminal as they happen, as well as written to the debug file.
To log you can call the function write_log($log)
(located in functins.php).
This approach is way better than using echo, die, print_r etc
since you get cleaner debug information in the terminal and also stored to a debug file. It will also show you debug information during the whole cycle of an action, for example after page redirects etc.