PluginProbe
PostNL for WooCommerce / 4.0.0
PostNL for WooCommerce v4.0.0
5.9.12 5.9.11 5.9.10 5.9.9 5.9.8 5.9.7 5.9.6 trunk 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 3.1.4 3.1.5 3.1.6 3.1.7 4.0.0 4.0.1 4.0.2 4.3.2 4.3.3 4.4.0 4.4.1 All 72 releases
woo-postnl / includes / class-wcpn-log.php

class-wcpn-log.php in PostNL for WooCommerce 4.0.0, at includes/class-wcpn-log.php

56 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (! defined('ABSPATH')) {
4 exit;
5 } // Exit if accessed directly
6
7 if (class_exists('WCPN_Log')) {
8 return;
9 }
10
11 class WCPN_Log
12 {
13
14 /**
15 * Log data if the error logging setting is enabled.
16 *
17 * @param string ...$messages
18 */
19 public static function add(string ...$messages): void
20 {
21 if (! WCPOST()->setting_collection->isEnabled(WCPOST_Settings::SETTING_ERROR_LOGGING)) {
22 return;
23 }
24
25 $message = implode("\n", $messages);
26
27 // Starting with WooCommerce 2.7, logging can be grouped by context and severity.
28 if (class_exists("WC_Logger") && version_compare(WOOCOMMERCE_VERSION, "2.7", ">=")) {
29 try {
30 (wc_get_logger())->debug($message, ["source" => "wc-postnl"]);
31 } catch (Exception $e) {
32 exit($e);
33 }
34 return;
35 }
36
37 if (class_exists("WC_Logger")) {
38 $wc_logger = function_exists("wc_get_logger") ? wc_get_logger() : new WC_Logger();
39 $wc_logger->add("wc-postnl", $message);
40
41 return;
42 }
43
44 // Old WC versions didn't have a logger
45 // add file in upload folder - wp-content/uploads
46 $upload_dir = wp_upload_dir();
47 $upload_base = trailingslashit($upload_dir["basedir"]);
48 $log_file = $upload_base . "postnl_log.txt";
49 $current_date_time = date("Y-m-d H:i:s");
50 $message = $current_date_time . " " . $message . "n";
51 file_put_contents($log_file, $message, FILE_APPEND);
52
53 return;
54 }
55 }
56