forked from fxbenard/EDD-Lock-Downloads-to-IP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edd-lock-downloads-to-ip.php
70 lines (51 loc) · 1.8 KB
/
edd-lock-downloads-to-ip.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
Plugin Name: Easy Digital Downloads - Lock Downloads to IP
Plugin URI: http://easydigitaldownloads.com/extension/lock-downloads-to-ip
Description: An extension for Easy Digital Downloads to lock file downloads to the IP address used to purchase the file
Author: Pippin Williamson
Version: 1.0
Author URI: http://pippinsplugins.com
Text Domain: edd-iplock
Domain Path: languages
*/
class EDD_Lock_Downloads_To_IP {
function __construct() {
// internationalization
add_action( 'init', array( $this, 'textdomain' ) );
// Check the IP during file download
add_action( 'edd_process_verified_download', array( $this, 'check_ip' ) );
}
/**
* Load the plugin text domain for internationalization
*
* @access public
* @since 1.0
* @return void
*/
public function textdomain() {
// Set filter for plugin's languages directory
$lang_dir = dirname( plugin_basename( __FILE__ ) ) . '/languages/';
// Load the translations
load_plugin_textdomain( 'edd-iplock', false, $lang_dir );
}
/**
* Check the IP address during file download and display an error if it doesn't match the purchase records
*
* @access public
* @since 1.0
* @return void
*/
public function check_ip( $download_id = 0, $email = 0 ) {
$payment_key = isset( $_GET['download_key'] ) ? urldecode( $_GET['download_key'] ) : false;
if( empty( $payment_key ) )
return;
$payment_id = edd_get_purchase_id_by_key( $payment_key );
if( empty( $payment_id ) )
return;
$payment_ip = get_post_meta( $payment_id, '_edd_payment_user_ip', true );
if( $payment_ip !== edd_get_ip() )
wp_die( __( 'You do not have permission to download this file because your IP address doesn\'t match our records.', 'edd-iplock' ), __( 'Error', 'edd-iplock' ) );
}
}
new EDD_Lock_Downloads_To_IP();