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
|
<?php
namespace AutomateWoo;
use AutomateWoo\Actions\ActionInterface; use AutomateWoo\Traits\MailServiceAction;
if ( ! defined( 'ABSPATH' ) ) { exit; }
/** * @class Action_Mailchimp_Subscribe */ class Action_Mailchimp_Subscribe extends Action_Mailchimp_Abstract {
/** * Implements Action load_admin_details abstract method * * @see Action::load_admin_details() */ protected function load_admin_details() { parent::load_admin_details(); $this->title = __( 'Add Contact To List', 'automatewoo' ); }
/** * Implements Action load_fields abstract method * * @see Action::load_fields() * @see MailServiceAction::load_subscribe_action_fields() */ public function load_fields() { $this->load_subscribe_action_fields( Integrations::mailchimp()->get_lists() ); }
/** * Implements Action run abstract method * * @throws \Exception When the action fails. * @see ActionInterface::run() */ public function run() { $this->validate_required_fields();
$list_id = $this->get_option( 'list' ); $email = $this->get_contact_email_option(); $first_name = $this->get_option( 'first_name', true ); $last_name = $this->get_option( 'last_name', true );
$args = []; $subscriber_hash = md5( $email );
$args['email_address'] = $email; $args['status'] = $this->get_option( 'double_optin' ) ? 'pending' : 'subscribed';
if ( $first_name || $last_name ) { $args['merge_fields'] = [ 'FNAME' => $first_name, 'LNAME' => $last_name, ]; }
$this->maybe_log_action( Integrations::mailchimp()->request( 'PUT', "/lists/$list_id/members/$subscriber_hash", $args ) ); } }
|