Skip to content

Instantly share code, notes, and snippets.

@lunule
Created December 22, 2024 14:20
Show Gist options
  • Save lunule/d1913cf37bbe4da624b9b9fe558fda77 to your computer and use it in GitHub Desktop.
Save lunule/d1913cf37bbe4da624b9b9fe558fda77 to your computer and use it in GitHub Desktop.
[WordPress - Log to error.log] #wp #core #error #debug #log
<?php
if (!function_exists('write_log')) {
function write_log($log) {
if (true === WP_DEBUG) {
if (is_array($log) || is_object($log)) {
error_log(print_r($log, true));
} else {
error_log($log);
}
}
}
}
// Example USAGE
if( !is_wp_error($post_id) ) :
// ...
else :
$error_string = $post_id->get_error_message();
write_log( $error_string );
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment