Almost everybody who is working with WordPress on higher level, and is using it behind borders of simple blogging website system definitely knows plugin Advanced Custom Fields (ACF in following text). ACF is a WordPress plugin which allows you to add extra content fields to your WordPress edit screens. These extra content fields are more commonly referred to as Custom Fields and can allow you to build website’s faster and educate your client’s quicker.
There are many fields available for you to extend your WordPress functionality in free version, and many more “advanced” ones in PRO version. Everything is very simple and intuitive and it is one of my favorite plugins that I am using on all websites. One that is important for this plugin is File field, I’m using file field to create attachment properties for custom posts to provide “post attachment” functionality to users publishing their posts.
This plugin is gathering files attached to the posts using mentioned ACF File field and putting them into one ZIP archive which can be downloaded then.
One of my customers asked for functionality on their website:
“We are publishing documents to official desk during whole year. Once a year we have to send a summary to 3rd party. That summary have to contain all attachments from all posts we have published during last year.”
So that was starting point a customer needs. So I’ve decided to follow one the best practice Don’t touch WordPress core and use its extensibility by plugins and create one for this purpose. Plugin should add some tool available to website admins to give them possibility to specify posts and grab all attachments from them, put them into ZIP file and download it.
Plugin WP Attachments Download #
- GitHub – You can find all source codes. versions history and use issues reporting on the GitHub.
- WordPress plugins repository – You can install directly from your WordPress admin or download from public repository
Plugin installation from WordPress admin
All you need is just to download/install and activate it in Plugins then it can be found under Tools -> Attachments. New WordPress plugin was created following all best practices described in Developer Handbook and built using awesome Boilerplate Generator. It provides functionality only in admin area to all users with permissions edit_posts.
Plugin form in WordPress administration tools
Downloading attachments #
Form is quite intuitive and simple but you can find some instruction how to use it here. As mentioned in its header you just specify post types, range of publish dates and ACF file group if there are more of them. Every time you change values in input fields, preview of data is generated in preview block over download button which is disabled until there is something to download.
Preview with nothing to download
Preview with available download
Once you can click Download button archive file is prepared from all posts and attachments fitting parameters, when prepared to download it will automatically prompt to to save the file. Until you leave plugin screen you can also use download link in completion info block under Download button.
Download file prompt
Successful completion block
And that’s all any extra magic, you can see the code used in plugin and tell me if you found something that you would write better way.
Reporting issues #
If you find this plugin useful and started to use it, maybe you can find some issues or problem with it. Please help make it better by reporting issues. The best channel for it is GitHub Issues or you can use one of contacts to report directly to me.