WP-DownloadManager Shortcodes

Below, you’ll find a detailed guide on how to add the WP-DownloadManager Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WP-DownloadManager Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the WP-DownloadManager Plugin and the shortcodes it provides:

Plugin Icon
WP-DownloadManager

"WP-DownloadManager is a versatile WordPress plugin designed to manage and track file downloads on your website. It offers an organized way to share files with your audience."

★★★★✩ (35) Active Installs: 4000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [page_download]
  • [download]

WP-DownloadManager [page_download] Shortcode

The WP-DownloadManager shortcode is a function that displays a download page based on a particular category. The shortcode is: [page_download]. It takes a ‘category’ attribute and returns a download page for that category.

Shortcode: [page_download]

Parameters

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

  • category – Specifies the category of downloads to display

Examples and Usage

Basic example – Utilizing the shortcode to display downloads from a specific category by referencing the category ID.

[page_download category=1 /]

Advanced examples

Using the shortcode to display downloads from multiple categories by referencing their IDs. The downloads will be displayed from all the categories whose IDs have been mentioned.

[page_download category="1,2,3" /]

Using the shortcode without a category ID. This will display all downloads regardless of their category.

[page_download /]

Please note that in the above examples, ‘1’, ‘2’, and ‘3’ are placeholders for the actual category IDs. Replace them with the IDs of the categories you want to display downloads from.

PHP Function Code

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

Shortcode line:

add_shortcode( 'page_download', 'download_page_shortcode' );

Shortcode PHP function:

function download_page_shortcode( $atts ) {
	$attributes = shortcode_atts( array( 'category' => 0 ), $atts );
	return downloads_page( $attributes['category'] );
}

Code file location:

wp-downloadmanager/wp-downloadmanager/wp-downloadmanager.php

WP-DownloadManager [download] Shortcode

The WP-DownloadManager shortcode allows users to download files from specific categories. It supports single or multiple IDs and categories, and allows sorting by file ID. The shortcode attributes include ‘id’, ‘category’, ‘display’, ‘sort_by’, ‘sort_order’, and ‘stream_limit’. If no ‘id’ or ‘category’ is specified, a message prompts users to visit the post to download the file.

Shortcode: [download]

Parameters

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

  • id – Identifies the specific file to download.
  • category – Specifies the category of the files to display.
  • display – Controls the display mode (default is ‘both’).
  • sort_by – Determines the sorting parameter (default is ‘file_id’).
  • sort_order – Sets the sorting order, ascending or descending (default is ‘asc’).
  • stream_limit – Sets the maximum number of streams (default is 0).

Examples and Usage

Basic example – The shortcode displays a download link for a specific file by referencing its ID.

[download id=1 /]

Advanced examples

Using the shortcode to display a download link for multiple files by referencing their IDs. The files are separated by commas.

[download id="1,2,3" /]

Using the shortcode to display a download link for files under a specific category. The category is referenced by its ID.

[download category=1 /]

Using the shortcode to display a download link for files under multiple categories. The categories are referenced by their IDs and separated by commas.

[download category="1,2,3" /]

Using the shortcode to display download links for files, sorted by file ID in descending order.

[download sort_by="file_id" sort_order="desc" /]

Using the shortcode to limit the number of downloads for a file.

[download id=1 stream_limit=10 /]

Using the shortcode to display a download link for a file, specifying the display option. The options are ‘title’, ‘icon’, ‘both’, ‘none’.

[download id=1 display="icon" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'download', 'download_shortcode' );

Shortcode PHP function:

function download_shortcode( $atts ) {
	$attributes = shortcode_atts( array( 'id' => 0, 'category' => 0, 'display' => 'both', 'sort_by' => 'file_id', 'sort_order' => 'asc', 'stream_limit' => 0 ), $atts );
	if(!is_feed()) {
		$conditions = array();
		$id = $attributes['id'];
		$category = $attributes['category'];

		// To maintain backward compatibility with [download=1].
		if( ! $id && ! empty( $atts[0] ) ) {
			$id = trim( $atts[0], '="\'' );
		}

		if( $id !== 0 ) {
			if( strpos($id, ',') !== false ) {
				$ids = array_map( 'intval', explode( ',', $id ) );
				$conditions[] = 'file_id IN (' . implode( ',', $ids ) . ')';
			} else {
				$conditions[] = 'file_id = ' . (int) $id;
			}
		}
		if( $category !== 0 ) {
			if( strpos( $category, ',' ) !== false ) {
				$categories = array_map( 'intval', explode( ',', $category ) );
				$conditions[] = 'file_category IN (' . implode( ',', $categories ) . ')';
			} else {
				$conditions[] = 'file_category = ' . (int) $category;
			}
		}
		if( $conditions ) {
			return download_embedded( implode( ' AND ', $conditions ), $attributes['display'], $attributes['sort_by'], $attributes['sort_order'], $attributes['stream_limit'] );
		}

		return '';
	}

	return __( 'Note: There is a file embedded within this post, please visit this post to download the file.', 'wp-downloadmanager' );
}

Code file location:

wp-downloadmanager/wp-downloadmanager/wp-downloadmanager.php

Conclusion

Now that you’ve learned how to embed the WP-DownloadManager Plugin shortcodes, 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 *