I’d prefer not to have an “if check” for every single constant wouldn’t it be cleaner to check for just for one of them and either define or not define at all?
If I understand this question we shouldn’t entirely check for just one of them. For example in our case (explained more below) We are only defining DUPLICATOR_WPROOTPATH
in wp-config
and letting the plugin’s define.php
take care of things from there.
However, let’s say that I wanted to change the name of wp-snapshots
I could modify just DUPLICATOR_SSDIR_NAME
while leaving everything else the same.
As an end user it would be much more complicated to have to set multiple constants just to change a couple of them. To use our case as an example again, we’d then have to copy over all the other //PATH CONSTANTS
resulting in duplicate code between wp-config.php
and define.php
I do agree that this doesn’t look the cleanest, There may be a way for you to add a setting screen option instead if that would feel cleaner to you. This method just seemed the simplest. I’ll also be the first to point out that, really for our use case only the //PATH CONSTANTS
need the check. I just though it would be nice to allow users to overwrite the other settings as well by setting a constant. Feel free to remove the checks around anything outside of Path Constants, just know that without the check if a user tries to define these themselves they will have a fatal.
Just to verify your use case: you have the wp-config.php in say a directory outside of the wproot?
Correct, our setup is a bit unique. We have thousands of WordPress site-site installs that all share the same core files. These files live in a _wp_
directory that is not accessible or writable by individual sites.
Each site then has its own wp-content
folder and wp-config.php
file inside of /htdocs/site-name/
which can be fully controlled or modified by the site.
So in our case what we did was after adding the if
check defined:
define('DUPLICATOR_WPROOTPATH', str_replace('\\', '/', $ SERVER['DOCUMENT ROOT'] . '/') );
In the local wp-config.php which allowed us to set the document root for wp-content
to /htdocs/
instead of /path/to/shared-wp-core/
(which are not writable)
My goal with this patch was to create a way for the paths to not just work with our setup, but with any unique WordPress install setup.