feature: Initial functional push

This commit is contained in:
Keith Solomon
2025-12-14 16:58:52 -06:00
parent 15445ad40e
commit 189b32ccff
14 changed files with 3365 additions and 0 deletions

64
includes/class-log.php Normal file
View File

@@ -0,0 +1,64 @@
<?php
namespace SiteSync;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class Log
*
* Handles logging for the Site Sync plugin, including info, warning, and error levels.
*/
class Log {
/**
* Logs an informational message.
*
* @param string $message The log message.
* @param array $context Additional context for the log entry.
*/
public static function info( string $message, array $context = array() ): void {
Logger::log( 'INFO', $message, $context );
self::write( 'INFO', $message, $context );
}
/**
* Logs a warning message.
*
* @param string $message The log message.
* @param array $context Additional context for the log entry.
*/
public static function warning( string $message, array $context = array() ): void {
Logger::log( 'WARN', $message, $context );
self::write( 'WARN', $message, $context );
}
/**
* Logs an error message.
*
* @param string $message The log message.
* @param array $context Additional context for the log entry.
*/
public static function error( string $message, array $context = array() ): void {
Logger::log( 'ERROR', $message, $context );
self::write( 'ERROR', $message, $context );
}
/**
* Writes a log entry to the error log and triggers the 'site_sync/log' action.
*
* @param string $level The log level (e.g., INFO, WARN, ERROR).
* @param string $message The log message.
* @param array $context Additional context for the log entry.
*/
private static function write( string $level, string $message, array $context ): void {
$contextStr = $context ? ' ' . wp_json_encode( $context ) : '';
error_log( sprintf( '[Site Sync][%s] %s%s', $level, $message, $contextStr ) ); // phpcs:ignore
/**
* Allow other listeners to capture logs (e.g., to DB table or UI).
*/
do_action( 'site_sync/log', $level, $message, $context );
}
}