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 ); } }