Debugging – Logging WordPress installations

This is the lede paragraph for the blog post. It should be populated with dynamic data from a WYSIWYG custom field assigned to your posts.

Written by

santy

Published on

BlogUncategorized

Contents

In WordPress, however, the DEBUG configuration constants are used to find errors, which, admittedly, is one of the most important steps, but it still doesn’t fix the problem.

Therefore, this tip is actually better achieved via the error output or the “logging”.

It should be noted that some hosting providers and systems that specialize in WordPress have already integrated these settings into their hosting backend. However, in most cases you have to follow the procedure described here. In WordPress, there are 5 constants that can be used to set the logging behavior.

Constants are written in capital letters in the PHP programming language, in which WordPress was written, and are set as follows:

define( ‘CONSTANT_NAME’, ‘constant_value’ );

This definition of the constants is written in the file wp-config.php. This is located directly in the main directory of the installation, so to speak next to the index.php. Each constant may only be defined once. So you have to delete or overwrite existing definitions.

WP_DEBUG

WP_DEBUG generally turns debugging on (true = true) or off (false = false). On public WordPress sites, this should always be off if possible.

// The following code activates debugging

define( ‘WP_DEBUG’, true );

// The following code activates writing to the default file

define( ‘WP_DEBUG_LOG’, true );

// The following code activates writing to a file under the specified path

define( ‘WP_DEBUG_LOG’, ‘/logs/wp-log.log’ );

WP_DEBUG_DISPLAY

WP_DEBUG_DISPLAY decides whether an error that occurs (with the triggering file and line) is displayed on the user’s screen (true) or not (false).

// The following code activates the exact display of the error on the screen

define( ‘WP_DEBUG_DISPLAY’, true );

SCRIPT_DEBUG

When SCRIPT_DEBUG is activated (true), WordPress outputs all CSS and Javascript files in uncompressed form to better analyze errors here. This only applies to files from the “core” system, not from themes or plugins. In general, this function is rarely used because it requires more in-depth knowledge.

// The following code activates the uncompressed output of WordPress asset files

define( ‘SCRIPT_DEBUG’, true );

SAVEQUERIES

To debug database queries, SAVEQUERIES must be activated (true). When this happens, a record is provided for each query, which in turn can be output or logged. SAVEQUERIES will become the content of a separate tip.

// The following code provides further data for each database query

define( ‘SAVEQUERIES’, true );

PHP errors, warnings and notices

Sometimes it is necessary to activate the output of PHP itself, because the output of WordPress is not sufficient or does not appear. Here, a distinction is made in descending order of priority between errors, warnings and notices. Unfortunately, the way these are activated differs somewhat from hoster to hoster. However, the following code, also inserted at the beginning of wp-config.php, usually gets you there:

// Shows all PHP errors, warnings and notices

ini_set(‘display_errors’, 1);

ini_set(‘display_startup_errors’, 1);

error_reporting(E_ALL);