errors - Removing warnings and notices from production servers

I'm getting errors, warnings and notices being displayed on a site. Those include things like filesystem paths, SQL

I'm getting errors, warnings and notices being displayed on a site. Those include things like filesystem paths, SQL queries and wpdb prefixes, which I don't think it's particularly good to have them being displayed to all visitors.

I have fixed the cause of the issue, but I want to prevent these error messages from being displayed on the live site. Turning WP_DEBUG_DISPLAY off hides the errors, but the warnings and notices remain. How do I hide those?

I'm getting errors, warnings and notices being displayed on a site. Those include things like filesystem paths, SQL queries and wpdb prefixes, which I don't think it's particularly good to have them being displayed to all visitors.

I have fixed the cause of the issue, but I want to prevent these error messages from being displayed on the live site. Turning WP_DEBUG_DISPLAY off hides the errors, but the warnings and notices remain. How do I hide those?

Share Improve this question edited May 29, 2019 at 21:32 That Brazilian Guy asked Mar 29, 2019 at 17:05 That Brazilian GuyThat Brazilian Guy 1,2413 gold badges19 silver badges43 bronze badges 7
  • 3 Do not hide those messages. Fix them instead. Disk full is a very serious problem that you have to address. – fuxia Commented Mar 29, 2019 at 17:30
  • In my opinion showing environment data (filesystem paths, SQL queries and wpdb prefixes) isn't exactly desirable. Fixing issues is important, but there should be some sort of automated monitoring workflow instead of relying on the kindness of site visitors. Or is it a good practice to have WP_DEBUG_DISPLAY turned on on production? – That Brazilian Guy Commented Mar 29, 2019 at 18:03
  • You should set up a password protected staging environment where all errors, warnings and notices are displayed while on production debug output is disabled. Fix everything on stage and copy to production then. – Luckyfella Commented Mar 29, 2019 at 18:41
  • @Luckyfella "Everybody has a testing environment. Some people are lucky enough enough to have a totally separate environment to run production in". – That Brazilian Guy Commented Mar 29, 2019 at 18:42
  • 1 @fuxia Sorry, but you're wrong. Such messages should be never displayed on production server. They can (and should) get logged, but never, never shown on the site. And yes - of course you should fix them, if it's possible (not always it is - even WordPress itself causes some notices sometimes). – Krzysiek Dróżdż Commented Mar 29, 2019 at 18:42
 |  Show 2 more comments

2 Answers 2

Reset to default 7

As many have already commented, it is better to fix the source of the issue than to hide the messages. That said, these types of messages should never be displayed on production server but, since you just never know, it is also a good idea to disable them on all servers (local development machine, development machines, etc.).

We use the following settings in wp-config.php to disable the display of all warnings, notices, errors, etc. and then use tail -f wp-content/debug.log to see the errors as we work:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Sometimes Notices don't include a backtrace so you can't see what's causing the message. Please see my answer to a similar question as it includes details on how to get a backtrace for such messages.

If you are still seeing warnings and info and such and you've followed my advice in this answer, then it is likely a plugin or the theme itself is re-enabling the display of warnings and info.

WP_DEBUG_DISPLAY is a constant that tells WordPress to run the following code:

if ( WP_DEBUG_DISPLAY ) {
    ini_set( 'display_errors', 1 );
} elseif ( null !== WP_DEBUG_DISPLAY ) {
    ini_set( 'display_errors', 0 );
}

This code is in wp-includes/load.php and is, if not the first, one of the very first files included in the WordPress bootstrapping procedure. The function that this code appears in is called in wp-settings.php which is the first file included after wp-config.php. This code is called before plugins are loaded and executed.

If a plugin producer has ini_set( 'display_errors', 1 ) in their code, it will override what you've got in wp-config.php and continue showing PHP errors, warnings, info, etc. There is no way, really, to override this. Try searching your entire plugins folder for ini_set to see if you can spot the culprit. You should probably also check your theme while you are at it.

As others have already said, it's very important to fix the underlying issues causing the error messages to show up.

In my opinion, it's also important to have these errors and warnings showing up on development and homologation environments, but not on production, for a variety or reasons.

I was able to remove notices and warnings from the production environment by placing the following line into wp-config.php:

ini_set('display_errors','Off');

Even with WP_DEBUG turned off, a few warnings were still being shown.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745186639a4615669.html

相关推荐

  • errors - Removing warnings and notices from production servers

    I'm getting errors, warnings and notices being displayed on a site. Those include things like filesystem paths, SQL

    12小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信