简体   繁体   中英

Suppress PHP warnings and notices in WordPress pages

When I try to load WordPress, I get a lot of Use of undefined constant 'view' - assumed ''view'' type of warnings and notices in the browser. This causes the pages to fill up with these messages before it renders the actual page content expected.

I tried changing error_reporting = E_ALL to error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING but the warnings and notices still show up.

After doing php --ini I located both the 7.0 and 7.1 ini files and updated the value in both and restarted both FPM services on my vagrant.

  • /etc/php/7.0/fpm/php.ini
  • /etc/php/7.1/fpm/php.ini

Why are these still showing up?

看起来您从某个源复制代码并粘贴到文件中,使用倒引号 ` 而不是 ',只需更改单引号即可修复。

 change ‘view’ to 'view' and so on.

You can combine WordPress build-in constants and PHP's ini settings.

Place these lines in your wp-config.php

ini_set('log_errors','on');
ini_set('display_errors','off');
ini_set('error_reporting', E_ALL );

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

This way all notices , warnings and errors will not be shown on the front-end of your website, but errors are still accesable by a log file.

To show errors and hide notices (and as was asked, warnings) there is a hacky way in wp-config.php :

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

plus this at the end of the file after wp-settings.php is loaded:

/*hide notices and warnings*/
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING );

I'm saying hacky only because it's after the line saying /* That's all, stop editing! Happy publishing. */ /* That's all, stop editing! Happy publishing. */ /* That's all, stop editing! Happy publishing. */ :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM