[Plugin: ThreeWP Broadcast] Broadcast CDN attachments
-
We use Amazon S3 with CloudFront plugin. As a result the copy_attachment() method doesn’t work as expected – no attachments are copied. I whipped up a minor patch to get this happening correctly however then ran into issues with the Scissors Continued plugin which has a wp_insert_attachment() hook. As a result we’re just going to use the handy “Override child post permalinks” option however this patch might help others so here it is:
In ThreeWP_Broadcast.php find the copy_attachment() method.
Changeif ( ! file_exists( $attachment_data->filename_path() ) ) return false; copy( $attachment_data->filename_path(), $upload_dir['path'] . '/' . $attachment_data->filename_base() );
to
//File won't exist on disk for Amazon S3 for WordPress with CloudFront uploads if ( !isset($attachment_data->post_custom['amazonS3_info']) ) { if ( ! file_exists( $attachment_data->filename_path() ) ) return false; copy( $attachment_data->filename_path(), $upload_dir['path'] . '/' . $attachment_data->filename_base() ); }
and change
$attach_id = wp_insert_attachment( $attachment, $upload_dir['path'] . '/' . $attachment_data->filename_base(), $post_id );
to
//File won't exist on disk for Amazon S3 for WordPress with CloudFront uploads if ( !isset($attachment_data->post_custom['amazonS3_info']) ) $attach_id = wp_insert_attachment( $attachment, $upload_dir['path'] . '/' . $attachment_data->filename_base(), $post_id ); else $attach_id = wp_insert_attachment( $attachment, false, $post_id );
For that second code block I wasn’t sure if passing the CDN file URL to wp_insert_attachment() is helpful or not – it didn’t seem to make a difference. Incase it does and I’m just not seeing it, here’s the version where it does:
//File won't exist on disk for Amazon S3 for WordPress with CloudFront uploads if ( !isset($attachment_data->post_custom['amazonS3_info']) ) $attach_id = wp_insert_attachment( $attachment, $upload_dir['path'] . '/' . $attachment_data->filename_base(), $post_id ); else { $s3_info = maybe_unserialize( reset($attachment_data->post_custom['amazonS3_info']) ); $attach_id = wp_insert_attachment( $attachment, 'https://'.$s3_info['bucket'].'/'.$s3_info['key'], $post_id ); }
- The topic ‘[Plugin: ThreeWP Broadcast] Broadcast CDN attachments’ is closed to new replies.