WordPress comes with it's own debugging system that is using constants, making it easy to turn on/off when you are switching environments. All constants are defined in the wp-config.php
file.
define( 'WP_DEBUG', true )
Setting WP_DEBUG to true will cause all PHP errors, warnings and notices to be displayed on the screen. Also, it will throw notices about deprecated functions and arguments.
define( 'WP_DEBUG_LOG', true )
Enabling WP_DEBUG_LOG will save all errors in a file( debug.log
located in /wp-content/). It is useful when debugging AJAX events.
define( 'WP_DEBUG_DISPLAY', true )
As an addition to the previous two constants, WP_DEBUG_DISPLAY can be used to control whether or not we want to print the errors on the page.
define( 'SAVEQUERIES', true )
When SAVEQUERIES is defined as true, every query that is executed will be saved. Also there are information about how long a query took to execute and what function called it. All information is stored in $wpdb->queries
.
Also there is a SCRIPT_DEBUG constant define( 'SCRIPT_DEBUG', true)
which forces the WordPress to use the development versions of the core CSS and JS files, instead of the minified versions.
Using Visual Studio (you will need PHP Tools)/PHPStorm/Eclipse, you can do debugging with Xdebug. If you are using XAMPP/MAMP, it already has Xdebug installed, so you will just need to configure it.
Locate php.ini
and add these two lines:
zend_extension="/absolute/path/to/xdebug.so"
xdebug.remote_enable = 1
There are other options that can be configured abd you can read about them in the xdebug documentation. Once you finish with editing the php.ini
file, restart your Apache server.
The next step is to set the PHP Debugger settings in your editor. Navigate to the Settings/Preferences dialog and locate the PHP Settings.
Once you are done with that, you can start setting breakpoints.