Server IP : 10.106.20.8  /  Your IP : 216.73.216.148
Web Server : Apache
System : Linux webm008.cluster106.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64
User : sixiemesrc ( 611999)
PHP Version : 8.0.30
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/sixiemesrc/new/wp-content/plugins/complianz-gdpr/websitescan/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/sixiemesrc/new/wp-content/plugins/complianz-gdpr/websitescan/class-wsc-logger.php
<?php

defined('ABSPATH') or die();

if (!class_exists("cmplz_wsc_logger")) {

	class cmplz_wsc_logger
	{
		public function init_hooks()
		{
			add_action( 'cmplz_every_month_hook', array( $this, 'clear_errors_log') );
		}

		/**
		 * Logs an error related to a specific $context and stores it in a WordPress option.
		 *
		 * @param string $context The $context name or identifier related to the error.
		 * @param string $error_message The error message to log.
		 */
		public static function log_errors(string $context, string $error_message = ''): void
		{
			// If WP_DEBUG is enabled, log the error to the error log
			if (defined('WP_DEBUG') && WP_DEBUG) {
				error_log("COMPLIANZ: error in context '$context': " . $error_message);
			}

			// Get existing errors from the options table
			$errors = get_option('cmplz_wsc_logs', array());

			$sanitized_context = sanitize_text_field($context);
			$sanitized_error_message = sanitize_text_field($error_message);
			$sanitized_timestamp = current_time('mysql');

			// Append the new error
			$errors[] = array(
				'context' => $sanitized_context,
				'error_message' => $sanitized_error_message,
				'timestamp' => $sanitized_timestamp
			);
			$sanitized_errors = array_map( function( $error ) {
				return array(
					'context' => sanitize_text_field( $error['context'] ),
					'error_message' => sanitize_text_field( $error['error_message'] ),
					'timestamp' => sanitize_text_field( $error['timestamp'] ),
				);
			}, $errors );

			// Update the option with the new error log
			update_option('cmplz_wsc_logs', $sanitized_errors, false);
		}

		/**
		 * Retrieves all logged errors from the WordPress options.
		 *
		 * @return array The array of logged errors.
		 */
		public function get_errors_log(): array
		{
			// Retrieve the errors stored in the WordPress option
			return get_option('cmplz_wsc_logs', array());
		}

		/**
		 * Clears all logged errors from the WordPress options.
		 */
		public function clear_errors_log(): void
		{
			// Delete the option to clear all stored errors
			delete_option('cmplz_wsc_logs');
		}
	}
}