Last active
May 27, 2019 12:35
-
-
Save jonathanbossenger/54c7741260f7e2687f00edae60489c74 to your computer and use it in GitHub Desktop.
Simple PHP debug function 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
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