class-events-manager.php
1.82 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
78
79
80
<?php
defined('ABSPATH') or exit;
/**
* Class MC4WP_Events_Manager_Integration
*
* @ignore
*/
class MC4WP_Events_Manager_Integration extends MC4WP_Integration
{
/**
* @var string
*/
public $name = 'Events Manager';
/**
* @var string
*/
public $description = 'Subscribes people from Events Manager booking forms.';
/**
* Add hooks
*/
public function add_hooks()
{
if (! $this->options['implicit']) {
add_action('em_booking_form_footer', array( $this, 'output_checkbox' ));
}
add_action('em_bookings_added', array( $this, 'subscribe_from_events_manager' ), 5);
}
/**
* Subscribe from Events Manager booking forms.
*
* @param EM_Booking $args
* @return bool
*/
public function subscribe_from_events_manager($args)
{
// Is this integration triggered? (checkbox checked or implicit)
if (! $this->triggered()) {
return false;
}
$em_data = $this->get_data();
// logged-in users do not have these form fields, so grab from user object instead
if (empty($em_data['user_email']) && is_user_logged_in()) {
$user = wp_get_current_user();
$em_data['user_email'] = $user->user_email;
$em_data['user_name'] = sprintf('%s %s', $user->first_name, $user->last_name);
}
if (empty($em_data['user_email'])) {
return false;
}
$data = array(
'EMAIL' => $em_data['user_email'],
'NAME' => $em_data['user_name'],
);
// subscribe using email and name
return $this->subscribe($data, $args->booking_id);
}
/**
* @return bool
*/
public function is_installed()
{
return defined('EM_VERSION');
}
}