Every page on the admin dashboard is looking like this — with “dead/empty” notification leftovers we cannot get rid of. NO new plugin was added and no plug-in update was made. Our code doesn’t touch any admin page.
Is there any database table I can “zap” or drain to allow us to get rid of this annoying effect.
The admin pages still function — we just have to scroll down to get to the actual content. This is an annoyance — but we’d like to get rid of it.
3 Answers
Let’s take a look at admin_notices
, since that’s where your output is.
https://core.trac.wordpress.org/browser/tags/5.4/src/wp-admin/admin-header.php#L281
So, it’s simply just an action-as-an-output-spot, what this means is that if you wish, you can output anything here and most importantly, this all happens in-memory, so, debugging should be pretty straight-forward; this spot is meant to output things. That’s it.
Unless you’re using a wrapper around this action such as https://github.com/WPTRT/admin-notices that allows you write your code cleaner (but this still uses the admin_notices
action inside), you’ll be doing something like add_action( 'admin_notices', function() { echo 'My notification!' } )
…and so will any other package that allows you to push these notifications out.
Knowing the following variables: in-memory, actions, we can attempt to see what’s going out in there. You can write your own action inspection engine
or, you can use someone else’s:
Now, if we are to Go to our Dashboard > Open the Query Monitor Panel (it’s in the top, sticky WP bar) > Access “Hooks & Actions” > Search for admin_notices
, we’ll be prompted with a screen like this:
In here, we can see exactly what’s hooked to this action and their priority, so, let’s try to replicate your issue. Let’s create some empty notifications and output them:
add_action( 'admin_notices', function() {
$class="notice notice-error";
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( '' ) );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( '' ) );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( '' ) );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( '' ) );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( '' ) );
}, 15 );
Great, and let’s see how our dashboard looks now:
Oof. It’s broken, just like yours is. But what does the image tell us? Well, it says that inside the theme, coming from a closure, within functions.php
on line 87
, there are some notifications that it’s trying to output.
Do this for your case and try to see which one is having issues.
Although a bit out of scope, or rather, comprising a larger scope, at times, I really wish you could get the return value
of a hook. Your case is the prime example of inspecting how the data flows within actions isn’t as easy to do, don’t get me wrong, it’s still possible, but requires quite some work to take care of everything and I gave up mid-way myself. In other words, wouldn’t it be cool to say Hey, WordPress, on action 'admin_notices', which one of the hooked functions returns an empty string or an error?
. Really saves you a lot of time.