How to correctly detect accessing wp-content/uploads?
Not sure if this is a stupid question or not; however, I've been trying to detect when a user accesses a PDF. I want to be able to know how often a user is accessing specific PDF files. I have been playing around with the 'template_redirect' hook, but the below code doesn't seem to be functioning.
function detect_access() {
$server_request = $_SERVER['REQUEST_URI'];
if ( strpos($server_request, '/wp-content/uploads') !== false ) {
wp_redirect( home_url('/') );
exit;
}
}
I would really appreciate the help, is there a hook that deals with this issue/another solution I have been blind to? Cheers!
Topic template-redirect plugin-development hooks pdf plugins Wordpress
Category Web