Skip to content

Commit c4ef623

Browse files
committed
use original folders
1 parent 56e8cd0 commit c4ef623

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-download-sync.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,13 @@ function ( $val ) use ( $media ) {
185185
/**
186186
* Download an attachment source to the file system.
187187
*
188-
* @param int $attachment_id The attachment ID.
189-
* @param string $source The optional source to download.
188+
* @param int $attachment_id The attachment ID.
189+
* @param string $source The optional source to download.
190+
* @param string|null $date The date of the attachment to set storage folders.
190191
*
191192
* @return array|\WP_Error
192193
*/
193-
public function download_asset( $attachment_id, $source = null ) {
194+
public function download_asset( $attachment_id, $source = null, $date = null ) {
194195
require_once ABSPATH . 'wp-admin/includes/image.php';
195196
require_once ABSPATH . 'wp-admin/includes/media.php';
196197
if ( empty( $source ) ) {
@@ -200,7 +201,7 @@ public function download_asset( $attachment_id, $source = null ) {
200201
$file_name = basename( $source );
201202
try {
202203
// Prime a file to stream to.
203-
$upload = wp_upload_bits( $file_name, null, 'temp' );
204+
$upload = wp_upload_bits( $file_name, null, 'temp', $date );
204205
if ( ! empty( $upload['error'] ) ) {
205206
return new \WP_Error( 'download_error', $upload['error'] );
206207
}

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-storage.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ public function sync( $attachment_id ) {
207207
if ( 'cld' !== $previous_state ) {
208208
$this->remove_local_assets( $attachment_id );
209209
}
210-
$this->download->download_asset( $attachment_id, $url );
210+
$date = get_post_datetime( $attachment_id );
211+
$this->download->download_asset( $attachment_id, $url, $date->format('Y/m') );
211212
}
212213

213214
$this->sync->set_signature_item( $attachment_id, 'storage' );

0 commit comments

Comments
 (0)