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_downloading | Triggered when a file is downloaded by a user. Passes $download and $version. |
dlm_options_start | Triggered at the start of the admin meta box for adding your own options. |
dlm_options_end | Triggered at the end of the admin meta box for adding your own options. |
dlm_save_meta_boxes | Triggered 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_redirect | Return a URL to redirect somewhere if the link is a 404. Default is false. |
dlm_access_denied_redirect | Return a URL to redirect somewhere if the user cannot access a file. Default is false. |
dlm_can_download | True if the user has permission to access the file. Can be used by third-party plugins. Passes $download and $version. |
dlm_do_not_force | True if you want to redirect to the download instead of forcing it. Passes $download and $version. |
dlm_placeholder_image_src | Filtered URL to the placeholder image for download thumbnails. |
dlm_download_get_the_download_link | Filter for the download URLs. |
dlm_shortcode_download_id | Used in shortcodes to filter the download ID if needed. |
dlm_cpt_dlm_download_args | Array of args used to register the dlm_download custom post type. |
dlm_cpt_dlm_download_supports | As above but for the ‘supports’ var only. |
dlm_cpt_dlm_download_version_args | Array of args used to register the dlm_download_version custom post type. |
download_monitor_settings | Filter for changing core settings. |
dlm_widget_downloads_list_start | Before the widget list of downloads. Default is <ul class="dlm-downloads"> |
dlm_widget_downloads_list_end | After the widget list of downloads. Default is </ul> |
dlm_widget_downloads_list_item_start | Before each item in the download widget. Default is <li> |
dlm_widget_downloads_list_item_end | After each item in the download widget. Default is </li> |
dlm_hide_meta_version | True if you want to hide the meta version. |
dlm_do_xhr | False 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';
}