PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 All 211 releases
charitable / includes / class-charitable-log-muter.php

class-charitable-log-muter.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13, at includes/class-charitable-log-muter.php

103 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Log Muter
4 *
5 * This class provides a simple way to mute specific error logs that clutter the error log.
6 * To enable/disable muting, simply change the MUTE_LOGS constant to true/false.
7 *
8 * Muted logs:
9 * - CHARITABLE: NEW VENDOR CALL (THROWN/RECEIVED)
10 * - Charitable Progress Bar Debug
11 * - Charitable Admin Splash
12 * - [Charitable Square] logs
13 * - Square Legacy Mode logs
14 * - NPS Survey logs
15 * - Admin notices saving logs
16 *
17 * @package Charitable
18 * @since 1.8.8
19 */
20
21 // Prevent direct access
22 if ( ! defined( 'ABSPATH' ) ) {
23 exit;
24 }
25
26 class Charitable_Log_Muter {
27
28 /**
29 * Whether to mute the specified logs
30 *
31 * Set to true to mute logs, false to show them
32 *
33 * @var boolean
34 */
35 const MUTE_LOGS = true;
36
37 /**
38 * Patterns to mute (case-insensitive)
39 *
40 * @var array
41 */
42 private static $mute_patterns = array(
43 'CHARITABLE: NEW VENDOR',
44 'Charitable Progress Bar Debug',
45 'Charitable Admin Splash',
46 '[Charitable Square]',
47 'Square Legacy Mode',
48 'Charitable: Loading NPS Survey',
49 'Charitable NPS Survey:',
50 'Saving admin notices to transient',
51 'Notices to save:'
52 );
53
54 /**
55 * Initialize the log muter
56 */
57 public static function init() {
58 // The log muter is ready to use
59 // Note: Direct error_log() calls in vendor files have been disabled
60 // by commenting them out in the vendor files themselves
61 }
62
63 /**
64 * Check if a message should be muted
65 *
66 * @param string $message The error message
67 * @return boolean True if message should be muted, false otherwise
68 */
69 public static function should_mute( $message ) {
70 if ( ! self::MUTE_LOGS ) {
71 return false;
72 }
73
74 foreach ( self::$mute_patterns as $pattern ) {
75 if ( stripos( $message, $pattern ) !== false ) {
76 return true;
77 }
78 }
79
80 return false;
81 }
82
83 /**
84 * Conditional error logging function
85 *
86 * @param string $message The message to log
87 * @param int $message_type The message type
88 * @param string $destination The destination
89 * @param string $extra_headers Extra headers
90 * @return boolean True if logged, false if muted
91 */
92 public static function log( $message, $message_type = 0, $destination = null, $extra_headers = null ) {
93 if ( self::should_mute( $message ) ) {
94 return true; // Return true to indicate "success" but don't actually log
95 }
96
97 return error_log( $message, $message_type, $destination, $extra_headers );
98 }
99 }
100
101 // Initialize the log muter
102 Charitable_Log_Muter::init();
103