The question often arises: how to count downloads and hide the real link to the file?

To solve the task we need to two things: intercept a click on the link and send the real file to the user by php.

What happens by the click on the fictitious link, pointing to an non-existent page? WordPress inits own core and tries to show 404 page. At this moment, we need to intervene by our function, update download counter, and send the real file. Here is code of such a function: