Title: [Plugin: ThreeWP Broadcast] Broadcast CDN attachments
Last modified: August 20, 2016

---

# [Plugin: ThreeWP Broadcast] Broadcast CDN attachments

 *  [flynsarmy](https://wordpress.org/support/users/flynsarmy/)
 * (@flynsarmy)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-threewp-broadcast-cdn-support-patch/)
 * 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.
    Change
 *     ```
       if ( ! 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, 'http://'.$s3_info['bucket'].'/'.$s3_info['key'], $post_id );
       }
       ```
   
 * [http://wordpress.org/extend/plugins/threewp-broadcast/](http://wordpress.org/extend/plugins/threewp-broadcast/)

Viewing 1 replies (of 1 total)

 *  [isay](https://wordpress.org/support/users/isay/)
 * (@isay)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-threewp-broadcast-cdn-support-patch/#post-3017509)
 * Hi there flynsarmy!
 * This is nearly exactly what I need to do, only I use the **w3-total-cache** plugin.
   [I described my problem here](http://wordpress.org/support/topic/plugin-w3-total-cache-trigger-upload-image-to-cdn).
 * Any ideas how I do the equivalent of `$attachment_data->post_custom['amazonS3_info']`
   in your code above?
 * Thank you very much for your help!
 * //Mike

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: ThreeWP Broadcast] Broadcast CDN attachments’ is closed to new
replies.

 * ![](https://ps.w.org/threewp-broadcast/assets/icon.svg?rev=1013783)
 * [Broadcast](https://wordpress.org/plugins/threewp-broadcast/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/threewp-broadcast/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/threewp-broadcast/)
 * [Active Topics](https://wordpress.org/support/plugin/threewp-broadcast/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/threewp-broadcast/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/threewp-broadcast/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [isay](https://wordpress.org/support/users/isay/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-threewp-broadcast-cdn-support-patch/#post-3017509)
 * Status: not resolved