This shortcode is used to download files from given URL. aw2.sideload shortcode also allows you to easily set a downloaded image as featured image, or as part of WooCommerce product image gallery.
attach_to_post | save_to_path‘attach_to_post’ allows you to attach the downloaded file to given post_id, while ‘save_to_path’ allows you to move the file to a specified directory.
It specifies the file URL that you want to download.
If you want to restrict the file uploads to certain file types then you can specify the comma-separated list of extensions using allowed_file_types.
Using attach_to_post with aw2.sideload
attach_to_post allows you to easily download a file/image from given URL and add it to the media library. With this, you can also set the image as featured image of a post or import that to WooCommerce product image gallery
You have following additional attributes that you can use with attach_to_post.
ID of the post to which you want to attach the downloaded file in WordPress. It is required for attach_to_post to work properly.
True | FalseIf set_featured is set to true, it will set the downloaded image to featured image for the post. It can only be used with attach_to_post main attribute
True | FalseIf specified as true, all the downloaded images are saved to WooCommerce product image gallery. It can only be used with attach_to_post main attribute
Examples of using aw2.sideload:
Using attach_to_post to upload an image to the media library.
[aw2.sideload attach_to_post post_id='1' set_featured='true' file_url='http://www.getawesomestudio.com/wp-content/uploads/2015/09/justswipe-1.jpg' set='module.upload' /]
Using woo_product_gal attribute with aw2.upload shortcode
[aw2.sideload attach_to_post post_id='1' woo_product_gal='true' file_url='http://www.getawesomestudio.com/wp-content/uploads/2015/09/justswipe-1.jpg' set='module.upload' /]
It retuns attachment id as well as attachment image URL
array(2) [ "id" => int(4642) "url" => string(59) "http://cdn.dev/wp-content/uploads/2017/04/justswipe-1-2.jpg" ]
Using save_to_path with aw2.sideload
If you want to download the file and move it to a different folder and not make it part of your media library then you can use ‘save_to_path‘. It gives you additional attributes to rename the downloaded file, and resize them if needed.
If you want to download a file outside of uploads dir, you can specify the folder path using dir_path.
If you are using save_to_path as the main attribute then you have to specify the file_name for saving the file.
true| falseIf you are using save_to_path as the main attribute then you have to specify the attach to true for saving the file and folder relative to media uploads folder. This also enables attaching the images t the media library as well.
ID of the post to which you want to attach the downloaded file in WordPress. It is required, if attach is set to true, to work properly.
yes | noBy default when the file is downloaded using aw2.sideload it does not get overwritten for save_to_path. If you want you can set overwrite_file to yes then downloaded file will overwrite existing file.
True | FalseIf specified as true, then images will be resized. It can only be used with save_to_path main attribute
comma separated list of sizes eg. “150×150,350×240”If resize is specified as true, all the downloaded images resized to specified sizes. It can only be used with save_to_path main attribute
True | FalseIf specified as true, all the downloaded images will be cropped to the specified dimensions using center positions. It can only be used with save_to_path main attribute
Examples of using save_to_path:
[aw2.sideload save_to_path file_url='http://www.getawesomestudio.com/wp-content/uploads/2015/09/justswipe-1.jpg' dir_path='downloaded_files' file_name='swiper-logo.jpg' overwrite_file='no' resize='true' crop='false' sizes='150x150,350x250' set='module.upload' /]
It returns the file path of saved file, as well as guessed URL for the file.
array(2) [ "path" => string(35) "downloaded_files/swiper-logo-10.jpg" "url" => string(50) "http://cdn.dev/downloaded_files/swiper-logo-10.jpg" ]
And there’s one thing I keep noticing: Everyone's obsessed with growth hacks.