NOTE: The .htaccess file needs to be writable in the wp-content sub-directories.
This is meant to be a simple plugin that lets you:
- Protect files in wp-content (excluding the mu-plugins and plugins folders)
- Use Google Analytics to track access or downloads to files like pdf and doc files
- Run custom code when a file in wp-content is accessed
CAUTION: This plugin may cause your website to load slower if you have pages that include a lot of protected images. Each image that is loaded needs to load WordPress files and check if a user is logged in, if the directory is protected, and run other custom code you may have.
Usage
To protect file downloads select the folders you want to protect in the WP-Content Listener's settings and check the protect checkbox.
To track file downloads you'll need a Google Analytics Universal account. On WP-Content Listener's settings page, select the folders you want to track, click the option to track, and enter your Google Analtyics Universal ID. You can view visits and other stats on the Google Analytics website under Behavior -> Events. The Event will be in the "Files" Category and "Download" action.
To run custom code when a file is accessed or downloaded select the folders you want to run the custom code in the settings. Then write your code and hook into the 'wpcl_before_file_download' action. If you need to protect your files with specific access rules (more than just if the user is logged in or not), hook into the 'wpcl_access_filter' filter.
This plugin did at one time work on IIS, but I cannot offer any support if anything does not currently work. Try at your own risk.
For servers that don't use .htaccess to redirect, you'll basically need to redirect anything going to your protected directory to go to /wpcl-listen-slug/?f=$1 where $1 is the path to the file after relative to your protected directory.
0.4
Added filter to change the directory in which this plugin monitors.
0.3
Updated to be compatible with PHP 7.
0.2
Fix for IIS web.config - changed to redirect file url instead of rewrite.\
Added description on where tracking ends up in Google Analytics.
0.1
Initial release.