Created
December 22, 2024 14:20
-
-
Save lunule/d1913cf37bbe4da624b9b9fe558fda77 to your computer and use it in GitHub Desktop.
[WordPress - Log to error.log] #wp #core #error #debug #log
This file contains hidden or 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 | |
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