$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp config - How can I resolve the php notice "Constant EMPTY_TRASH_DAYS already defined"|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp config - How can I resolve the php notice "Constant EMPTY_TRASH_DAYS already defined"

matteradmin8PV0评论

With define('WP_DEBUG', true); in wp-config.php, I get the following notice:

Constant EMPTY_TRASH_DAYS already defined in /wp-config.php on line 83

I have checked this file, and this constant is defined just once. I've also searched through all of the php files on the server and don't see that it's defined anywhere else. I've run a thorough search. The only other place it's defined is in default-constants.php:

if ( !defined( 'EMPTY_TRASH_DAYS' ) )
define( 'EMPTY_TRASH_DAYS', 30 );

By commenting out the second line, the notice disappears. But it doesn't make sense to have to edit default-constants.php in order to define the constant in the proper place, which is wp-config.php.

How should I define this constant properly, without editing default-constants.php, which risks being overwritten during an upgrade?

With define('WP_DEBUG', true); in wp-config.php, I get the following notice:

Constant EMPTY_TRASH_DAYS already defined in /wp-config.php on line 83

I have checked this file, and this constant is defined just once. I've also searched through all of the php files on the server and don't see that it's defined anywhere else. I've run a thorough search. The only other place it's defined is in default-constants.php:

if ( !defined( 'EMPTY_TRASH_DAYS' ) )
define( 'EMPTY_TRASH_DAYS', 30 );

By commenting out the second line, the notice disappears. But it doesn't make sense to have to edit default-constants.php in order to define the constant in the proper place, which is wp-config.php.

How should I define this constant properly, without editing default-constants.php, which risks being overwritten during an upgrade?

Share Improve this question edited Oct 27, 2018 at 4:31 Kit Johnson asked Oct 25, 2018 at 2:26 Kit JohnsonKit Johnson 2794 silver badges11 bronze badges 4
  • 1 The load process is index.php (in install root, not your theme) -> wp-blog-header.php -> wp-load.php -> wp-config.php. That notice is telling you where it's attempting to set the constant a 2nd time. It seems very strange to see that error that early in the process where only core files have been loaded. I would start by switching to a default theme and disabling all plugins, check if error is still present, then re-enable one-by-one. – Milo Commented Oct 25, 2018 at 3:45
  • Thank you @Milo! Disabling all plugins and reverting to 2017 theme didn't seem to help. However I found that by commenting out a line in default-constants.php the notice disappears. I've edited the question to include this updated information. However, the problem still isn't fully resolved, in that I shouldn't have to edit default-constants.php. – Kit Johnson Commented Oct 25, 2018 at 11:26
  • 1 In wp-config.php there's this line: require_once( ABSPATH . 'wp-settings.php' );. Is your define( 'EMPTY_TRASH_DAYS', 30 ); before this line? – Jacob Peattie Commented Oct 25, 2018 at 11:33
  • Yay @JacobPeattie you solved it! Shall I write up your comment as an answer or would you prefer to do that yourself? – Kit Johnson Commented Oct 27, 2018 at 4:27
Add a comment  | 

2 Answers 2

Reset to default 4

When defining any WordPress constants in wp-config.php you need to do it before this line:

require_once( ABSPATH . 'wp-settings.php' );

That line loads many of WordPress’s default constants, and if you haven’t already defined them yourself then they’ll be defined in that line, meaning that any of them that you try to define after this line will have already been defined.

It means that the constant EMPTY_TRASH_DAYS has been defined twice. You need to check and remove the second definition of the same constant. It may be that it's been defined somewhere else. So search all the files of WordPress using grep, find or some advanced text editor like Sublime Text

Post a comment

comment list (0)

  1. No comments so far