Skip to content

Instantly share code, notes, and snippets.

@jonathanbossenger
Last active May 27, 2019 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanbossenger/54c7741260f7e2687f00edae60489c74 to your computer and use it in GitHub Desktop.
Save jonathanbossenger/54c7741260f7e2687f00edae60489c74 to your computer and use it in GitHub Desktop.
Simple PHP debug function for WordPress
function custom_error_log( $message, $data = '' ) {
if ( ! defined( 'DEBUG' ) || ! DEBUG ) {
return;
}
// For plugins
$log = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'log/';
// For themes
// $log = trailingslashit( get_stylesheet_directory() ) . 'log/';
if ( ! is_dir( $log ) ) {
mkdir( $log );
}
$file = $log . date( 'Y-m-d' ) . '.log';
if ( ! is_file( $file ) ) {
file_put_contents( $file, '' );
}
if ( ! empty( $data ) ) {
$message = array( $message => $data );
}
$data_string = print_r( $message, true ) . "\n";
file_put_contents( $file, $data_string, FILE_APPEND );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment