/var/www/html_uk/wp-content/plugins/automatewoo/includes/Traits/MailServiceAction.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php

namespace AutomateWoo\Traits;

use 
AutomateWoo\Clean;
use 
AutomateWoo\Fields\Checkbox;
use 
AutomateWoo\Fields\Select;
use 
AutomateWoo\Fields\Text;

/**
* Trait SubscribeAction
*
* Helper functions for e-mail list subscriber actions.
*
* @since 5.6.10
*/
trait MailServiceAction {

    
/**
     * Get the list field selector.
     *
     * @param array $lists The list array for showing in this selector.
     * @return Select
     */
    
protected function add_integration_list_field$lists ) {
        
$list_select = ( new Select() )
            ->
set_title__'List''automatewoo' ) )
            ->
set_name'list' )
            ->
set_options$lists )
            ->
set_required();

        
$this->add_field$list_select );
        return 
$list_select;
    }

    
/**
     * Get the contact email field.
     *
     * @return Text
     */
    
protected function get_contact_email_field() {
        
$field = ( new Text() )
            ->
set_name'email' )
            ->
set_title__'Contact email''automatewoo' ) )
            ->
set_description__'Use variables such as {{ customer.email }} here. If blank {{ customer.email }} will be used.''automatewoo' ) )
            ->
set_placeholder'{{ customer.email }}' )
            ->
set_variable_validation();

        return 
$field;
    }

    
/**
     * Get the contact email option. Defaults to {{ customer.email }}.
     *
     * @return string|bool
     */
    
protected function get_contact_email_option() {
        
$email Clean::email$this->get_option'email'true ) );

        if ( 
$email ) {
            return 
$email;
        }

        
$customer $this->workflow->data_layer()->get_customer();

        if ( ! 
$customer ) {
            return 
false;
        }

        return 
$customer->get_email();
    }

    
/**
     * Load the fields for a subscribe action
     *
     * @param array $lists The lists to add in the action list selector.
     */
    
protected function load_subscribe_action_fields$lists ) {

        
$first_name = ( new Text() )
            ->
set_name'first_name' )
            ->
set_title__'First name''automatewoo' ) )
            ->
set_description__'This field is optional.''automatewoo' ) )
            ->
set_variable_validation();

        
$last_name = ( new Text() )
            ->
set_name'last_name' )
            ->
set_title__'Last name''automatewoo' ) )
            ->
set_description__'This field is optional.''automatewoo' ) )
            ->
set_variable_validation();

        
$double_optin = ( new Checkbox() )
            ->
set_name'double_optin' )
            ->
set_title__'Double optin''automatewoo' ) )
            ->
set_description__'Users will receive an email asking them to confirm their subscription.''automatewoo' ) );

        
$this->add_integration_list_field$lists );
        
$this->add_field$this->get_contact_email_field() );
        
$this->add_field$double_optin );
        
$this->add_field$first_name );
        
$this->add_field$last_name );
    }
}