Created
February 25, 2022 02:54
-
-
Save itsariful/767617d9bcbff05224e2504a767b67e6 to your computer and use it in GitHub Desktop.
Essential Debug functions for WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Essential Debug functions for WordPress | |
* Place this file in wp-content/mu-plugins | |
* @author itsarifulislam@gmail.com | |
*/ | |
/** | |
* pretty_log | |
* | |
* Log something in debug.log file | |
* | |
* @param $title String Adds a nice title before the log | |
* @param $log Mixed Data to be logged | |
* @param $trace Bool Log the backtrace summary | |
* | |
* @return void | |
*/ | |
function pretty_log( String $title = '', $log = '', $trace = false ) { | |
if ( ! empty($title) ) { | |
error_log( print_r( '======================== ' . $title . ' ========================', 1 ) ); | |
} | |
if ( ! empty($log) ) { | |
error_log( print_r( $log, 1 ) ); | |
} | |
if ( $trace ) { | |
error_log( print_r( '======================== Backtrace History ========================', 1 ) ); | |
error_log( print_r( wp_debug_backtrace_summary( null, 0, false ), 1 ) ); | |
} | |
} | |
/** | |
* pretty_trace | |
* | |
* Log the backtrace summary in debug.log file | |
* | |
* @param $title String Adds a nice title before the log | |
* | |
* @return void | |
*/ | |
function pretty_trace( String $title = '' ) { | |
if ( ! empty($title) ) { | |
error_log( print_r( '======================== ' . $title . ' ========================', 1 ) ); | |
} | |
error_log( print_r( '======================== Backtrace History ========================', 1 ) ); | |
error_log( print_r( wp_debug_backtrace_summary( null, 0, false ), 1 ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment