PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 5.4.3
WooCommerce Square v5.4.3
5.4.3 5.4.2 5.4.1 5.4.0 trunk 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.7.0 2.8.0 2.9.0 2.9.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.2.0 3.3.0 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.7.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 4.0.0 4.1.0 4.2.0 4.2.1 4.2.2 4.2.3 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 5.0.0 5.0.1 5.1.0 5.1.1 5.1.2 5.2.0 5.3.0 5.3.1 5.3.2 5.3.3
woocommerce-square / includes / Emails / Base_Email.php
woocommerce-square / includes / Emails Last commit date
Base_Email.php 2 years ago WC_Square_Access_Token_Email.php 1 year ago WC_Square_Gift_Card_Sent.php 1 year ago WC_Square_Sync_Completed.php 1 year ago
Base_Email.php
214 lines
1 <?php
2 /**
3 * WooCommerce Square
4 *
5 * This source file is subject to the GNU General Public License v3.0
6 * that is bundled with this package in the file license.txt.
7 * It is also available through the world-wide-web at this URL:
8 * http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later
9 * If you did not receive a copy of the license and are unable to
10 * obtain it through the world-wide-web, please send an email
11 * to license@woocommerce.com so we can send you a copy immediately.
12 *
13 * DISCLAIMER
14 *
15 * Do not edit or add to this file if you wish to upgrade WooCommerce Square to newer
16 * versions in the future. If you wish to customize WooCommerce Square for your
17 * needs please refer to https://docs.woocommerce.com/document/woocommerce-square/
18 *
19 * @author WooCommerce
20 * @copyright Copyright: (c) 2019, Automattic, Inc.
21 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later
22 */
23
24 namespace WooCommerce\Square\Emails;
25
26 use WooCommerce\Square\Framework\Square_Helper;
27
28 defined( 'ABSPATH' ) || exit;
29
30 /**
31 * Base email class.
32 *
33 * @since 2.1.0
34 */
35 class Base_Email extends \WC_Email {
36 /**
37 * Whether the email is enabled by default.
38 *
39 * @var string
40 */
41 protected $enabled_default = 'no';
42
43 /**
44 * Plain text template path.
45 *
46 * @var string
47 */
48 public $template_plain = 'emails/plain/square-email.php';
49
50 /**
51 * HTML template path.
52 *
53 * @var string
54 */
55 public $template_html = 'emails/square-email.php';
56
57 /**
58 * Template path.
59 *
60 * @var string
61 */
62 public $template_base;
63
64 /**
65 * Email body.
66 *
67 * @var string
68 **/
69 public $body;
70
71 /**
72 * Email constructor.
73 *
74 * @since 2.1.0
75 */
76 public function __construct() {
77 $this->template_base = wc_square()->get_plugin_path() . '/templates/';
78
79 // call parent constructor
80 parent::__construct();
81
82 // set default recipient
83 $this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) );
84 }
85
86 /**
87 * Initializes the email settings form fields.
88 *
89 * Extends and overrides parent method.
90 *
91 * @since 2.1.0
92 */
93 public function init_form_fields() {
94 // initialize the default fields from parent email object
95 parent::init_form_fields();
96
97 $form_fields = $this->form_fields;
98
99 // set email disabled by default
100 if ( isset( $form_fields['enabled'] ) ) {
101 $form_fields['enabled']['default'] = $this->enabled_default;
102 }
103
104 // the email has no customizable body or heading via input field
105 unset( $form_fields['body'], $form_fields['heading'] );
106
107 // adjust email subject field
108 if ( isset( $form_fields['subject'] ) ) {
109 /* translators: Placeholder: %s - default email subject text */
110 $form_fields['subject']['description'] = sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: %s', 'woocommerce-square' ), '<code>' . $this->get_default_subject() . '</code>' );
111 $form_fields['subject']['desc_tip'] = false;
112 $form_fields['subject']['default'] = $this->subject;
113 }
114
115 if ( ! $this->is_customer_email() ) {
116 // add a recipient field
117 $form_fields = Square_Helper::array_insert_after(
118 $form_fields,
119 isset( $form_fields['enabled'] ) ? 'enabled' : key( $form_fields ),
120 array(
121 'recipient' => array(
122 'title' => __( 'Recipient(s)', 'woocommerce-square' ),
123 'type' => 'text',
124 /* translators: %s default email address */
125 'description' => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to admin email: %s', 'woocommerce-square' ), '<code>' . esc_attr( get_option( 'admin_email' ) ) . '</code>' ),
126 'placeholder' => get_bloginfo( 'admin_email' ),
127 'default' => get_bloginfo( 'admin_email' ),
128 ),
129 )
130 );
131 }
132
133 // set the updated fields
134 $this->form_fields = $form_fields;
135 }
136
137 /**
138 * Gets the default email subject.
139 *
140 * @since 2.1.0
141 *
142 * @return string
143 */
144 public function get_default_subject() {
145 return $this->subject;
146 }
147
148 /**
149 * Gets the email body.
150 *
151 * @since 2.1.0
152 *
153 * @return string may contain HTML
154 */
155 protected function get_default_body() {
156 return $this->body;
157 }
158
159 /**
160 * Determines if the email has valid recipients.
161 *
162 * @since 2.1.0
163 *
164 * @return bool
165 */
166 protected function has_recipients() {
167 return ! empty( $this->get_recipient() );
168 }
169
170 /**
171 * Gets the arguments that should be passed to an email template.
172 *
173 * @since 2.1.0
174 *
175 * @param array $args optional associative array with additional arguments
176 * @return array
177 */
178 protected function get_template_args( $args = array() ) {
179 return array_merge(
180 $args,
181 array(
182 'email' => $this,
183 'email_body' => '',
184 'email_heading' => '',
185 'additional_content' => '',
186 )
187 );
188 }
189
190 /**
191 * Gets the email HTML content.
192 *
193 * @since 2.0.0
194 *
195 * @return string HTML
196 */
197 public function get_content_html() {
198 $args = array( 'plain_text' => false );
199 return wc_get_template_html( $this->template_html, array_merge( $args, $this->get_template_args( $args ) ) );
200 }
201
202 /**
203 * Gets the email plain text content.
204 *
205 * @since 2.0.0
206 *
207 * @return string plain text
208 */
209 public function get_content_plain() {
210 $args = array( 'plain_text' => true );
211 return wc_get_template_html( $this->template_plain, array_merge( $args, $this->get_template_args( $args ) ) );
212 }
213 }
214