Skip to content

Instantly share code, notes, and snippets.

@mintplugins
Created April 11, 2016 21:40
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 mintplugins/eb3819a5f9940decc4f9345f82c829db to your computer and use it in GitHub Desktop.
Save mintplugins/eb3819a5f9940decc4f9345f82c829db to your computer and use it in GitHub Desktop.
Write debugging text to a txt file
function pj_debug_to_txt_file( $debug_value, $filename, $append = true ){
$upload_dir = wp_upload_dir();
$filename = trailingslashit( $upload_dir['basedir'] ) . $filename . '.txt';
if ( false === $append ) {
// Blank out the log file if needed
@file_put_contents( $filename, '' );
@chmod( $filename, 0664 );
}
if ( true === $append ) {
$log_file = fopen( $filename, 'a' );
}
fwrite( $log_file, $debug_value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment