Consolidate the plugin into the TourWebsite repository (its separate nested git repo has been removed). Includes the full new-design reskin: scoped design stylesheet, SVG icon sprite, rebuilt listing/single/section templates, and homepage hero/FAQ/testimonials shortcodes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4hNL1PSHxXbu94SCenpKj
104 lines
2.6 KiB
PHP
104 lines
2.6 KiB
PHP
<?php
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
class VC_Logger {
|
|
const STORE = 'vc_activity_log';
|
|
const MAX = 300;
|
|
|
|
public static function log( $message, $force = false ) {
|
|
if ( ! $force && ! vc_get_option( 'debug_logging', false ) ) {
|
|
return;
|
|
}
|
|
|
|
if ( is_array( $message ) || is_object( $message ) ) {
|
|
$message = wp_json_encode( self::redact( $message ) );
|
|
} else {
|
|
$message = self::redact_string( (string) $message );
|
|
}
|
|
|
|
error_log( '[Viator Collector] ' . $message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
|
|
}
|
|
|
|
/**
|
|
* Record an informational event in the admin activity log.
|
|
*/
|
|
public static function info( $message ) {
|
|
self::record( 'info', $message );
|
|
self::log( $message );
|
|
}
|
|
|
|
/**
|
|
* Record an error event in the admin activity log and the PHP error log.
|
|
*/
|
|
public static function error( $message ) {
|
|
self::record( 'error', $message );
|
|
self::log( $message, true );
|
|
}
|
|
|
|
/**
|
|
* Append an entry to the rolling, in-database activity log shown in admin.
|
|
*/
|
|
public static function record( $level, $message ) {
|
|
if ( is_array( $message ) || is_object( $message ) ) {
|
|
$message = wp_json_encode( self::redact( $message ) );
|
|
} else {
|
|
$message = self::redact_string( (string) $message );
|
|
}
|
|
|
|
$log = get_option( self::STORE, array() );
|
|
if ( ! is_array( $log ) ) {
|
|
$log = array();
|
|
}
|
|
|
|
$log[] = array(
|
|
't' => current_time( 'mysql' ),
|
|
'level' => ( 'error' === $level ? 'error' : 'info' ),
|
|
'msg' => $message,
|
|
);
|
|
|
|
if ( count( $log ) > self::MAX ) {
|
|
$log = array_slice( $log, -self::MAX );
|
|
}
|
|
|
|
update_option( self::STORE, $log, false );
|
|
}
|
|
|
|
/**
|
|
* Recent activity log entries, newest first.
|
|
*/
|
|
public static function get_log() {
|
|
$log = get_option( self::STORE, array() );
|
|
if ( ! is_array( $log ) ) {
|
|
return array();
|
|
}
|
|
return array_reverse( $log );
|
|
}
|
|
|
|
public static function clear_log() {
|
|
delete_option( self::STORE );
|
|
}
|
|
|
|
private static function redact( $value ) {
|
|
if ( is_array( $value ) ) {
|
|
foreach ( $value as $key => $item ) {
|
|
if ( preg_match( '/api.?key|exp-api-key|authorization|token|secret/i', (string) $key ) ) {
|
|
$value[ $key ] = '[redacted]';
|
|
} else {
|
|
$value[ $key ] = self::redact( $item );
|
|
}
|
|
}
|
|
} elseif ( is_string( $value ) ) {
|
|
$value = self::redact_string( $value );
|
|
}
|
|
return $value;
|
|
}
|
|
|
|
private static function redact_string( $value ) {
|
|
$key = vc_get_api_key();
|
|
if ( $key ) {
|
|
$value = str_replace( $key, '[redacted]', $value );
|
|
}
|
|
return preg_replace( '/(exp-api-key|api_key|apiKey|token|secret)\s*[:=]\s*[^,\s]+/i', '$1=[redacted]', $value );
|
|
}
|
|
}
|