Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3_UPLOADS_USE_LOCAL not replacing path or basedir #647

Open
knlb opened this issue Aug 4, 2023 · 1 comment
Open

S3_UPLOADS_USE_LOCAL not replacing path or basedir #647

knlb opened this issue Aug 4, 2023 · 1 comment

Comments

@knlb
Copy link

knlb commented Aug 4, 2023

Is there any reason why filter_upload_dir in class-plugin.php still returns the s3 path when S3_UPLOADS_USE_LOCAL is defined?
url and baseurl are replaced with the local directory correctly but path and basedir or not. It's causing some compatibility problems with another plugin, but maybe they're using the wrong field. I'm not quite clear on when to use path/basedir vs url/baseurl, but it seems that they should both be pointed to the local directory when USE_LOCAL is defined as true.

@knlb
Copy link
Author

knlb commented Aug 4, 2023

Seem that the solution is to set the path and basedir back to the original values-

public function filter_upload_dir(array $dirs): array
    {

        $this->original_upload_dir = $dirs;
        $s3_path = $this->get_s3_path();

        $dirs['path'] = str_replace(WP_CONTENT_DIR, $s3_path, $dirs['path']);
        $dirs['basedir'] = str_replace(WP_CONTENT_DIR, $s3_path, $dirs['basedir']);

        if (!defined('S3_UPLOADS_DISABLE_REPLACE_UPLOAD_URL') || !S3_UPLOADS_DISABLE_REPLACE_UPLOAD_URL) {

            if (defined('S3_UPLOADS_USE_LOCAL') && S3_UPLOADS_USE_LOCAL) {
                $dirs['url'] = str_replace($s3_path, $dirs['baseurl'] . '/s3/' . $this->bucket, $dirs['path']);
                $dirs['baseurl'] = str_replace($s3_path, $dirs['baseurl'] . '/s3/' . $this->bucket, $dirs['basedir']);
                $dirs['path'] = $this->original_upload_dir['path'];
                $dirs['basedir'] = $this->original_upload_dir['basedir'];
            } else {
                $dirs['url'] = str_replace($s3_path, $this->get_s3_url(), $dirs['path']);
                $dirs['baseurl'] = str_replace($s3_path, $this->get_s3_url(), $dirs['basedir']);
            }
        }

        return $dirs;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant