Adding an action hook for counting downloads

In the preceding section, we looked at the process of using filter hooks to extend plugins. We can also use action hooks to extend plugins through addons. The process of counting downloads should be initialized just after the user clicks the Download link and before the file download popup is shown on the browser. So, we need an action hook within those two events. Let's modify the wpqpa_file_attachment_download function to include a new action, as shown in the following code:

$file_mime_type = mime_content_type( $file_dir );if( $file_mime_type != '' ){   do_action('wpqpa_before_download_post_attachment',$attachments[0]);   header( 'Cache-Control: public' ); header( 'Content-Description: File Transfer' ...

Get WordPress Development Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.