- Contributors: DrewAPicture
- Donate link: http://www.werdswords.com
- Tags: downloads, shortcode, force download
- Requires at least: 3.0
- Tested up to: 3.5.1
- Stable tag: 1.1
- License: GPLv2
This is a WordPress plugin which allows you to wrap file links in a shortcode that will force a download when clicked.
Have you ever linked a PDF, an mp3, image, or other kind of file because you wanted to let people download it but instead it just loads in the browser? This plugin introduces a [download] shortcode which allows you to output links that will tell the browser to download those files!
- A link titled
My Link - With a rewritten URL of
http://yoursite.com/download/my_song.mp3[download label="My Link"]http://yoursite.com/wp-content/uploads/my_song.mp3[/download]
- A rewritten link titled
http://yoursite.com/download/my_song.mp3[download]http://yoursite.com/wp-content/uploads/my_song.mp3[/download]
- A link titled
My Other Link - With an exposed URL of
http://yoursite.com/wp-content/force-download.php?file=uploads/my_other_song.mp3[download label="My Other Link"]http://yoursite.com/wp-content/uploads/my_other_song.mp3[/download]
- An exposed link titled
http://yoursite.com/wp-content/force-download.php?file=uploads/my_other_song.mp3[download]http://yoursite.com/wp-content/uploads/my_other_song.mp3[/download]
echo do_shortcode( '[download label="My Label"]http://example.com/wp-content/uploads/my_song.mp3[/download]' );
- If your server permissions allow it, the plugin will automatically attempt to copy force-download.php to your
/wp-content/directory. - If your server permissions DO NOT allow it, you will need to manually upload the file located in
/download-shortcode/wp-content/force-download.phpto your/wp-content/directory. - By default, forced-download links only support files located in your uploads directory. More about this in Other Notes.
- Upload the entire
download-shortcodefolder to the/wp-content/plugins/directory - The plugin will automatically attempt to copy force-download.php into your
/wp-content/folder, though you may need to upload it manually if your server lacks the necessary permissions. - Activate the plugin through the 'Plugins' menu in the Dashboard.
Currently, this plugin can force downloads for pdf, mp4, mp3, gif, png, jpg and jpeg files
When I click links from the front-end, all I get is a 404 Page Not Found error or a white screen. What gives?
There are two things you should check:
- There may be a problem with the force-download.php script located in your
/wp-content/directory. Try copying the force-download.php file from download-shortcode/inc/force-download.php to your/wp-content/directory. - It is also possible you just need to flush your rewrite rules by visiting the Settings > Permalinks screen in your Dashboard.
Check out the Other Notes section for example functions and filters.
I've uninstalled Download Shortcode but now I have a bunch of broken shortcodes in my posts and pages. How can I hide them?
You can add the following function to your theme's functions.php file to hide all instances of the [download] shortcode in your content.
function hide_download_shortcodes( $attr, $content ) {
return;
}
add_shortcode( 'download', 'hide_download_shortcodes' );
- If you have 'pretty permalinks' enabled via Settings > Permalinks, your links will automatically be rewritten to
http://yoursite.com/download/path/__yourfile - If you don't include a label with your shortcode, the link URL will be displayed instead
If you wish to modify how some aspects of how download shortcodes are displayed or rewritten, there are several filters you can use to accomplish this. These should be added to your theme's functions.php file.
This example filter adds a class of 'downloads' to your links:
function add_download_links_class() {
return 'downloads';
}
add_filter( 'fds_download_link_class', 'add_download_links_class' );
add_filter( 'fds_rewrite_urls', '__return_false' );
This example filter changes the supported directory to /themes/.
function change_download_files_directory() {
return 'themes';
}
add_filter( 'fds_download_files_directory', 'change_download_files_directory' );
Please note, the directory must be located in your /wp-content/ directory.
This example filter changes the rewrite path to http://yoursite.com/members/yourfile.jpg
function change_download_rewrite_path() {
return 'members';
}
add_filter( 'fds_download_rewrite_path', 'change_download_rewrite_path' );
- Add support for WordPress in a subdirectory
- Regenerate pot file to include translatable strings
- TODO: Add Multisite upload directory support
- Complete plugin rewrite
- Introduce URL rewriting if 'pretty permalinks' are enabled
- Add logic to make overwriting/updating/removing force-download.php more automated
- Add
fds_rewrite_urlsfilter to allow disabling URL rewriting - Add
fds_download_rewrite_pathfilter to allow changing the rewrite endpoint - Add
fds_upload_rewrite_pathfilter to allow changing the supported directory - Make the plugin translatable
- Update readme.txt with note about replacing force-download.php in wp-content with the new one
- Remove faulty strlen check on filenames in force-download.php
- Fixes for WSOD issues.
- Fix security vulnerability which exposed php core files to direct download
- Adds phpDoc blocks
- Add
fds_download_link_classfilter to change download link class - Other minor tweaks
- Initial release