WordPress Document Manager – How to send an email after download

Recently someone came to me with a problem, they needed to fire off an email from the popular wordpress plugin Smarty Pants Client Document Manager. The plugin did not have that default functionality but it does supply the hooks to do so.

To attack this issue we needed to find two hooks

“sp_download_file_after_query” Which fires after a user has downloaded a file

“sp_cdm_settings_email” which adds a system email to the settings page

In the email settings function we are just creating a simple email that is integrated into the smarty email editor.

In the function we created for the download you can see how we took the file array and from that array got information about the file owner, project owner and current user. With that information we can take the content from the email we created and do anything we want with it. In this instance I’m taking the file owner and sending them a notification that someone has downloaded a file.

Since we built this into the email manager you have full use of the email shortcodes, so that makes this method versatile to do pretty much anything from emailing to submitting information to 3rd party APIs. Check out the plugin here and the code below.