-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlog-admin-notices.php
More file actions
51 lines (43 loc) · 1.69 KB
/
log-admin-notices.php
File metadata and controls
51 lines (43 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Plugin Name: Log Admin Notices
* Description: Log's admin notices on admin_init, great for finding admin_notices to hide.
* Version: 1.0.0
* Type: snippet
* Status: Complete
*/
add_action( 'admin_init', function () {
# -- Use the global wp_filter
global $wp_filter;
# -- Log stff
$log_file = ABSPATH . 'wp-content/mu-plugins/temp.log';
# -- List all admin_notices
$log_message = "<!-- ".var_export( $wp_filter[ 'admin_notices' ], true )."-->";
# -- List all admin_notices functions and their details.
$log_message .= "\n#### Go through all Admin Notices Content ####\n";
foreach($wp_filter['admin_notices'] as $weight => $callbacks) {
foreach($callbacks as $name => $details) {
# -- Check if function is an array
if ( is_array($details['function']) ) {
$log_message .= "\n-- Start Function Array";
$log_message .= "\n".print_r($details['function'],true);
#$log_message .= "\nArray[0]".$details['function']['0'];
} else {
$log_message .= "\n-- Start Function ".$details['function'];
}
# -- Buffer and output details
ob_start();
call_user_func($details['function']);
$log_message .= ob_get_clean();
$log_message .= "\n-- End Function ".$details['function']."\n\n";
#// Check if this contains our forbidden string
#foreach($forbidden_message_strings as $forbidden_string) {
#if(strpos($message, $forbidden_string) !== FALSE) {
// Found it - under this callback
# $wp_filter['admin_notices']->remove_filter('admin_notices', $details['function'], $weight);
#}
#}
}
}
file_put_contents($log_file, $log_message, FILE_APPEND);
});