1. Home
  2. Knowledge Base
  3. Developer Docs
  4. Action and Filter Reference

Action and Filter Reference

Download Monitors comes with various actions and filters that allow you to hook into certain events or alter certain variables. You can read more about WordPress Actions here and about WordPress Filters here.

You will need to add these actions and/or filters in the functions.php file of your child theme so you will not lose any of your work when there are any updates.

Action

You will need to utilize the following syntax for implementing custom functionality within the Download Monitor framework: add_action( 'hook', 'callback' ); . In this case, hook represents the designated Download Monitor hook, while callback denotes the function crafted by you. You need to use this when there is a need to extend or modify the standard behavior of the associated feature.

dlm_downloadingTriggered when a file is downloaded by a user. Passes $download and $version.
dlm_options_startTriggered at the start of the admin meta box for adding your own options.
dlm_options_endTriggered at the end of the admin meta box for adding your own options.
dlm_save_meta_boxesTriggered on save.


Here is an example:

add_action( 'dlm_downloading', 'custom_downloading_function',15, 3 );

function custom_downloading_function($download, $version, $file_path){
// Do stuff here based on $download, $version and $file_path
}

 Filters

You need to use the following code structure: add_filter( 'hook', 'callback' );. In this case, hook denotes the designated Download Monitor hook, and callback refers to the user-created function associated with the respective filter. This function is intended to alter the data parsed by the filter, serving as a means to manipulate the data as required.

dlm_404_redirectReturn a URL to redirect somewhere if the link is a 404. Default is false.
dlm_access_denied_redirectReturn a URL to redirect somewhere if the user cannot access a file. Default is false.
dlm_can_downloadTrue if the user has permission to access the file. Can be used by third-party plugins. Passes $download and $version.
dlm_do_not_forceTrue if you want to redirect to the download instead of forcing it. Passes $download and $version.
dlm_placeholder_image_srcFiltered URL to the placeholder image for download thumbnails.
dlm_download_get_the_download_linkFilter for the download URLs.
dlm_shortcode_download_idUsed in shortcodes to filter the download ID if needed.
dlm_cpt_dlm_download_argsArray of args used to register the dlm_download custom post type.
dlm_cpt_dlm_download_supportsAs above but for the ‘supports’ var only.
dlm_cpt_dlm_download_version_argsArray of args used to register the dlm_download_version custom post type.
download_monitor_settingsFilter for changing core settings.
dlm_widget_downloads_list_startBefore the widget list of downloads. Default is <ul class="dlm-downloads">
dlm_widget_downloads_list_endAfter the widget list of downloads. Default is </ul>
dlm_widget_downloads_list_item_startBefore each item in the download widget. Default is <li>
dlm_widget_downloads_list_item_endAfter each item in the download widget. Default is </li>
dlm_hide_meta_versionTrue if you want to hide the meta version.
dlm_do_xhrFalse in order to get our plugin to not use AJAX


Here is an example:

add_filter( 'dlm_404_redirect', 'custom_redirect_function', 15, 1 );

function custom_redirect_function( $redirect ) {
   return 'https://google.com';
}
Was this article helpful?
Start Protecting your WordPress Downloads

Protect and track downloads on WordPress... What are you waiting for?