PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / trunk
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) vtrunk
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 1.8.0 All 210 releases
charitable / includes / class-charitable-error-handler.php

class-charitable-error-handler.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) trunk, at includes/class-charitable-error-handler.php

187 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The error handler to suppress text domain loading notices.
4 *
5 * @package Charitable/Classes/Charitable_Error_Handler
6 * @version 1.8.7
7 * @author WP Charitable LLC
8 * @copyright Copyright (c) 2023, WP Charitable LLC
9 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Error_Handler' ) ) :
18
19 /**
20 * Charitable_Error_Handler
21 *
22 * @since 1.8.6.2
23 */
24 class Charitable_Error_Handler {
25
26 /**
27 * Previous error handler.
28 *
29 * @since 1.8.6.2
30 *
31 * @var callable|null
32 */
33 private $previous_error_handler;
34
35 /**
36 * Whether the error handler is handling an error.
37 *
38 * @since 1.8.6.2
39 *
40 * @var bool
41 */
42 private $handling = false;
43
44 /**
45 * Class constructor.
46 *
47 * @since 1.8.6.2
48 */
49 public function __construct() {
50 // Empty constructor.
51 }
52
53 /**
54 * Init class.
55 *
56 * @since 1.8.6.2
57 *
58 * @return void
59 */
60 public function init() {
61 if ( defined( 'CHARITABLE_DISABLE_ERROR_HANDLER' ) && CHARITABLE_DISABLE_ERROR_HANDLER ) {
62 return;
63 }
64
65 $this->hooks();
66 }
67
68 /**
69 * Add hooks.
70 *
71 * @since 1.8.6.2
72 *
73 * @return void
74 */
75 protected function hooks() {
76 // Only hook into WordPress 6.7+ textdomain notices.
77 if ( version_compare( $GLOBALS['wp_version'], '6.7', '>=' ) ) {
78 add_action( 'doing_it_wrong_run', array( $this, 'action_doing_it_wrong_run' ), 0, 3 );
79 add_action( 'doing_it_wrong_run', array( $this, 'action_doing_it_wrong_run' ), 20, 3 );
80 add_filter( 'doing_it_wrong_trigger_error', array( $this, 'filter_doing_it_wrong_trigger_error' ), 10, 4 );
81 }
82 }
83
84 /**
85 * Action for _doing_it_wrong() calls.
86 *
87 * @since 1.8.6.2
88 *
89 * @param string $function_name The function that was called.
90 * @param string $message A message explaining what has been done incorrectly.
91 * @param string $version The version of WordPress where the message was added.
92 *
93 * @return void
94 */
95 public function action_doing_it_wrong_run( $function_name, $message, $version ) {
96 global $wp_filter;
97
98 $function_name = (string) $function_name;
99 $message = (string) $message;
100
101 if ( ! class_exists( 'QM_Collectors' ) || ! $this->is_just_in_time_for_charitable_pro_domain( $function_name, $message ) ) {
102 return;
103 }
104
105 $qm_collector_doing_it_wrong = QM_Collectors::get( 'doing_it_wrong' );
106 $current_priority = $wp_filter['doing_it_wrong_run']->current_priority();
107
108 if ( $qm_collector_doing_it_wrong === null || $current_priority === false ) {
109 return;
110 }
111
112 switch ( $current_priority ) {
113 case 0:
114 remove_action( 'doing_it_wrong_run', array( $qm_collector_doing_it_wrong, 'action_doing_it_wrong_run' ) );
115 break;
116 case 20:
117 add_action( 'doing_it_wrong_run', array( $qm_collector_doing_it_wrong, 'action_doing_it_wrong_run' ), 10, 3 );
118 break;
119 }
120 }
121
122 /**
123 * Filter for _doing_it_wrong() calls.
124 *
125 * @since 1.8.6.2
126 *
127 * @param bool|mixed $trigger Whether to trigger the error for _doing_it_wrong() calls. Default true.
128 * @param string $function_name The function that was called.
129 * @param string $message A message explaining what has been done incorrectly.
130 * @param string $version The version of WordPress where the message was added.
131 *
132 * @return bool
133 */
134 public function filter_doing_it_wrong_trigger_error( $trigger, $function_name, $message, $version ): bool {
135 $trigger = (bool) $trigger;
136 $function_name = (string) $function_name;
137 $message = (string) $message;
138
139 return $this->is_just_in_time_for_charitable_pro_domain( $function_name, $message ) ? false : $trigger;
140 }
141
142 /**
143 * Whether it is the just_in_time_error for Charitable-related domains.
144 *
145 * @since 1.8.6.2
146 *
147 * @param string $function_name Function name.
148 * @param string $message Message.
149 *
150 * @return bool
151 */
152 protected function is_just_in_time_for_charitable_pro_domain( string $function_name, string $message ): bool {
153 if ( $function_name !== '_load_textdomain_just_in_time' ) {
154 return false;
155 }
156
157 $domains = array(
158 // Core domains.
159 'charitable-pro',
160 'charitable',
161 // Addon domains.
162 'charitable-recurring',
163 'charitable-ambassadors',
164 'charitable-newsletter',
165 'charitable-stripe',
166 'charitable-paypal',
167 'charitable-payfast',
168 'charitable-square',
169 'charitable-shoutouts',
170 'charitable-pdf-receipts',
171 'charitable-windcave',
172 'charitable-easy-digital-downloads-connect',
173 'charitable-geolocation',
174 );
175
176 foreach ( $domains as $domain ) {
177 if ( strpos( $message, '<code>' . $domain ) !== false ) {
178 return true;
179 }
180 }
181
182 return false;
183 }
184 }
185
186 endif;
187