aw2.sideload
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.
Attributes:
- main:
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. - file_url:
It specifies the file URL that you want to download.
- allowed_file_types:
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.
Additional Attributes:
- post_id:
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.
- set_featured:
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 - woo_product_gal:
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.
Additional Attributes:
- dir_path:
If you want to download a file outside of uploads dir, you can specify the folder path using dir_path.
- file_name:
If you are using save_to_path as the main attribute then you have to specify the file_name for saving the file.
- attach:
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. - post_id:
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.
- overwrite_file
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. - resize:
True | FalseIf specified as true, then images will be resized. It can only be used with save_to_path main attribute - sizes:
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 - crop:
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" ]
Other shortcodes
Conditionals (7)
Core (11)
- aw2.run
- aw2.return
- aw2.template
- aw2.module
- aw2.raw
- aw2.get
- aw2.set_array
- aw2.set
- aw2.echo
- aw2.shortcode
- aw2.part
CRM (1)
Database (1)
Design & JavaScript (3)
- aw2.enqueue
- aw2.client
- aw2.spa
E-commerce (1)
Excelsheet (1)
- excel.write_bulk
Form Handling (3)
- aw2.sideload
- aw2.save_form
- aw2.upload
Mailing & SMS (3)
- aw2.subscribe
- aw2.sms
- aw2.wp_mail
PDF (1)
Utility (6)
- aw2.register
- aw2.register_handler
- aw2.reset_password
- aw2.login_handler
- app.restore
- app.backup
Latest Blogs
And there’s one thing I keep noticing: Everyone's obsessed with growth hacks.