PluginProbe ʕ •ᴥ•ʔ
Disable Admin Notices – Hide Dashboard Notifications / trunk
Disable Admin Notices – Hide Dashboard Notifications vtrunk
1.4.5 trunk 1.0.0 1.0.2 1.0.3 1.0.5 1.0.6 1.1.1 1.1.3 1.1.4 1.2.0 1.2.2 1.2.3 1.2.4 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4
disable-admin-notices / includes / functions.php
disable-admin-notices / includes Last commit date
3rd-party 3 years ago classes 6 months ago class-plugin.php 3 months ago functions.php 3 years ago index.php 8 years ago
functions.php
122 lines
1 <?php
2 /**
3 * Helper functions
4 * @author Webcraftic <alex.kovalevv@gmail.com>
5 * @copyright (c) 05.07.2020, Webcraftic
6 * @version 1.0
7 */
8
9 /**
10 * Access to global variable $wp_filter in WP core.
11 * Migration from WP 4.2 to 4.9
12 *
13 * @see https://codex.wordpress.org/Version_4.7 WP 4.7 changelog (WP_Hook)
14 *
15 * @param $key string filter name
16 *
17 * @return array callbacks array by link
18 */
19 function &wdan_get_wp_filter( $key ) {
20 global $wp_filter;
21
22 $default = [];
23
24 if ( 'admin_notices' === $key && is_multisite() && is_network_admin() ) {
25 $key = 'network_admin_notices';
26 }
27
28 if ( ! isset( $wp_filter[ $key ] ) ) {
29 return $default;
30 }
31
32 return $wp_filter[ $key ]->callbacks;
33 }
34
35 /**
36 * @param $key
37 *
38 * @return array
39 */
40 function wdan_collect_notices( $key ) {
41 $wp_filter = &wdan_get_wp_filter( $key );
42
43 $content = [];
44
45 if ( ! empty( $wp_filter ) ) {
46 foreach ( (array) $wp_filter as $filters ) {
47 foreach ( $filters as $callback_name => $callback ) {
48
49 if ( 'usof_hide_admin_notices_start' == $callback_name || 'usof_hide_admin_notices_end' == $callback_name ) {
50 continue;
51 }
52
53 ob_start();
54
55 // #CLRF-140 fix bug for php7
56 // when the developers forgot to delete the argument in the function of implementing the notification.
57 $args = [];
58 $accepted_args = isset( $callback['accepted_args'] ) && ! empty( $callback['accepted_args'] ) ? $callback['accepted_args'] : 0;
59
60 if ( $accepted_args > 0 ) {
61 for ( $i = 0; $i < (int) $accepted_args; $i ++ ) {
62 $args[] = null;
63 }
64 }
65 //===========
66
67 call_user_func_array( $callback['function'], $args );
68 $cont = ob_get_clean();
69
70 if ( ! empty( $cont ) ) {
71 $salt = is_multisite() ? get_current_blog_id() : '';
72 $uniq_id1 = md5( $cont . $salt );
73 $uniq_id2 = md5( $callback_name . $salt );
74
75 if ( is_array( $callback['function'] ) && sizeof( $callback['function'] ) == 2 ) {
76 $class = $callback['function'][0];
77 if ( is_object( $class ) ) {
78 $class_name = get_class( $class );
79 $method_name = $callback['function'][1];
80 $uniq_id2 = md5( $class_name . ':' . $method_name );
81 }
82 }
83
84 $content[ $uniq_id1 . "_" . $uniq_id2 ] = $cont;
85 }
86 }
87 }
88 }
89
90 return $content;
91 }
92
93 /**
94 * @param $key
95 * @param array $excluded_classes
96 * @param array $excluded_callback_names
97 */
98 function wdan_clear_all_notices( $key, $excluded_classes = [], $excluded_callback_names = [] ) {
99 $wp_filter = &wdan_get_wp_filter( $key );
100
101 if ( ! empty( $wp_filter ) ) {
102 foreach ( (array) $wp_filter as $f_key => $f ) {
103 foreach ( $f as $c_name => $clback ) {
104 if ( is_array( $clback['function'] ) && sizeof( $clback['function'] ) == 2 ) {
105 $class = $clback['function'][0];
106 if ( is_object( $class ) ) {
107 $class_name = get_class( $class );
108
109 if ( in_array( $class_name, $excluded_classes ) ) {
110 continue;
111 }
112 }
113 }
114
115 if ( in_array( $c_name, $excluded_callback_names ) ) {
116 continue;
117 }
118 unset( $wp_filter[ $f_key ][ $c_name ] );
119 }
120 }
121 }
122 }