Code-Snippets-Functions/Execute a function on a child site/Easy Digital Downloads/restrict-downloads-to-purchase-email.txt

28 lines
633 B
Text

class EDD_Force_Login_And_Email {
function __construct() {
add_action( 'plugins_loaded', array( $this, 'load' ) );
}
public function load() {
add_filter( 'edd_file_download_has_access', array( $this, 'check_access' ), 9999, 3 );
}
public function check_access( $has_access, $payment, $args ) {
if( ! is_user_logged_in() ) {
$has_access = false;
}
$customer = new EDD_Customer( edd_get_payment_customer_id( $payment ) );
if( ! in_array( $args['email'], $customer->emails ) ) {
$has_access = false;
}
return $has_access;
}
}
$GLOBALS['edd_force_login_and_email'] = new EDD_Force_Login_And_Email();