upskill-event-manager/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/includes/class-hvac-logger.php
bengizmo 0e8b0f0325 feat: Add Zoho CRM integration with staging mode protection
- Implement OAuth 2.0 authentication for Zoho CRM
- Add sync functionality for Events → Campaigns, Users → Contacts, Orders → Invoices
- Create staging mode that prevents production syncs from non-production domains
- Build admin interface for sync management
- Add comprehensive field mapping between WordPress and Zoho
- Include test scripts and documentation
- Ensure production sync only on upskillhvac.com domain
2025-05-19 13:17:44 -03:00

156 lines
No EOL
3.2 KiB
PHP

<?php
/**
* HVAC Community Events Logger
*
* Centralized logging system for the plugin
*
* @package HVAC_Community_Events
* @subpackage Includes
* @since 1.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class HVAC_Logger
*
* Handles all debug logging for the plugin
*/
class HVAC_Logger {
/**
* Whether logging is enabled
*
* @var bool
*/
private static $enabled = null;
/**
* Log prefix for all messages
*
* @var string
*/
private static $prefix = '[HVAC CE]';
/**
* Initialize the logger
*
* @return void
*/
public static function init() {
if ( null === self::$enabled ) {
self::$enabled = self::is_logging_enabled();
}
}
/**
* Check if logging is enabled
*
* @return bool
*/
private static function is_logging_enabled() {
// Check for WP_DEBUG constant
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
return true;
}
// Check for plugin-specific debug option
$plugin_debug = get_option( 'hvac_ce_debug_mode', false );
// Check for query parameter (for temporary debugging)
if ( isset( $_GET['hvac_debug'] ) && wp_verify_nonce( $_GET['hvac_debug'], 'hvac_debug_nonce' ) ) {
return true;
}
return (bool) $plugin_debug;
}
/**
* Log a debug message
*
* @param string $message The message to log
* @param string $context Optional context/category
* @param array $data Optional data to include
* @return void
*/
public static function log( $message, $context = '', $data = array() ) {
self::init();
if ( ! self::$enabled ) {
return;
}
$log_message = self::$prefix;
if ( ! empty( $context ) ) {
$log_message .= " [{$context}]";
}
$log_message .= " {$message}";
if ( ! empty( $data ) ) {
$log_message .= ' | Data: ' . print_r( $data, true );
}
// Use WordPress error_log function
error_log( $log_message );
}
/**
* Log an error
*
* @param string $message The error message
* @param string $context Optional context
* @param array $data Optional error data
* @return void
*/
public static function error( $message, $context = '', $data = array() ) {
self::log( "[ERROR] {$message}", $context, $data );
}
/**
* Log a warning
*
* @param string $message The warning message
* @param string $context Optional context
* @param array $data Optional warning data
* @return void
*/
public static function warning( $message, $context = '', $data = array() ) {
self::log( "[WARNING] {$message}", $context, $data );
}
/**
* Log an info message
*
* @param string $message The info message
* @param string $context Optional context
* @param array $data Optional data
* @return void
*/
public static function info( $message, $context = '', $data = array() ) {
self::log( "[INFO] {$message}", $context, $data );
}
/**
* Enable or disable logging
*
* @param bool $enabled Whether to enable logging
* @return void
*/
public static function set_enabled( $enabled ) {
self::$enabled = (bool) $enabled;
update_option( 'hvac_ce_debug_mode', self::$enabled );
}
/**
* Get a debug nonce for temporary debugging
*
* @return string
*/
public static function get_debug_nonce() {
return wp_create_nonce( 'hvac_debug_nonce' );
}
}