Quick Download Button Shortcode

Below, you’ll find a detailed guide on how to add the Quick Download Button Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Quick Download Button Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Quick Download Button Plugin and the shortcodes it provides:

Plugin Icon
Quick Download Button

"Quick Download Button is a user-friendly WordPress plugin that enables seamless file downloads. It provides a simple, one-click download button, enhancing user experience on your site."

★★★★✩ (9) Active Installs: 4000+ Tested with: 6.0.6 PHP Version: 5.6
Included Shortcodes:
  • [quick_download_button]

Quick Download Button [quick_download_button] Shortcode

The Quick Download Button shortcode is a versatile tool for WordPress sites, allowing users to customize the download button. It allows customization of button title, file size, URL, and extension. It also provides options for external URL, opening in a new window, wait time, background color, font color, icon color, message, button type, border width, style, color, radius, alignment, padding, user role, and validation message. The shortcode fetches the attachment id from the URL and passes it to the plugin download file. It sets the URL to external if the URL value is empty. It also allows the opening of the download in a new window. It provides options for setting wait time, color of the button, font, and icon. It allows customization of the message displayed on the button, type of the button, border width, style, color, radius, alignment, and padding. It also allows setting the user role and validation message. In summary, this shortcode provides extensive customization options for the download button, enhancing user experience and website functionality.

Shortcode: [quick_download_button]

Parameters

Here is a list of all possible quick_download_button shortcode parameters and attributes:

  • title – Sets the text of the download button.
  • file_size – Specifies the size of the downloadable file.
  • url – Sets the URL of the downloadable file.
  • extension – Sets the file extension of the downloadable file.
  • extension_text – Displays the file extension on the button.
  • url_external – Sets an external URL for the download.
  • open_new_window – Opens the download link in a new window.
  • wait – Sets a delay before the download begins.
  • color_bg – Specifies the background color of the button.
  • color_font – Specifies the font color of the button.
  • color_icon_dark – Sets the download icon color to dark.
  • msg – Sets the message displayed while waiting for download.
  • button_type – Specifies the size of the download button.
  • border_width – Sets the width of the button border.
  • border_style – Specifies the style of the button border.
  • border_color – Sets the color of the button border.
  • border_radius – Specifies the radius of the button border.
  • align – Sets the alignment of the download button.
  • padding – Specifies the padding around the download button.
  • user_must_be – Sets the user role required to download the file.
  • validate – Validates the download request before processing.
  • validate_msg – Sets the message displayed when validation fails.

Examples and Usage

Basic example – A shortcode that uses the default parameters to create a download button.

[quick_download_button /]

Advanced examples

Customizing the download button’s title, file size, and URL, while keeping the remaining parameters at their default values.

[quick_download_button title="Download My Ebook" file_size="5MB" url="http://example.com/my-ebook.pdf" /]

Creating a download button with a custom title, file size, URL, and also specifying that it should open in a new window. The button’s background and font colors are also customized.

[quick_download_button title="Download My Ebook" file_size="5MB" url="http://example.com/my-ebook.pdf" open_new_window="true" color_bg="#000000" color_font="#ffffff" /]

Displaying a download button with a custom title, URL, and a message to display while the file is downloading. The button is also set to validate the user before allowing the download.

[quick_download_button title="Download My Ebook" url="http://example.com/my-ebook.pdf" msg="Downloading, please wait..." validate="true" validate_msg="Please log in to download." /]

PHP Function Code

In case you have difficulties debugging what causing issues with [quick_download_button] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'quick_download_button', array( $this, 'quick_download_button_shortcode' ) );

Shortcode PHP function:

function quick_download_button_shortcode( $attr ) {

		$this->a = shortcode_atts(
			array(
				'title'          		=> 'Download',
				'file_size'      		=> '',
				'url'            		=> '',
				'extension'      		=> '',
				'extension_text' 		=> '0',
				'url_external'   		=> '',
				'open_new_window'		=> 'false',
				'wait'			 		=> 0,
				'color_bg'				=> null,
				'color_font'			=> null,
				'color_icon_dark'		=> 'true',
				'msg'					=> 'Please wait...',
				'button_type'			=> 'large',
				'border_width'			=> null,
				'border_style'			=> null,
				'border_color'			=> null,
				'border_radius'			=> null,
				'align'					=> null,
				'padding'				=> null,
				'user_must_be'			=> '',
				'validate'		        => false,
				'validate_msg'			=> ''
			),
			$attr
		);

		global $post;
		$this->pid          = $post->ID;
		$this->download_pid = (int) get_option( 'qdbu_quick_download_button_page_id' );

		$this->attachment_id = attachment_url_to_postid( $this->a['url'] );  //get attachment id from URL

		$quick_download_button_url = qdbu_default_url() . '?aid=' . $this->attachment_id; //pass attachment id to plugin download file


		$this->url = ! empty( $this->a['url'] && strpos( $this->a['url'], site_url()) !== false ) ? $quick_download_button_url : $this->a['url_external']; //if url value is empty set url to external url (url_external)

		$this->open_new_window = 'true' === $this->a['open_new_window'] ? 'true' : 'false';

		$this->wait = $this->a['wait'] > 0 ? $this->a['wait'] : 0;

		$this->color_gb = null !==  $this->a['color_bg'] ? $this->a['color_bg'] : null;

		$this->color_font = null !==  $this->a['color_font'] ? $this->a['color_font'] : null;

		$this->color_icon_dark = 'true' ===  $this->a['color_icon_dark'] ? 'true' : 'false';

		$this->msg = !empty($this->a['msg']) && '' !== $this->a['msg'] ? $this->a['msg'] : 'Please wait...';

		$this->button_type = !empty($this->a['button_type']) ? $this->a['button_type'] : 'large';

		$this->border_width = !null !==  $this->a['border_width'] ? $this->a['border_width'] : null;

		$this->border_style = !null !==  $this->a['border_style'] ? $this->a['border_style'] : null;

		$this->border_color = !null !==  $this->a['border_color'] ? $this->a['border_color'] : null;

		$this->border_radius = !null !==  $this->a['border_radius'] ? $this->a['border_radius'] : null;

		$this->padding = !null !==  $this->a['padding'] ? $this->a['padding'] : null;

		$this->align = !null !==  $this->a['align'] ? $this->a['align'] : null;

		$this->user_role = '' !== $this->a['user_must_be'] ? trim(strtolower( $this->a['user_must_be'])) : '';

		$this->validate_msg = '' !== $this->a['validate_msg'] ? esc_attr($this->a['validate_msg']) : 'Please contact the admin.';


		return $this->generate_button();
	}

Code file location:

quick-download-button/quick-download-button/class/shortcode.class.php

Conclusion

Now that you’ve learned how to embed the Quick Download Button Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *