Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: PMPro Customizations
- Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-customizations/
- Description: Customizations for Paid Memberships Pro
- Version: 0.1
- Author: You
- Author URI: https://facebook.com/You
- */
- // NOTE: Copy this code and paste it at: wp-content/plugins/pmpro-customizations/pmpro-customizations.php
- // You can add more modification here
- /* PMPro Protect Download */
- function my_pmpro_getfile()
- {
- if(isset($_REQUEST['pmpro_getfile']))
- {
- global $wpdb;
- //prevent loops when redirecting to .php files
- if(!empty($_REQUEST['noloop']))
- {
- status_header( 500 );
- die("This file cannot be loaded through the get file script.");
- }
- $uri = $_REQUEST['pmpro_getfile'];
- if($uri[0] == "/")
- $uri = substr($uri, 1, strlen($uri) - 1);
- /*
- Remove ../-like strings from the URI.
- Actually removes any combination of two or more ., /, and \.
- This will prevent traversal attacks and loading hidden files.
- */
- $uri = preg_replace("/[\.\/\\\\]{2,}/", "", $uri);
- //edit to point at your protected directory
- $new_uri = "downloads/" . $uri;
- $filename = ABSPATH . $new_uri;
- $pathParts = pathinfo($filename);
- //remove params from the end
- if(strpos($filename, "?") !== false)
- {
- $parts = explode("?", $filename);
- $filename = $parts[0];
- }
- //add index.html if this is a directory
- if(is_dir($filename))
- $filename .= "index.html";
- //only checking if the file is pulled from outside the admin
- if(!is_admin())
- {
- //non-members don't have access (checks for level 2 or 3)
- if(!pmpro_hasMembershipLevel())
- {
- //nope
- //header('HTTP/1.1 503 Service Unavailable', true, 503);
- //echo "HTTP/1.1 503 Service Unavailable";
- wp_redirect(wp_login_url());
- exit;
- }
- }
- //if file is not found, die
- if(!file_exists($filename))
- {
- status_header( 404 );
- nocache_headers();
- die("File not found.");
- }
- //if blacklistsed file type, redirect to it instead
- $basename = basename($filename);
- $parts = explode('.', $basename);
- $ext = strtolower($parts[count($parts)-1]);
- //build blacklist and allow for filtering
- $blacklist = array("inc", "php", "php3", "php4", "php5", "phps", "phtml");
- $blacklist = apply_filters("pmpro_getfile_extension_blacklist", $blacklist);
- //check
- if(in_array($ext, $blacklist))
- {
- //add a noloop param to avoid infinite loops
- $uri = add_query_arg("noloop", 1, $uri);
- //guess scheme and add host back to uri
- if(is_ssl())
- $uri = "https://" . $_SERVER['HTTP_HOST'] . "/" . $uri;
- else
- $uri = "http://" . $_SERVER['HTTP_HOST'] . "/" . $uri;
- wp_redirect($uri);
- exit;
- }
- require_once(dirname(__FILE__) . '/../paid-memberships-pro/classes/class.mimetype.php');
- //otherwise show it
- $mimetype = new pmpro_mimetype();
- header("Content-type: " . $mimetype->getType($filename));
- header("Content-Disposition: attachment; filename=" . basename($filename) . ";"); /*make sure download file name not random*/
- readfile($filename);
- exit;
- }
- }
- add_action("init", "my_pmpro_getfile");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement