/var/www/html_uk/wp-content/plugins/automatewoo/includes/Actions/Send_Email_Abstract.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php

namespace AutomateWoo;

use 
AutomateWoo\Actions\PreviewableInterface;
use 
AutomateWoo\Actions\TestableInterface;
use 
AutomateWoo\Exceptions\InvalidArgument;
use 
AutomateWoo\Fields\EmailAddressWithName;
use 
AutomateWoo\Traits\ArrayValidator;

defined'ABSPATH' ) || exit;

/**
 * Abstract class for send email actions.
 *
 * @class Action_Send_Email_Abstract
 * @since 4.4.0
 */
abstract class Action_Send_Email_Abstract extends Action implements PreviewableInterfaceTestableInterface {

    use 
ArrayValidator;

    
/**
     * Get the email type (html-template, html-raw, plain-text).
     *
     * @return string
     */
    
abstract public function get_email_type();

    
/**
     * Load admin props.
     */
    
public function load_admin_details() {
        
$this->group __'Email''automatewoo' );
    }

    
/**
     * Load fields.
     */
    
public function load_fields() {
        
$to = new Fields\Text();
        
$to->set_name'to' );
        
$to->set_title__'To''automatewoo' ) );
        
$to->set_description__'Enter emails here or use variables such as {{ customer.email }}. Multiple emails can be separated by commas. Add <b>--notracking</b> after an email to disable open and click tracking for that recipient.''automatewoo' ) );
        
$to->set_placeholder__'E.g. {{ customer.email }}, [email protected] --notracking''automatewoo' ) );
        
$to->set_variable_validation();
        
$to->set_required();

        
$subject = new Fields\Text();
        
$subject->set_name'subject' );
        
$subject->set_title__'Email subject''automatewoo' ) );
        
$subject->set_variable_validation();
        
$subject->set_required();

        
$reply_to = ( new EmailAddressWithName() )
            ->
set_name'reply_to' )
            ->
set_title__'Reply to''automatewoo' ) )
            ->
set_description(
                
__'Optionally set a reply-to email for the email. Please note that not all email delivery services support "Reply-To" email headers.''automatewoo' )
            );

        
$this->add_field$to );
        
$this->add_field$reply_to );
        
$this->add_field$subject );
    }

    
/**
     * Get workflow email object for this action.
     *
     * Sets the email subject, content and reply_to from the action options.
     *
     * @param string $recipient
     * @param string $content
     *
     * @return Workflow_Email
     */
    
public function get_workflow_email_objectstring $recipientstring $content ) {
        
$subject  $this->get_option'subject'true );
        
$reply_to $this->get_option'reply_to'true );

        
$email = new Workflow_Email$this->workflow$recipient$subject$content );
        
$email->set_type$this->get_email_type() );

        if ( 
is_array$reply_to ) && $reply_to[0] && is_email$reply_to[1] ) ) {
            
$email->set_reply_tosprintf'%s <%s>'$reply_to[0], $reply_to[1] ) );
        }

        return 
$email;
    }


    
/**
     * Log the result of a send email attempt.
     *
     * @param \WP_Error|bool $result
     */
    
public function add_send_email_result_to_workflow_log$result ) {
        if ( 
is_wp_error$result ) ) {
            
$this->workflow->log_action_email_error$result$this );
        } else {
            
$this->workflow->log_action_note$this__'Email successfully sent.''automatewoo' ) );
        }
    }

    
/**
     * Validate the args used to run a test of this action.
     *
     * @since 5.2.0
     *
     * @param array $args
     *
     * @throws InvalidArgument If test args are invalid.
     */
    
protected function validate_test_args( array $args ) {
        if ( ! isset( 
$args['recipients'] ) ) {
            throw 
InvalidArgument::missing_required'recipients' );
        }
        
$this->validate_array_of_strings$args['recipients'] );
    }
}