/var/www/html_uk/wp-content/plugins/automatewoo/includes/Actions/Mailchimp_Unsubscribe.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
<?php

namespace AutomateWoo;

if ( ! 
defined'ABSPATH' ) ) {
    exit;
}

/**
 * @class Action_Mailchimp_Unsubscribe
 */
class Action_Mailchimp_Unsubscribe 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 __'Remove Contact From List''automatewoo' );
    }

    
/**
     * Implements Action load_fields abstract method
     *
     * @see Action::load_fields()
     */
    
public function load_fields() {
        
$unsubscribe_only = new Fields\Checkbox();
        
$unsubscribe_only->set_name'unsubscribe_only' );
        
$unsubscribe_only->set_title__'Unsubscribe only''automatewoo' ) );
        
$unsubscribe_only->set_description__'If checked the user will be unsubscribed instead of deleted.''automatewoo' ) );

        
$this->add_list_field();
        
$this->add_field$this->get_contact_email_field() );
        
$this->add_field$unsubscribe_only );
    }

    
/**
     * Implements 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();
        
$subscriber md5$email );

        if ( 
$this->get_option'unsubscribe_only' ) ) {
            
$this->maybe_log_action(
                
Integrations::mailchimp()->request(
                    
'PATCH',
                    
"/lists/$list_id/members/$subscriber",
                    [
                        
'status' => 'unsubscribed',
                    ]
                )
            );
        } else {
            
$this->maybe_log_actionIntegrations::mailchimp()->request'DELETE'"/lists/$list_id/members/$subscriber) );
        }
    }
}