public function calculate_path()
{
$paths = array();
// If we have a custom path then try to use it.
if ($this->get_custom_path()) {
$paths[] = $this->get_custom_path();
}
// If there is already a backups directory then try to use that.
if ($this->get_existing_path()) {
$paths[] = $this->get_existing_path();
}
// If not then default to a new directory in wp-content.
$paths[] = $this->get_default_path();
// If that didn't work then fallback to a new directory in uploads.
$paths[] = $this->get_fallback_path();
// Loop through possible paths, use the first one that exists/can be created and is writable.
foreach ($paths as $path) {
if (wp_mkdir_p($path) && file_exists($path) && wp_is_writable($path)) {
// Also handles fixing perms / directory already exists.
$this->path = $path;
break;
}
}
}