mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-30 11:42:22 +08:00
https://github.com/easydigitaldownloads/library/blob/master/_misc/restrict-downloads-to-purchase-email.html
28 lines
633 B
Text
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();
|