最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

"leftover" notifications left on ever admin screen?

programmeradmin3浏览0评论

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.

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.

Share Improve this question asked Apr 9, 2020 at 15:18 JasonGenXJasonGenX 718 bronze badges 4
  • Try disabling your plugins one at a time and then your theme, I would think it would have to be something in one of those. – RiddleMeThis Commented Apr 14, 2020 at 19:16
  • That's pretty much the answer to any Wordpress issue. None of our plugins changed for 2+ years. what is the source of this display? The plugins may contribute to it, but the WordPress admin displays them. Where are those empty notifications on the database? – JasonGenX Commented Apr 14, 2020 at 20:09
  • Notifications aren't typically saved in the database. "what is the source of this display?" that you can figure out by debugging, which I suggested to do. – RiddleMeThis Commented Apr 14, 2020 at 20:49
  • JasonGenX - the notices are usually generated when a condition is or is not met, so they're not stored anywhere. Whatever is resulting in them appearing is just triggering repeatedly. Even though the plugins haven't been updated in the past two years, other things may have changed. WordPress may have updated, the server software may have updated, one of the plugins may call to an API service somewhere and since you haven't updated them there may be errors when the plugin tries to communicate with the API. Question though, is it always the same/similar number of notices or do they increase? – Tony Djukic Commented Apr 15, 2020 at 21:36
Add a comment  | 

3 Answers 3

Reset to default 9 +100

Let's take a look at admin_notices, since that's where your output is.

https://core.trac.wordpress/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/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:

https://wordpress/plugins/query-monitor/

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.

Can't post a comment so here goes.

If you're not into writing or debugging code I'd try this:

Search the WordPress site for a plugin called "Disable admin notices individually". Whenever an admin notice pops up, you can disable it. While this plugin doesn't fix the root cause of the problem, it does seem to hide it under a rock so you don't see it.

I do want to point out that if you've updated WordPress but haven't updated plugins, that may be the problem.

Here's a workaround with jQuery. Add this to your functions.php in the active theme folder

function enqueue_my_scripts_hide_warnings() {
?>
<script>
jQuery(document).ready(function(){
    jQuery('.notice-info').each(function(){
        if(!jQuery(this).text()){
            jQuery(this).hide();
        }
    })
    jQuery('.notice-warning').each(function(){
        if(!jQuery(this).text()){
            jQuery(this).hide();
        }
    })
});
</script>
<?php

}  
add_action( 'admin_footer', 'enqueue_my_scripts_hide_warnings' );

If that selector doesn't work, just replace line 5-9 with this below. However the selector may be too wide, so use with caution. May have to tweak the selector depending on how your admin pages work.

    jQuery('.notice').each(function(){
        if(!jQuery(this).text()){
            jQuery(this).hide();
        }
    })
发布评论

评论列表(0)

  1. 暂无评论