Skip to content

Instantly share code, notes, and snippets.

@tresorama
Last active May 14, 2024 12:07
Show Gist options
  • Save tresorama/b4bb295e6340d6346650586ade8cefe9 to your computer and use it in GitHub Desktop.
Save tresorama/b4bb295e6340d6346650586ade8cefe9 to your computer and use it in GitHub Desktop.
Wordpress snippets

Test WP_DEBUG

First enable debug. Then test that notice/warning/error are written to log file correctly.

Enable Debug

// in wp-config.php

define("WP_DEBUG", true);
define("WP_DEBUG_LOG", true); // write to log file (wp-content/error.log)
define("WP_DEBUG_DISPLAY", false)// write on HTML response when error occur

Test it

Add this code and comment/uncomment accordingly, then reload a wordpress page and check te log file.

// in wp-content/themes/xxx/functions.php

// Test WP Debug
// Uncomment to test PHP Notice
echo $unknown_variable;
// Uncomment to test PHP Warning
include ("unknown_external_file.php");
// Uncomment to test PHP Error
unknown_function();

Resources

https://phoenixnap.com/kb/php-error-types#:~:text=Warning%20errors%20in%20PHP%20are,Using%20deprecated%20functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment