WC_Log_Handler_File::delete_logs_before_timestamp()public staticWC 3.4.0

Delete all logs older than a defined timestamp.

Method of the class: WC_Log_Handler_File{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = WC_Log_Handler_File::delete_logs_before_timestamp( $timestamp );
$timestamp(int)
Timestamp to delete logs before.

Changelog

Since 3.4.0 Introduced.

WC_Log_Handler_File::delete_logs_before_timestamp() code WC 9.2.3

public static function delete_logs_before_timestamp( $timestamp = 0 ) {
	if ( ! $timestamp ) {
		return;
	}

	$log_files     = self::get_log_files();
	$log_directory = LoggingUtil::get_log_directory();

	foreach ( $log_files as $log_file ) {
		$last_modified = filemtime( trailingslashit( $log_directory ) . $log_file );

		if ( $last_modified < $timestamp ) {
			@unlink( trailingslashit( $log_directory ) . $log_file ); // @codingStandardsIgnoreLine.
		}
	}
}