Created
April 11, 2020 17:44
-
-
Save taricco/47272b87d9ee8b876b48efd91ac95a3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_filter( 'wp_handle_upload_prefilter', function ( $file ) { | |
| $uploads = wp_upload_dir(); | |
| $use_yearmonth = get_option( 'uploads_use_yearmonth_folders' ); | |
| if ( boolval( $use_yearmonth ) ) { | |
| // if upload to year month based folders is enabled check current target | |
| $year = date( 'Y' ); | |
| $month = date( 'm' ); | |
| $target = $uploads['path'] . DIRECTORY_SEPARATOR . $year . DIRECTORY_SEPARATOR . $month . DIRECTORY_SEPARATOR . $file['name']; | |
| } else { | |
| // uploads dir | |
| $target = $uploads['path'] . DIRECTORY_SEPARATOR . $file['name']; | |
| } | |
| if ( file_exists( $target ) ) { | |
| $file['error'] = 'File with the same name already exists. Either overwrite/replace the file via FTP, or rename your file before uploading. Remember to FTP overwrite/replace the @2x version of the image file if needed.'; | |
| } | |
| return $file; | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment