class-memberpress.php
1.73 KB
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
71
72
73
74
75
76
77
<?php
defined('ABSPATH') or exit;
/**
* Class MC4WP_MemberPress_Integration
*
* @ignore
*/
class MC4WP_MemberPress_Integration extends MC4WP_Integration
{
/**
* @var string
*/
public $name = 'MemberPress';
/**
* @var string
*/
public $description = 'Subscribes people from MemberPress register forms.';
/**
* Add hooks
*/
public function add_hooks()
{
if (! $this->options['implicit']) {
if (has_action('mepr_checkout_before_submit')) {
add_action('mepr_checkout_before_submit', array( $this, 'output_checkbox' ));
} else {
add_action('mepr-checkout-before-submit', array( $this, 'output_checkbox' ));
}
}
if (has_action('mepr_signup')) {
add_action('mepr_signup', array( $this, 'subscribe_from_memberpress' ), 5);
} else {
add_action('mepr-signup', array( $this, 'subscribe_from_memberpress' ), 5);
}
}
/**
* Subscribe from MemberPress sign-up forms.
*
* @param MeprTransaction $txn
* @return bool
*/
public function subscribe_from_memberpress($txn)
{
// Is this integration triggered? (checkbox checked or implicit)
if (! $this->triggered()) {
return false;
}
$user = get_userdata($txn->user_id);
$data = array(
'EMAIL' => $user->user_email,
'FNAME' => $user->first_name,
'LNAME' => $user->last_name,
);
// subscribe using email and name
return $this->subscribe($data, $txn->id);
}
/**
* @return bool
*/
public function is_installed()
{
return defined('MEPR_VERSION');
}
}