Shortcodes allow you to perform predefined actions within your WordPress content automatically. For example, instead of creating and sending a private download link to each customer manually, you can use a shortcode to auto-generate and display the link on the download page.
Below is the list of all the shortcodes available on Prevent Direct Access Gold and its extensions.
- Prevent Direct Access Gold
- Protect WordPress Pages & Posts
- WordPress Amazon S3 – Wasabi Smart File Uploads
- How to use shortcode
Prevent Direct Access (PDA) Gold
Generate Private Download Links
The [pda_private_link]
shortcode allows you to create a private link for downloading any file protected by the PDA Gold plugin.
It comes in handy when you want to create private and expiring access to your users. For instance, a private download link to your giveaway ebook, which expires after one click, will be sent to your users after they subscribe to your email newsletter.
Example Shortcode
[pda_private_link file_id=1 download_limit=1 download_expiry=1]
Available Attributes
The following attributes are shown within the sample shortcode above.
- file_id (required)
The ID of your protected file. You can get the ID number by hovering over the desired file’s title.
- download_limit (optional)
The number of times (clicks) users can access this private link.
- download_expiry (optional)
The number of minutes after that the private download link will expire.
A few things are worth noting:
- [pda_private_link] Invalid attributes or values error message will display if any of the file_id, download_limit, or download_expiry attributes is invalid.
- Decimal values will automatically be rounded up.
- Private links generated by shortcode don’t show under our protection configuration popup and will be deleted every 24 hours after expiration.
List accessible files
The [pda_list_files]
shortcode allows you to display all protected files a user can access in the frontend. Depending on the user role or username, the plugin will display all files that are accessible to them.
Example Shortcode
[pda_list_files orderby="name" order="ASC" max_files_per_query=10000]
Available Attributes
The following attributes are shown within the sample shortcode above.
- orderby (optional) – Define the way to sort files
none
– No orderID
– Order by file IDauthor
– Order by authortitle
– Order by file titlename
– Order by file slug (default)date
– Order by datemodified
– Order by last modified daterand
– Random order
- order (optional) – Designates the ascending or descending order of the “orderby” parameter
ASC
(default) – ascending order from lowest to highest values (1, 2, 3; a, b, c)DESC
– descending order from highest to lowest values (3, 2, 1; c, b, a)
- max_files_per_query (optional) – The maximum number of protected files that our plugin will get per query. The larger number, the slower query speed. The default value is 100000. You use this attribute only when the performance of your site is affected due to the shortcode.
Protect WordPress Pages & Posts (PPP)
The [ppp_private_link]
shortcode allows you to create private access links from anywhere on your site.
Example Shortcode
[ppp_private_link post_id=1 access_limit=1 access_expiry=1]
Attributes
The following attributes are shown within the sample shortcode above.
- post_id (required)
The ID of the protected content. You can get the ID number by hovering over the desired post title.
- access_limit (optional)
The number of clicks users can access this private link.
- access_expiry (optional)
The number of minutes after that the private link will expire.
A few things are worth noting:
- “The private link cannot be generated due to invalid attribute value” error message will display if any of the post_id, access_limit, or access_expiry attributes is invalid or the post is unprotected.
- Decimal values will automatically be rounded up.
Since version 2.0.1, private links generated by shortcode will expire after one month by default, even though access_expiry isn’t added to the shortcode. You can change this default value by setting our PPP_SC_DEFAULT_TIME_LIMIT
constant in the wp-config.php file.
define( 'PPP_SC_DEFAULT_TIME_LIMIT', time-in-munutes);
WordPress Amazon S3 – Wasabi Smart File Uploads
The [ssu_upload]
shortcode allows users to upload files on the frontend website to Amazon S3 or Wasabi bucket directly.
Example Shortcode
[ssu_upload button="Upload to S3"]
Attributes
The following attributes are shown within the sample shortcode above.
- description: the description of your upload form
- button: the upload button’s text
- Default: Upload to S3
- error_msg: The message shown when users failed to upload files
- Default: An unexpected error occurred while uploading your file, please try again later.
- success_msg: The message shown when users upload files successfully
- Default: File is uploaded successfully as follows
- class: Allow you to apply a style to the upload button and match your custom theme
Make file public
To make the files uploaded via [ssu_upload]
shortcode public, simply add the following code snippet to your (child) theme’s functions.php file.
add_filter( 'ssu_shortcode_public_acl', '__return_true' );
Define the upload folder
To upload files via [ssu_upload]
shortcode to a specific folder, simply add the following code snippet to your (child) theme’s functions.php file.
//Upload files to random folder add_filter( 'ssu_shortcode_upload_folder', function() { return 'random'; } );
Please note that if you define the SSU_FOLDER
with a non-existing name, our plugin will create a new folder with this name for you.
Display S3 file URLs
To display S3 URLs of uploaded files to your users, simply add the following code snippet to your (child) theme’s functions.php file or Code Snippets plugin.
add_filter( 'ssu_display_file_url_on_frontend', '__return_true' );
How to use shortcode
Shortcodes can be used anywhere within WordPress, including pages, posts, and sidebar widgets. Simply modify the example shortcode as your desired and paste it into the content editor.
After saving the changes, you can see the item that shortcode intends to display from the frontend.
How to get file ID
Go to Media Library List View and hover over the desired file’s title. A link containing the file ID will be shown at the bottom of the screen. In the example below, you can see that the file ID is 2454.
How to get post ID
Find the id of a post by simply hovering over its title. A link containing the post id will be shown at the bottom of the screen. In the example below, you can see the post ID is 1.