PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
← All changes | jetpack_vendor/automattic/jetpack-jitm/src/class-jitm.php +60 -1 16.2 → 16.3-beta View file →
@@ -24,9 +24,9 @@
24 24 * @since-jetpack 5.6.0
25 25 */
26 26 class JITM {
27 27
28 - const PACKAGE_VERSION = '5.0.2';
28 + const PACKAGE_VERSION = '5.1.1';
29 29
30 30 /**
31 31 * List of screen IDs where JITMs are allowed to display.
32 32 *
@@ -114,8 +114,67 @@
114 114 if ( null === self::$configured_instance ) {
115 115 self::$configured_instance = self::get_instance();
116 116 }
117 117 return self::$configured_instance;
118 + }
119 +
120 + /**
121 + * Clears admin notices from the current screen, keeping JITMs.
122 + *
123 + * A screen that opted out through `jetpack_display_jitms_on_screen` has nothing
124 + * to keep, so it stays silent.
125 + *
126 + * @since 5.1.0
127 + *
128 + * @return void
129 + */
130 + public static function suppress_foreign_admin_notices() {
131 + foreach ( array( 'admin_notices', 'all_admin_notices' ) as $hook ) {
132 + $ours = self::collect_own_callbacks( $hook );
133 +
134 + remove_all_actions( $hook );
135 +
136 + foreach ( $ours as $priority => $callbacks ) {
137 + foreach ( $callbacks as $callback ) {
138 + add_action( $hook, $callback['function'], $priority, $callback['accepted_args'] );
139 + }
140 + }
141 + }
142 + }
143 +
144 + /**
145 + * Returns our callbacks on $hook, keyed by priority.
146 + *
147 + * Matched by class: `prepare_jitms()` hooks the cached instance and
148 + * `get_instance()` builds a fresh one, so comparing objects would miss.
149 + *
150 + * @since 5.1.0
151 + *
152 + * @param string $hook Hook name.
153 + * @return array<int, array<int, array{function: callable, accepted_args: int}>>
154 + */
155 + private static function collect_own_callbacks( $hook ) {
156 + global $wp_filter;
157 +
158 + $kept = array();
159 +
160 + if ( ! isset( $wp_filter[ $hook ] ) || ! is_object( $wp_filter[ $hook ] ) ) {
161 + return $kept;
162 + }
163 +
164 + foreach ( $wp_filter[ $hook ]->callbacks as $priority => $callbacks ) {
165 + foreach ( $callbacks as $callback ) {
166 + if (
167 + is_array( $callback['function'] )
168 + && isset( $callback['function'][0] )
169 + && $callback['function'][0] instanceof self
170 + ) {
171 + $kept[ $priority ][] = $callback;
172 + }
173 + }
174 + }
175 +
176 + return $kept;
118 177 }
119 178
120 179 /**
121 180 * Sets up JITM action callbacks if needed.