Heart Web

WordPress Debugging

In this article

A collection of tools for debugging issues in WP code

Enable logging – the log file

For a remote site, the log file is the easiest way to get info out of a running system.  Generally you don’t want to leave logging on for a live system as it can slow things down.

See this article for an introduction to using the WP log file and the write_log() helper function.

Once enabled, you will usually find trhe debug log under:

/public_html/wp-content/debug.log

If you use Woocommerce, it’s debug output can be found under:

/public_html/wp-content/uploads/wc-logs

Change the default log location

The default log location in /wp-content is publicly readable, so anyone can go to your site and download your log file.  Log files can contain sensative information, so you probably don’t want just anyone accessing them.

We are going to change the default log location to /public_html/wp-admin/logs/.

1/ create the new directory ‘logs’ and change it’s permissions to remove public/world access.

2/ go back to wp-config.php and update this lines to include the new location.  The directory must exist and be specified from the hosting root.

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG','{hosting_root}/public_html/wp-admin/logs/debug.log' );

Replace {hosting_root} with your directory root.

3/ generate a log entry and make sure the log file is created where specified.

If the log file is not created then check the host root and also check other permisions.

4/ Finally test that you cannot access the new log file.

In your browser go to:  https://{your site url}/wp-admin/logs/debug.log

See https://wordpress.stackexchange.com/a/337878 for more info.

 

XDebug : Find the source of WP deprecated warnings

XDebug will add a stack trace to the log file for any warnings, errors etc.  See this SO answer for more details.

  • Enable logging on your WP installation.
  • Via cPanel, find the PHP entry and enable the xdebug module.
  • perform the action that generates the log message, then go back and turn off xdebug.
  • Vied the full stack trace in the Log file and see where the Deprecated message originates.

Which template am I looking at?

‘Show Current Template’ adds a menu item showing the templates that are called for the current page.

Show Current Template

Grep for a hook in source code

If you can get a terminal on to your host, you can use grep to search for hooks and function definitions and calls in the source code.

From the plugins folder, this will recursively search all directories and files for files containing the specified text.

grep -r 'wcs_view_subscription_actions'  .

Grep for plugin action and filter definitions

grep -r 'do_action'  .
grep -r 'apply_filter'  .

User Switching

Sometimes you need to see what a user is seeing to find the issue.  This plug allows you to switch your WP user on the fly and see the site how that user would see it.

User Switching

Finding issues caused by a plugin

Sometimes you need to isolate a plugin that is causing issues.  When reporting a issue to a supplier, often the standard response from support staff is to revert to a base theme and then disable all your plugins and then come back to us!  This plugin can help switch theme and disable specific plugins for the whole site or just for admin

WP Safe Mode