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

Save to subdirectory based on post_date, and fix for Windows #93

Open
scottpoulin opened this issue May 18, 2023 · 0 comments
Open

Save to subdirectory based on post_date, and fix for Windows #93

scottpoulin opened this issue May 18, 2023 · 0 comments

Comments

@scottpoulin
Copy link

To save images based on post_date to subfolder /uploads/year/month rather than current year/month, in file imageUploader.php, function getUploadDir, line 105, was:

if ($this->_uploadDir === null) {
    $this->_uploadDir = wp_upload_dir(date('Y/m', strtotime( $this->post['post_date'] ) ));
}

change to:

if ($this->_uploadDir === null) {
    if ( isset( $this->post['post_date'] ) ) {
        $this->_uploadDir = wp_upload_dir(date('Y/m', strtotime( $this->post['post_date'] ) ));
    } else {
        $this->_uploadDir = wp_upload_dir(date('Y/m', time()));
    }
}

In Windows (at least running WAMP), WP constant DIRECTORY_SEPARATOR is set to '', which is removed when written to the database, resulting in broken URLs like /wp-content/uploads/2023/05imagefilename.jpg instead of /wp-content/uploads/2023/05/imagefilename.jpg. I don't know if this will be the case for all Windows installs, but if you run into issues, just search/replace DIRECTORY_SEPARATOR with '/' in file imageUploader.php.

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