What’s the cause of this ‘Cannot redeclare’ error?
-
I have a custom theme which I’ve been using for years, on various sites.
After some minor updates and a rename, on activation I’m getting several ‘cannot redeclare’ errors for files which haven’t been modified (and which work fine when reverting to the older version of the theme, and on other sites using the updated theme).
The issue only occurs with function files which are in a sub-folder ‘admin’.
The functions.php file contains this:
function require_all_files($dir) { foreach( glob( "$dir/*" ) as $path ) { if ( preg_match( '/\.php$/', $path ) ) { require_once $path; // it's a PHP file so just require it } elseif ( is_dir( $path ) ) { require_all_files( $path ); // it's a subdir, so call the same function for this subdir } } } require_all_files( get_template_directory() . "/functions/" );
And the ‘functions’ folder contains a sub-folder ‘admin’.
I have this code, and folder/sub-folder set-up on all of my sites (including the older version of the theme) – and it works fine except for one.
On renaming that ‘admin’ sub-folder, things work ok.
I’m baffled.
- The topic ‘What’s the cause of this ‘Cannot redeclare’ error?’ is closed to new replies.