|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Deprecated functions. |
|
4
|
|
|
* |
|
5
|
|
|
* Contains the functions used to deprecate functions and |
|
6
|
|
|
* hooks in MonsterInsights, as well as the deprecated functions |
|
7
|
|
|
* and hooks themselves, where possible. |
|
8
|
|
|
* |
|
9
|
|
|
* @since 6.0.0 |
|
10
|
|
|
* |
|
11
|
|
|
* @package MonsterInsights |
|
12
|
|
|
* @subpackage Deprecated |
|
13
|
|
|
* @author Chris Christoff |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
// Exit if accessed directly |
|
17
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
18
|
|
|
exit; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Fires functions attached to a deprecated filter hook. |
|
23
|
|
|
* |
|
24
|
|
|
* When a filter hook is deprecated, the apply_filters() call is replaced with |
|
25
|
|
|
* apply_filters_deprecated(), which triggers a deprecation notice and then fires |
|
26
|
|
|
* the original filter hook. Note, this is a copy of WordPress core's _apply_filters_deprecated |
|
27
|
|
|
* function, that we've copied into MonsterInsights so that we can use it on WordPress |
|
28
|
|
|
* versions older than 6.0.0 (when it was introduced to core). If we ever bump our |
|
29
|
|
|
* minimum WP version requirements above 6.0.0, we'll remove this function. |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $tag The name of the filter hook. |
|
32
|
|
|
* @param array $args Array of additional function arguments to be passed to apply_filters(). |
|
33
|
|
|
* @param string $version The version of WordPress that deprecated the hook. |
|
34
|
|
|
* @param string $message Optional. A message regarding the change. Default null. |
|
35
|
|
|
* |
|
36
|
|
|
* @since 6.0.0 |
|
37
|
|
|
* @access private |
|
38
|
|
|
* |
|
39
|
|
|
* @see _apply_filters_deprecated() |
|
40
|
|
|
* |
|
41
|
|
|
*/ |
|
42
|
|
|
function _monsterinsights_apply_filters_deprecated( $tag, $args, $version, $message = null ) { |
|
43
|
|
|
if ( ! has_filter( $tag ) ) { |
|
44
|
|
|
return $args[0]; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
_monsterinsights_deprecated_hook( $tag, $version, $message ); |
|
48
|
|
|
|
|
49
|
|
|
return apply_filters_ref_array( $tag, $args ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Fires functions attached to a deprecated action hook. |
|
54
|
|
|
* |
|
55
|
|
|
* When an action hook is deprecated, the do_action() call is replaced with |
|
56
|
|
|
* do_action_deprecated(), which triggers a deprecation notice and then fires |
|
57
|
|
|
* the original hook. Note, this is a copy of WordPress core's _do_action_deprecated |
|
58
|
|
|
* function, that we've copied into MonsterInsights so that we can use it on WordPress |
|
59
|
|
|
* versions older than 6.0.0 (when it was introduced to core). If we ever bump our |
|
60
|
|
|
* minimum WP version requirements above 6.0.0, we'll remove this function. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $tag The name of the action hook. |
|
63
|
|
|
* @param array $args Array of additional function arguments to be passed to do_action(). |
|
64
|
|
|
* @param string $version The version of WordPress that deprecated the hook. |
|
65
|
|
|
* @param string $message Optional. A message regarding the change. |
|
66
|
|
|
* |
|
67
|
|
|
* @since 6.0.0 |
|
68
|
|
|
* @access private |
|
69
|
|
|
* |
|
70
|
|
|
* @see _do_action_deprecated() |
|
71
|
|
|
* |
|
72
|
|
|
*/ |
|
73
|
|
|
function _monsterinsights_do_action_deprecated( $tag, $args, $version, $message = null ) { |
|
74
|
|
|
if ( ! has_action( $tag ) ) { |
|
75
|
|
|
return; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
_monsterinsights_deprecated_hook( $tag, $version, $message ); |
|
79
|
|
|
|
|
80
|
|
|
do_action_ref_array( $tag, $args ); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Marks a deprecated action or filter hook as deprecated and throws a notice. |
|
85
|
|
|
* |
|
86
|
|
|
* Use the {@see 'deprecated_hook_run'} action to get the backtrace describing where |
|
87
|
|
|
* the deprecated hook was called. |
|
88
|
|
|
* |
|
89
|
|
|
* Default behavior is to trigger a user error if `WP_DEBUG` is true. |
|
90
|
|
|
* |
|
91
|
|
|
* This function is called by the do_action_deprecated() and apply_filters_deprecated() |
|
92
|
|
|
* functions, and so generally does not need to be called directly. |
|
93
|
|
|
* |
|
94
|
|
|
* Note, this is a copy of WordPress core's _deprecated_hook |
|
95
|
|
|
* function, that we've copied into MonsterInsights so that we can use it on WordPress |
|
96
|
|
|
* versions older than 6.0.0 (when it was introduced to core). If we ever bump our |
|
97
|
|
|
* minimum WP version requirements above 6.0.0, we'll remove this function. |
|
98
|
|
|
* |
|
99
|
|
|
* @param string $hook The hook that was used. |
|
100
|
|
|
* @param string $version The version of WordPress that deprecated the hook. |
|
101
|
|
|
* @param string $message Optional. A message regarding the change. |
|
102
|
|
|
* |
|
103
|
|
|
* @since 6.0.0 |
|
104
|
|
|
* @access private |
|
105
|
|
|
* |
|
106
|
|
|
*/ |
|
107
|
|
|
function _monsterinsights_deprecated_hook( $hook, $version, $message = null ) { |
|
108
|
|
|
/** |
|
109
|
|
|
* Fires when a deprecated hook is called. |
|
110
|
|
|
* |
|
111
|
|
|
* @param string $hook The hook that was called. |
|
112
|
|
|
* @param string $version The version of MonsterInsights that deprecated the hook used. |
|
113
|
|
|
* @param string $message A message regarding the change. |
|
114
|
|
|
* |
|
115
|
|
|
* @since 6.0.0 |
|
116
|
|
|
* |
|
117
|
|
|
*/ |
|
118
|
|
|
do_action( 'deprecated_hook_run', $hook, $version, $message ); |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Filters whether to trigger deprecated hook errors. |
|
122
|
|
|
* |
|
123
|
|
|
* @param bool $trigger Whether to trigger deprecated hook errors. Requires |
|
124
|
|
|
* `WP_DEBUG` to be defined true. |
|
125
|
|
|
* |
|
126
|
|
|
* @since 6.0.0 |
|
127
|
|
|
* |
|
128
|
|
|
*/ |
|
129
|
|
|
if ( ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) || monsterinsights_is_debug_mode() ) { |
|
130
|
|
|
$message = empty( $message ) ? '' : ' ' . $message; |
|
131
|
|
|
// Translators: Placeholders add the hook name, plugin version and bold text. |
|
132
|
|
|
trigger_error( sprintf( esc_html__( '%1$s is %3$sdeprecated%4$s since MonsterInsights version %2$s!', 'google-analytics-for-wordpress' ), $hook, $version, '<strong>', '</strong>' ) . $message ); // phpcs:ignore |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Marks a function as deprecated and informs when it has been used. |
|
138
|
|
|
* |
|
139
|
|
|
* There is a hook monsterinsights_deprecated_function_run that will be called that can be used |
|
140
|
|
|
* to get the backtrace up to what file and function called the deprecated |
|
141
|
|
|
* function. Based on the one in EDD core. |
|
142
|
|
|
* |
|
143
|
|
|
* The current behavior is to trigger a user error if WP_DEBUG is true. |
|
144
|
|
|
* |
|
145
|
|
|
* This function is to be used in every function that is deprecated. |
|
146
|
|
|
* |
|
147
|
|
|
* @param string $function The function that was called |
|
148
|
|
|
* @param string $version The version of WordPress that deprecated the function |
|
149
|
|
|
* @param array $backtrace Optional. Contains stack backtrace of deprecated function |
|
150
|
|
|
* |
|
151
|
|
|
* @return void |
|
152
|
|
|
* @uses do_action() Calls 'monsterinsights_deprecated_function_run' and passes the function name, what to use instead, |
|
153
|
|
|
* and the version the function was deprecated in. |
|
154
|
|
|
* @uses apply_filters() Calls 'monsterinsights_deprecated_function_trigger_error' and expects boolean value of true to do |
|
155
|
|
|
* trigger or false to not trigger error. |
|
156
|
|
|
* |
|
157
|
|
|
* @since 6.0.0 |
|
158
|
|
|
* @access private |
|
159
|
|
|
* |
|
160
|
|
|
*/ |
|
161
|
|
|
function _monsterinsights_deprecated_function( $function, $version, $backtrace = null ) { |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Deprecated Function Action. |
|
165
|
|
|
* |
|
166
|
|
|
* Allow plugin run an action on the use of a |
|
167
|
|
|
* deprecated function. This could be used to |
|
168
|
|
|
* feed into an error logging program or file. |
|
169
|
|
|
* |
|
170
|
|
|
* @param string $function The function that was called. |
|
171
|
|
|
* @param string $version The version of WordPress that deprecated the function. |
|
172
|
|
|
* @param array $backtrace Optional. Contains stack backtrace of deprecated function. |
|
173
|
|
|
* |
|
174
|
|
|
* @since 6.0.0 |
|
175
|
|
|
* |
|
176
|
|
|
*/ |
|
177
|
|
|
do_action( 'deprecated_function_run', $function, $version, $backtrace ); |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Filters whether to trigger an error for deprecated functions. |
|
181
|
|
|
* |
|
182
|
|
|
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true. |
|
183
|
|
|
* |
|
184
|
|
|
* @since 6.0.0 |
|
185
|
|
|
* |
|
186
|
|
|
*/ |
|
187
|
|
|
if ( ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) || monsterinsights_is_debug_mode() ) { |
|
|
|
|
|
|
188
|
|
|
// Translators: Placeholders add the hook name, plugin version and bold text. |
|
189
|
|
|
trigger_error( sprintf( esc_html__( '%1$s is %3$sdeprecated%4$s since MonsterInsights version %2$s.', 'google-analytics-for-wordpress' ), $function, $version, '<strong>', '</strong>' ) ); |
|
190
|
|
|
// Limited to previous 1028 characters, but since we only need to move back 1 in stack that should be fine. |
|
191
|
|
|
trigger_error( print_r( $backtrace, 1 ) ); // phpcs:ignore |
|
|
|
|
|
|
192
|
|
|
// Alternatively we could dump this to a file. |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Marks something as deprecated. |
|
198
|
|
|
* |
|
199
|
|
|
* The current behavior is to trigger a user error if WP_DEBUG is true. |
|
200
|
|
|
* |
|
201
|
|
|
* @param string $message Deprecation message shown. |
|
202
|
|
|
* |
|
203
|
|
|
* @return void |
|
204
|
|
|
* @since 6.0.0 |
|
205
|
|
|
* @access private |
|
206
|
|
|
* |
|
207
|
|
|
* @uses apply_filters() Calls 'monsterinsights_deprecated_trigger_error' and expects boolean value of true to do |
|
208
|
|
|
* trigger or false to not trigger error. |
|
209
|
|
|
* |
|
210
|
|
|
*/ |
|
211
|
|
|
function _monsterinsights_deprecated( $message ) { |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Deprecated Message Filter. |
|
215
|
|
|
* |
|
216
|
|
|
* Allow plugin to filter the deprecated message. |
|
217
|
|
|
* |
|
218
|
|
|
* @param string $message Error message. |
|
219
|
|
|
* |
|
220
|
|
|
* @since 6.0.0 |
|
221
|
|
|
* |
|
222
|
|
|
*/ |
|
223
|
|
|
do_action( 'monsterinsights_deprecated_run', $message ); |
|
224
|
|
|
|
|
225
|
|
|
$show_errors = current_user_can( 'manage_options' ); |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* Deprecated Error Trigger. |
|
229
|
|
|
* |
|
230
|
|
|
* Allow plugin to filter the output error trigger. |
|
231
|
|
|
* |
|
232
|
|
|
* @param bool $show_errors Whether to show errors. |
|
233
|
|
|
* |
|
234
|
|
|
* @since 6.0.0 |
|
235
|
|
|
* |
|
236
|
|
|
*/ |
|
237
|
|
|
$show_errors = apply_filters( 'monsterinsights_deprecated_trigger_error', $show_errors ); |
|
238
|
|
|
if ( ( WP_DEBUG && $show_errors ) || monsterinsights_is_debug_mode() ) { |
|
239
|
|
|
trigger_error( esc_html( $message ) ); |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* Check installed deprecated addons. |
|
245
|
|
|
* |
|
246
|
|
|
* @return void |
|
247
|
|
|
* @since 8.19.0 |
|
248
|
|
|
*/ |
|
249
|
|
|
function _monsterinsights_check_deprecated_addons() { |
|
250
|
|
|
// Check facebook-instant-articles |
|
251
|
|
|
if ( |
|
252
|
|
|
in_array( |
|
253
|
|
|
'monsterinsights-facebook-instant-articles/monsterinsights-facebook-instant-articles.php', |
|
254
|
|
|
apply_filters( |
|
|
|
|
|
|
255
|
|
|
'active_plugins', |
|
256
|
|
|
get_option( 'active_plugins' ) |
|
257
|
|
|
) |
|
258
|
|
|
) |
|
259
|
|
|
) { |
|
260
|
|
|
// Deprecated addon is activated, add a notice. |
|
261
|
|
|
add_action( 'admin_notices', '_monsterinsights_notice_deprecated_facebook_instant_articles' ); |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
// Check google-optimize |
|
265
|
|
|
if ( |
|
266
|
|
|
in_array( |
|
267
|
|
|
'monsterinsights-google-optimize/monsterinsights-google-optimize.php', |
|
268
|
|
|
apply_filters( |
|
269
|
|
|
'active_plugins', |
|
270
|
|
|
get_option( 'active_plugins' ) |
|
271
|
|
|
) |
|
272
|
|
|
) |
|
273
|
|
|
) { |
|
274
|
|
|
// Deprecated addon is activated, add a notice. |
|
275
|
|
|
add_action( 'admin_notices', '_monsterinsights_notice_deprecated_google_optimize' ); |
|
276
|
|
|
} |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* Admin notice for deprecated Facebook Instant Articles addon |
|
281
|
|
|
* |
|
282
|
|
|
* @access public |
|
283
|
|
|
* @return void |
|
284
|
|
|
* @since 8.19.0 |
|
285
|
|
|
* |
|
286
|
|
|
*/ |
|
287
|
|
|
function _monsterinsights_notice_deprecated_facebook_instant_articles() |
|
288
|
|
|
{ |
|
289
|
|
|
?> |
|
290
|
|
|
<div data-dismissible="deprecated-addon-facebook-instant-articles" class="notice notice-error is-dismissible"> |
|
291
|
|
|
<p> |
|
292
|
|
|
<?php echo __( 'Facebook Instant Article support ended in April 2023. You may deactivate and delete the MonsterInsights addon at your earliest convenience.', 'ga-premium' ); ?> |
|
293
|
|
|
</p> |
|
294
|
|
|
</div> |
|
295
|
|
|
<?php |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* Admin notice for deprecated Google Optimize addon |
|
300
|
|
|
* |
|
301
|
|
|
* @access public |
|
302
|
|
|
* @return void |
|
303
|
|
|
* @since 8.20.0 |
|
304
|
|
|
* |
|
305
|
|
|
*/ |
|
306
|
|
|
function _monsterinsights_notice_deprecated_google_optimize() |
|
307
|
|
|
{ |
|
308
|
|
|
?> |
|
309
|
|
|
<div data-dismissible="deprecated-addon-facebook-instant-articles" class="notice notice-error is-dismissible"> |
|
310
|
|
|
<p> |
|
311
|
|
|
<?php echo __( 'Google Optimize and Optimize 360 support ended in September 2023. You may deactivate and delete the MonsterInsights addon at your earliest convenience.', 'ga-premium' ); ?> |
|
312
|
|
|
</p> |
|
313
|
|
|
</div> |
|
314
|
|
|
<?php |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
if (!function_exists('monsterinsights_get_ua')) { |
|
318
|
|
|
function monsterinsights_get_ua() { |
|
319
|
|
|
return ''; |
|
320
|
|
|
} |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
if (!function_exists('monsterinsights_get_network_ua')) { |
|
324
|
|
|
function monsterinsights_get_network_ua() { |
|
325
|
|
|
return ''; |
|
326
|
|
|
} |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
if (!function_exists('monsterinsights_mp_track_event_call')) { |
|
330
|
|
|
function monsterinsights_mp_track_event_call() { |
|
331
|
|
|
return ''; |
|
332
|
|
|
} |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
if (!function_exists('monsterinsights_mp_api_call')) { |
|
336
|
|
|
function monsterinsights_mp_api_call() { |
|
337
|
|
|
return ''; |
|
338
|
|
|
} |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
if (!function_exists('monsterinsights_get_mp_api_url')) { |
|
342
|
|
|
function monsterinsights_get_mp_api_url() { |
|
343
|
|
|
return ''; |
|
344
|
|
|
} |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
if (!function_exists('monsterinsights_get_tracking_ids')) { |
|
348
|
|
|
function monsterinsights_get_tracking_ids() { |
|
349
|
|
|
return ''; |
|
350
|
|
|
} |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
if (!function_exists('monsterinsights_is_valid_ua')) { |
|
354
|
|
|
function monsterinsights_is_valid_ua() { |
|
355
|
|
|
return false; |
|
356
|
|
|
} |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
if (!function_exists('monsterinsights_get_ua_to_output')) { |
|
360
|
|
|
function monsterinsights_get_ua_to_output() { |
|
361
|
|
|
return ''; |
|
362
|
|
|
} |
|
363
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.