| 1 |
<?php |
| 2 |
/** |
| 3 |
* Function: f12_debug_log |
| 4 |
* Version: 1.0.0 |
| 5 |
* Description: Logs debug messages to the error log if WP_DEBUG is enabled. Optionally includes context data. |
| 6 |
*/ |
| 7 |
if (!function_exists('f12_debug_log')) { |
| 8 |
/** |
| 9 |
* Logs a debug message with optional context. |
| 10 |
* |
| 11 |
* @param string $message The debug message to log. |
| 12 |
* @param array $context Additional context data to include in the log (optional). |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
function f12_debug_log(string $message, array $context = []): void |
| 16 |
{ |
| 17 |
if (!defined('WP_DEBUG') || WP_DEBUG !== true) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
$context_str = !empty($context) ? json_encode($context) : ''; |
| 22 |
$log_entry = sprintf("%s %s\n", $message, $context_str); |
| 23 |
error_log($log_entry); |
| 24 |
} |
| 25 |
} |