php8 dirty fix
-
the plugin is not compatible with PHP8
to fix this just replace the function “filter_wp_unique_filename” in wp-content/plugins/do-spaces-sync/dos_class.php
with thispublic function filter_wp_unique_filename($filename) {
// php8 workaround
$upload_dir = wp_upload_dir();
$subdir = $upload_dir['subdir'];
// If this plugin isn't configured, don't interfere
if (empty($this->key) || empty($this->secret) || empty($this->container) || empty($this->endpoint)) {
return $filename;
}
try {
$filesystem = DOS_Filesystem::get_instance($this->key, $this->secret, $this->container, $this->endpoint);
$number = 1;
$new_filename = $filename;
$fileparts = pathinfo($filename);
// If no extension, avoid notices
$base = $fileparts['filename'] ?? $new_filename;
$ext = $fileparts['extension'] ?? '';
$cdnPath = rtrim($this->storage_path,'/') . '/' . ltrim($subdir,'/') . '/' . $new_filename;
// Safety cap to prevent infinite loops
$maxTries = 200;
while ($maxTries-- > 0) {
$exists = false;
try {
$exists = $filesystem->has($cdnPath);
} catch (\Throwable $e) {
// If remote check fails, don't block uploads
return $filename;
}
if (!$exists) break;
$new_filename = $ext !== ''
? ($base . "-$number." . $ext)
: ($base . "-$number");
$number++;
$cdnPath = rtrim($this->storage_path,'/') . '/' . ltrim($subdir,'/') . '/' . $new_filename;
}
return $new_filename;
} catch (\Throwable $e) {
// Anything AWS/Guzzle-related exploding should never kill WordPress uploads
return $filename;
}
}
You must be logged in to reply to this topic.