If you are developing this on your local computer, you can create a debug.log
file in your wp-content
folder, and add the following to your wp-config.php
file so that you can write to the file:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false );
I add this function in a plugin to write to the debug.log
file:
function write_log( ...$log_items ) {
if ( true === WP_DEBUG ) {
foreach ( $log_items as $log_item ) {
if ( is_array( $log_item ) || is_object( $log_item ) ) {
error_log( print_r( $log_item, true ) );
} else {
error_log( $log_item );
}
}
}
}
This will let you add calls to write_log
to your code so that you can see what’s going on. For example, in the dcpmp_get_level_for_id
function, you can add:
write_log( 'In the dcpmp_get_level_for_id function, called with the id argument set to: ', $id );
That will let you know if the function is being called, and what argument is being passed to it. Make sure that write_log
calls are removed before you add the code to your live site. It is usually possible to work through code in this way, to figure out where it is going wrong.