Changeset 3482820
- Timestamp:
- 03/15/2026 01:18:07 AM (2 weeks ago)
- Location:
- quick-download-button/trunk
- Files:
-
- 3 edited
-
class/download.class.php (modified) (2 diffs)
-
quick-download-button.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
quick-download-button/trunk/class/download.class.php
r2540789 r3482820 21 21 */ 22 22 public function get_full_path() { 23 $this->file_url = wp_get_attachment_url( $this->attachment_id );24 23 $this->attachment_title = get_the_title( $this->attachment_id ); 25 24 $this->file_url = get_attached_file( $this->attachment_id ); 26 25 27 if ( file_exists( $this->file_url ) ) { 28 29 return esc_url( $this->file_url ); 26 if ( $this->file_url && file_exists( $this->file_url ) ) { 27 return $this->file_url; 30 28 } 31 29 return ''; … … 38 36 */ 39 37 public function file_from_url() { 38 $file_path = $this->get_full_path(); 39 40 if ( empty( $file_path ) ) { 41 wp_die( 'File not found.', 'Download Error', array( 'response' => 404 ) ); 42 } 43 40 44 header( 'Content-Description: File Transfer' ); 41 45 header( 'Content-Type: application/octet-stream' ); 42 header( 'Content-Disposition: attachment; filename="' . basename( $ this->get_full_path()) . '"', true, 200 );46 header( 'Content-Disposition: attachment; filename="' . basename( $file_path ) . '"', true, 200 ); 43 47 header( 'Expires: 0' ); 44 48 header( 'Cache-Control: must-revalidate' ); 45 49 header( 'Pragma: public' ); 46 header( 'Content-Length: ' . filesize( $ this->get_full_path()) );47 readfile( $ this->get_full_path());50 header( 'Content-Length: ' . filesize( $file_path ) ); 51 readfile( $file_path ); 48 52 exit; 49 53 } -
quick-download-button/trunk/quick-download-button.php
r3001366 r3482820 5 5 * Plugin URI: https://github.com/kusimo/quick-download-button 6 6 * Description: Use to add download button link to post or page. 7 * Version: 1.2. 67 * Version: 1.2.7 8 8 * Author: Abidemi Kusimo 9 9 * -
quick-download-button/trunk/readme.txt
r3001366 r3482820 2 2 Contributors: kusimo 3 3 Donate link: https://www.buymeacoffee.com/kusimo 4 Tags: media download, hide download link, download button4 Tags: download button, file download, download link, countdown timer, media download 5 5 License: GPLv2 or later 6 License URI: http://www.gnu.org/licenses/gpl-2.0.html 7 Requires at least: 3.0.1 8 Tested up to: 6.4.1 9 Stable tag: 1.2.6 10 Requires PHP: 5.6 11 License: GPLv3 12 License URI: http://www.gnu.org/licenses/gpl.html 13 14 Quick download button with block and shortcode support. 6 License URI: https://www.gnu.org/licenses/gpl-2.0.html 7 Requires at least: 5.0 8 Tested up to: 6.7 9 Stable tag: 1.2.7 10 Requires PHP: 7.4 11 12 Add a stylish, customizable download button to any post or page with block and shortcode support. 15 13 16 14 == Description == 17 The Quick Download Button plugin for WordPress allows you to easily integrate a simple but sophisticated download button into your posts and pages. This versatile plugin offers a range of features like a countdown timer, multiple button styles, and the ability to hide or show file size and extension. It supports both WordPress blocks and shortcodes, making it highly adaptable to your website's needs. 18 15 16 **Quick Download Button** makes it easy to add professional download buttons anywhere on your WordPress site. Whether you are sharing PDFs, music, videos, or zip archives, this plugin gives you full control over how your download buttons look and behave. 17 18 **Key Features:** 19 20 * Works with both the **Gutenberg block editor** and the **Classic Editor** (via shortcode) 21 * **4 button styles** — Large, Mid, Small, and Basic 22 * **Countdown timer** — make visitors wait before the download starts 23 * **File size display** — auto-calculated or manually specified 24 * **File type icon** — automatically detected for common file types 25 * **Access control** — restrict downloads by user role or login status 26 * **Hide download links** — protect the real URL from casual inspection 27 * **External URL support** — link to files hosted anywhere 28 * **Force download** — bypass the browser's default open-in-tab behavior 29 * **Open in new tab or same window** 30 * **Custom button colors, borders, padding, and alignment** 31 * **Multisite compatible** 32 * **Optimized loading** — CSS and JS only load on pages that use the button 33 34 **Supported file types for icon display:** 35 `pdf`, `mp3`, `mov`, `zip`, `txt`, `doc`, `xml`, `mp4`, `ppt`, `htm`, `html`, `ps`, `tex`, `csv`, `xlsx`, `pptx`, `js`, `css`, `php`, and common images (`png`, `gif`, `jpg`, `jpeg`, `bmp`). 19 36 20 37 == Installation == 21 1. Upload the quick-download-button folder to the /wp-content/plugins/ directory 22 2. Activate the Delete Quick Download Button plugin through the \'Plugins\' menu in WordPress 23 24 == Features == 25 26 * Display file size and extension. 27 * Create customizable download buttons via shortcode. 28 * Link your download button to any publicly accessible web location. 29 * Support for a wide range of file types including music, video, PDFs, spreadsheets, and more. 30 * Option to hide the download link for added security. 31 * Countdown feature to specify a waiting time before the download starts. 32 * Customizable waiting message for user engagement. 33 * Support for external download links. 34 * Shows download file extension for 'pdf','mp3','mov','zip','txt','doc','xml','mp4','ppt' and images ( png, gif, jpg, jpeg, bmp). 35 * Support for htm, html, ps, tex, xml, txt, csv, xlsx (Microsoft Excel), pptx (Microsoft PowerPoint), js, css, php. 36 * Open external download in new tab or same window. 37 * Force file download. 38 * Access control based on user roles and login status. 39 * WordPress Gutenberg block support for easy integration. 40 41 42 == Basic Usage == 43 44 ** Shortcode ** 45 To add a download button, open the post or page editor and paste the following shortcode example: 46 47 ` 48 [quick_download_button title="Download" url="http://yoursite/wp-content/upload/fileto_download.pdf"] 49 ` 50 Replace the url value with your file's URL. Change the title value to customize the button text. 51 38 39 1. Upload the `quick-download-button` folder to the `/wp-content/plugins/` directory. 40 2. Activate **Quick Download Button** through the 'Plugins' menu in WordPress. 41 3. Use the Gutenberg block or the `[quick_download_button]` shortcode to add download buttons to your content. 42 43 == Basic Usage == 44 45 **Shortcode** 46 47 Paste the shortcode into any post or page: 48 49 `[quick_download_button title="Download" url="https://yoursite.com/wp-content/uploads/file.pdf"]` 50 51 Replace the `url` value with your file's URL and `title` with your preferred button text. 52 53 **Gutenberg Block** 54 55 1. Open the post or page editor and click the **Add Block** icon (+). 56 2. Search for **Download Button** (found under the Media category) and click to insert it. 57 3. Click the button to set its title and click the download icon to select or upload your file. 58 4. Adjust colors, countdown, and file size in the block settings panel on the right. 59 60 To hide the file size in the block editor, add `hide-size` to the **Additional CSS class(es)** field in block settings. 52 61 53 62 == More Shortcode Usage == 54 63 55 ** Open link in a new window ** 56 57 Set open_new_window to true to open the download link in a new tab, or false to open it in the same window. 58 59 ` 60 [quick_download_button title="Download" open_new_window="true" url_external="https://google.com"] 61 ` 62 63 ** Set the button background color (color_bg="#ffc107"), waiting timer (wait=15) and a custom message (msg="Please wait 15 seconds") ** 64 65 ` 66 [quick_download_button title="Download" color_bg="#ffc107" open_new_window="true" wait=15 msg="Please wait 15 seconds" url_external="https://google.com"] 67 ` 68 69 ** Link to an External URL ** 70 71 To use external url, add url_external attribute. 72 73 ` 74 [quick_download_button title="Download" url_external="https://google.com"] 75 ` 76 77 ** Auto Calculate File Size ** 78 79 To have the plugin automatically generate the file size, ensure the file URL is in the WordPress upload directory and set file_size to 1. 80 81 ` 82 [quick_download_button file_size="1" title="Download" url="http://yoursite/wp-content/upload/fileto_download.pdf"] 83 ` 84 85 ** Manually Add File Size ** 86 87 You can manually specify the file size in the file_size attribute. 88 89 ` 90 [quick_download_button file_size="14.5MB" title="Download" url="http://yoursite/wp-content/upload/fileto_download.pdf"] 91 ` 92 93 94 ** Hide File Extension Icon ** 95 96 To display both the file extension icon and text, set extension and extension_text to 1. 97 98 ` 99 [quick_download_button title="Download" filesize="1" extension="0" url="http://yoursite/wp-content/upload/fileto_download.pdf"] 100 ` 101 102 ** Display File Extension Icon and Text ** 103 104 To showcase both the file extension icon and its text, set both the extension and extension_text attributes to 1. 105 106 ` 107 [quick_download_button title="Download" filesize="1" extension="1" extension_text="1" url="http://yoursite/wp-content/upload/fileto_download.pdf"] 108 ` 109 110 ** Using the Gutenberg Block ** 111 112 1. Open the post where you wish to add a download link and click on the 'Add Block' icon (+). 113 2. Look for 'Download Button' under the Media category and click to add it. 114 3. Click on the button to edit its title and the adjacent download icon to upload the file for download. 115 4. Provide a custom title in the text box if desired. The default title is 'Download'. That's it! 116 117 ** Advanced Gutenberg Usage ** 118 To hide the file size in the Gutenberg editor, utilize the 'Additional CSS class(es)' field in the block settings. Add 'hide-size' to this field to apply the effect. 119 120 121 == For Developers: Integrating in a Theme File == 122 123 To incorporate the download button within a theme file, use the following code with your specified attributes and values: 124 125 ` 126 echo do_shortcode('[quick_download_button title="Download" url="http://yoursite/wp-content/upload/fileto_download.pdf"]'); 127 ` 64 **Open in a new window** 65 66 `[quick_download_button title="Download" open_new_window="true" url_external="https://example.com/file.zip"]` 67 68 **Custom color, countdown timer, and wait message** 69 70 `[quick_download_button title="Download" color_bg="#ffc107" wait="15" msg="Please wait 15 seconds..." url_external="https://example.com/file.zip"]` 71 72 **Link to an external URL** 73 74 `[quick_download_button title="Download" url_external="https://example.com/file.zip"]` 75 76 **Auto-calculate file size** 77 78 The file must be in your WordPress uploads directory: 79 80 `[quick_download_button file_size="1" title="Download" url="https://yoursite.com/wp-content/uploads/file.pdf"]` 81 82 **Manually specify file size** 83 84 `[quick_download_button file_size="14.5MB" title="Download" url="https://yoursite.com/wp-content/uploads/file.pdf"]` 85 86 **Hide file extension icon** 87 88 `[quick_download_button title="Download" extension="0" url="https://yoursite.com/wp-content/uploads/file.pdf"]` 89 90 **Show file extension icon and text** 91 92 `[quick_download_button title="Download" extension="1" extension_text="1" url="https://yoursite.com/wp-content/uploads/file.pdf"]` 93 94 **Change button style** 95 96 `[quick_download_button button_type="small" title="Download Now" url_external="https://example.com/file.zip"]` 97 98 Button type options: `large`, `mid`, `small`, `basic` 99 100 **Add a border** 101 102 `[quick_download_button button_type="small" border_width="2" border_style="solid" border_color="black" title="Download Now" url_external="https://example.com/file.zip"]` 103 104 **Round the corners** 105 106 `[quick_download_button button_type="small" border_radius="9" title="Download Now" url_external="https://example.com/file.zip"]` 107 108 **Change icon color** 109 110 `[quick_download_button button_type="large" color_icon_dark="false" color_bg="black" color_font="#FFF" title="Download Now" url_external="https://example.com/file.zip"]` 111 112 **Change alignment** 113 114 `[quick_download_button button_type="small" align="left" title="Download Now" url_external="https://example.com/file.zip"]` 115 116 **Countdown with file size** 117 118 `[quick_download_button button_type="basic" wait="10" msg="Please wait..." file_size="40MB" title="Download Now" url_external="https://example.com/file.zip"]` 119 120 == For Developers: Using in a Theme File == 121 122 `echo do_shortcode('[quick_download_button title="Download" url="https://yoursite.com/wp-content/uploads/file.pdf"]');` 123 124 == Shortcode Attributes == 125 126 | Attribute | Description | Example value | 127 |---|---|---| 128 | `title` | Button label text | `"Download Now"` | 129 | `url` | URL of a file in your WordPress uploads folder | `"https://yoursite.com/wp-content/uploads/file.pdf"` | 130 | `url_external` | URL of a file hosted outside WordPress | `"https://example.com/file.zip"` | 131 | `file_size` | Set to `1` to auto-detect, or enter a value manually | `"1"` or `"14.5MB"` | 132 | `extension` | Show (`1`) or hide (`0`) the file extension icon | `"1"` | 133 | `extension_text` | Show (`1`) the extension as text alongside the icon | `"1"` | 134 | `open_new_window` | Open the link in a new tab (`true`) or same window (`false`) | `"true"` | 135 | `wait` | Seconds to wait before the download link appears | `"15"` | 136 | `msg` | Message shown during the countdown | `"Please wait..."` | 137 | `button_type` | Button style preset | `large` / `mid` / `small` / `basic` | 138 | `color_bg` | Button background color (hex or CSS color name) | `"#ffc107"` | 139 | `color_font` | Button text color | `"#ffffff"` | 140 | `color_icon_dark` | Use dark icon (`true`) or light icon (`false`) | `"false"` | 141 | `border_width` | Border thickness in pixels | `"2"` | 142 | `border_style` | CSS border style | `"solid"` | 143 | `border_color` | Border color | `"black"` | 144 | `border_radius` | Corner rounding in pixels | `"9"` | 145 | `align` | Button alignment | `left` / `center` / `right` | 146 | `padding` | Inner padding (CSS shorthand) | `"10px 20px"` | 147 148 == Frequently Asked Questions == 149 150 = Can this plugin hide (protect) download links? = 151 152 Yes. The plugin can conceal the real download URL from the page source, making it harder for users to grab the direct link without going through the button. 153 154 = Does it work with the Classic Editor? = 155 156 Yes. Use the `[quick_download_button]` shortcode in the Classic Editor just as you would in any text or HTML block. 157 158 = Does it work with the Gutenberg block editor? = 159 160 Yes. Search for **Download Button** in the block inserter (under the Media category). 161 162 = Can it display the file size automatically? = 163 164 Yes, for files stored in your WordPress uploads directory. Set `file_size="1"` in the shortcode or enable it in the block settings panel. 165 166 = Can I set a countdown before the download link appears? = 167 168 Yes. Use the `wait` attribute (number of seconds) and an optional `msg` attribute for the countdown message. Set `msg=""` to hide the message entirely. 169 170 = Can I restrict downloads to logged-in users or specific roles? = 171 172 Yes. Access control based on login status and user roles is supported via the block settings or shortcode. 173 174 = Can I link to files hosted on other websites? = 175 176 Yes. Use the `url_external` attribute for any publicly accessible URL. 177 178 = What file types show an icon? = 179 180 `pdf`, `mp3`, `mov`, `zip`, `txt`, `doc`, `xml`, `mp4`, `ppt`, `htm`, `html`, `ps`, `tex`, `csv`, `xlsx`, `pptx`, `js`, `css`, `php`, and common images (`png`, `gif`, `jpg`, `jpeg`, `bmp`). 181 182 = How do I hide the file size in the Gutenberg block? = 183 184 Add `hide-size` to the **Additional CSS class(es)** field in the block settings sidebar. 128 185 129 186 == Donations == 130 187 131 If you find this plugin helpful and would like to support its ongoing development, please consider [Donate](https://www.buymeacoffee.com/kusimo) 132 133 134 == Documentation == 135 To contribute and improve this plugin please visit the [Git repo](https://github.com/kusimo/quick-download-button). 136 137 == Frequently Asked Questions == 138 139 = Can this plugin be used to hide (protect) download links on my site? = 140 141 Yes, it can. 142 143 = Can I use the plugin in the Classic Editor? = 144 145 Yes, you can use this plugin with shortcodes in the Classic Editor. 146 147 = Can this plugin be used to display download file size on my site? = 148 149 Yes, it displays the download file size. 150 151 = Can I hide the 'Please wait...' message for the countdown timer? = 152 153 For shortcodes, leave the msg attribute blank. Example: 154 ` 155 [quick_download_button button_type="small" msg="" title="Download Now" url_external="http://external-url-here/"] 156 ` 157 158 For blocks, under 'Countdown Settings', select the time to wait (e.g., 15 for 15 seconds) and remove the default message from the message box. 159 160 = What are the shortcode attributes? = 161 162 * 'title' 163 * 'file_size' 164 * 'url' 165 * 'extension' 166 * 'url_external' 167 * 'open_new_window' 168 * 'wait' 169 * 'color_bg' 170 * 'color_font' 171 * 'color_icon_dark' 172 * 'msg' 173 * 'button_type' (large / mid / small / basic ) 174 * 'border_width' 175 * 'border_style' 176 * 'border_color' 177 * 'border_radius' 178 * 'align' 179 * 'padding' 180 181 Change button style with 'button_type': 182 ` 183 [quick_download_button button_type="small" title="Download Now" url_external="http://external-url-here/"] 184 ` 185 186 Add file from your WordPress site with url: 187 ` 188 [quick_download_button button_type="mid" title="Download Now" url="http://yoursite/wp-content/uploads/yourfile.pdf"] 189 ` 190 191 Add border radius with 'border_radius': 192 ` 193 [quick_download_button button_type="small" border_radius="9" title="Download Now" url_external="http://external-url-here/"] 194 ` 195 196 Change icon color with color_icon_dark: 197 ` 198 [quick_download_button button_type="large" color_icon_dark="false" color_bg="black" color_font="#FFF" title="Download Now" url_external="http://external-url-here/"] 199 ` 200 201 Add countdown and wait message with wait and msg: 202 ` 203 [quick_download_button button_type="basic" wait="10" msg="Please wait..." title="Download Now" url_external="http://external-url-here/"] 204 ` 205 206 Manually add file size with file_size: 207 ` 208 [quick_download_button button_type="basic" wait="10" msg="Please wait..." file_size="40MB" title="Download Now" url_external="http://external-url-here/"] 209 ` 210 211 Hide file extension with extension: 212 ` 213 [quick_download_button button_type="basic" extension="0" title="Download Now" url_external="http://external-url-here/"] 214 ` 215 216 Add border style: 217 ` 218 [quick_download_button button_type="small" border_width="2" border_style="solid" border_color="black" title="Download Now" url_external="http://external-url-here/"] 219 ` 220 221 Change alignment with align: 222 ` 223 [quick_download_button button_type="small" align="left" title="Download Now" url_external="http://external-url-here/"] 224 ` 188 If this plugin saves you time and you would like to support its continued development, please consider [buying me a coffee](https://www.buymeacoffee.com/kusimo). Thank you! 189 190 == Documentation & Source Code == 191 192 To report issues or contribute, visit the [GitHub repository](https://github.com/kusimo/quick-download-button). 225 193 226 194 == Screenshots == 227 195 228 1. Download button example (Large button). 229 196 1. Large button style with file size and extension icon. 197 2. Small button style example. 198 3. Countdown timer in action before the download link appears. 199 4. Button styles 200 5. Gutenberg block settings panel. 230 201 231 202 == Changelog == 232 203 233 = 1.2.6 - November 23rd, 2023 = 234 * Optimised resource loading: CSS and JavaScript files are now only loaded when the Quick Download Button is present on the page. 235 236 = 1.2.5 April 19th, 2023 = 237 * Minor fixes of 404 error that occurs when quick download button page is deleted. After deletion of the QDB page, please deactivate and reactive the plugin. 238 239 = 1.2.4 March 13th, 2023 = 240 * Fixed the error nonce did not verify when download link is external URL 241 242 = 1.2.3 August 29th, 2022 = 243 * Control access to download using users' role and logged in. 244 245 = 1.2.0 August 27th, 2022 = 246 * Fixed CSS for the large button so it works with new upgrade. 247 248 = 1.0.9 August 27th, 2022 = 249 * Add 3 extra buttons - small, medium and basic. 250 * Add button alignment - center, left or right. 251 252 = 1.0.8 August 13th, 2022 = 253 * Fixed message not showing up when user is waiting for download. 254 255 = 1.0.5 July 23rd, 2022 = 256 * Add support for multi site. 257 * Add wait time attribute and background color attribute to shortcode. 258 204 = 1.2.7 - March 15, 2025 = 205 * Fixed: Fatal error "ValueError: Path cannot be empty" when using download block with internal files 206 * Technical: Removed incorrect `esc_url()` sanitization that was stripping local file paths 207 * Improved: File paths are now handled correctly for both internal and external downloads 208 209 = 1.2.6 - November 23, 2023 = 210 * Optimized resource loading: CSS and JavaScript files now only load on pages that contain a Quick Download Button. 211 212 = 1.2.5 - April 19, 2023 = 213 * Fixed a 404 error that occurred when the Quick Download Button page was deleted. After deleting the page, deactivate and reactivate the plugin to resolve. 214 215 = 1.2.4 - March 13, 2023 = 216 * Fixed nonce verification failure when the download link is an external URL. 217 218 = 1.2.3 - August 29, 2022 = 219 * Added access control — restrict downloads by user role and login status. 220 221 = 1.2.0 - August 27, 2022 = 222 * Fixed CSS for the large button style to work correctly after the upgrade. 223 224 = 1.0.9 - August 27, 2022 = 225 * Added 3 new button styles: small, medium, and basic. 226 * Added button alignment support: center, left, or right. 227 228 = 1.0.8 - August 13, 2022 = 229 * Fixed the wait message not displaying during the countdown timer. 230 231 = 1.0.5 - July 23, 2022 = 232 * Added multisite support. 233 * Added `wait` and `color_bg` attributes to the shortcode. 259 234 260 235 == Upgrade Notice == 261 236 262 = 1.2.6 - November 23rd, 2023 = 263 * Optimised resource loading: CSS and JavaScript files are now only loaded when the Quick Download Button is present on the page. 264 265 = 1.2.5 April 19th, 2023 = 266 * Minor fixes of 404 error that occurs when quick download button page is deleted. After deletion of the QDB page, please deactivate and reactive the plugin. 267 268 = 1.2.4 March 13th, 2023 = 269 * Fixed the error nonce did not verify when download link is external URL 237 = 1.2.7 = 238 Fixes a fatal download error when using the Gutenberg block with internal files. Upgrade recommended. 239 240 = 1.2.6 = 241 Optimized loading: plugin assets now only load on pages that use the download button, improving page speed for all other pages.
Note: See TracChangeset
for help on using the changeset viewer.