PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 4.5.0
WooCommerce Square v4.5.0
5.5.0 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
Access_Token_Email.php 2 years ago Base_Email.php 3 years ago Gift_Card_Sent.php 2 years ago Sync_Completed.php 2 years ago
Base_Email.php
207 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 constructor.
66 *
67 * @since 2.1.0
68 */
69 public function __construct() {
70 $this->template_base = wc_square()->get_plugin_path() . '/templates/';
71
72 // call parent constructor
73 parent::__construct();
74
75 // set default recipient
76 $this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) );
77 }
78
79 /**
80 * Initializes the email settings form fields.
81 *
82 * Extends and overrides parent method.
83 *
84 * @since 2.1.0
85 */
86 public function init_form_fields() {
87 // initialize the default fields from parent email object
88 parent::init_form_fields();
89
90 $form_fields = $this->form_fields;
91
92 // set email disabled by default
93 if ( isset( $form_fields['enabled'] ) ) {
94 $form_fields['enabled']['default'] = $this->enabled_default;
95 }
96
97 // the email has no customizable body or heading via input field
98 unset( $form_fields['body'], $form_fields['heading'] );
99
100 // adjust email subject field
101 if ( isset( $form_fields['subject'] ) ) {
102 /* translators: Placeholder: %s - default email subject text */
103 $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>' );
104 $form_fields['subject']['desc_tip'] = false;
105 $form_fields['subject']['default'] = $this->subject;
106 }
107
108 if ( ! $this->is_customer_email() ) {
109 // add a recipient field
110 $form_fields = Square_Helper::array_insert_after(
111 $form_fields,
112 isset( $form_fields['enabled'] ) ? 'enabled' : key( $form_fields ),
113 array(
114 'recipient' => array(
115 'title' => __( 'Recipient(s)', 'woocommerce-square' ),
116 'type' => 'text',
117 /* translators: %s default email address */
118 'description' => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to admin email: %s', 'woocommerce-square' ), '<code>' . esc_attr( get_option( 'admin_email' ) ) . '</code>' ),
119 'placeholder' => get_bloginfo( 'admin_email' ),
120 'default' => get_bloginfo( 'admin_email' ),
121 ),
122 )
123 );
124 }
125
126 // set the updated fields
127 $this->form_fields = $form_fields;
128 }
129
130 /**
131 * Gets the default email subject.
132 *
133 * @since 2.1.0
134 *
135 * @return string
136 */
137 public function get_default_subject() {
138 return $this->subject;
139 }
140
141 /**
142 * Gets the email body.
143 *
144 * @since 2.1.0
145 *
146 * @return string may contain HTML
147 */
148 protected function get_default_body() {
149 return $this->body;
150 }
151
152 /**
153 * Determines if the email has valid recipients.
154 *
155 * @since 2.1.0
156 *
157 * @return bool
158 */
159 protected function has_recipients() {
160 return ! empty( $this->get_recipient() );
161 }
162
163 /**
164 * Gets the arguments that should be passed to an email template.
165 *
166 * @since 2.1.0
167 *
168 * @param array $args optional associative array with additional arguments
169 * @return array
170 */
171 protected function get_template_args( $args = array() ) {
172 return array_merge(
173 $args,
174 array(
175 'email' => $this,
176 'email_body' => '',
177 'email_heading' => '',
178 'additional_content' => '',
179 )
180 );
181 }
182
183 /**
184 * Gets the email HTML content.
185 *
186 * @since 2.0.0
187 *
188 * @return string HTML
189 */
190 public function get_content_html() {
191 $args = array( 'plain_text' => false );
192 return wc_get_template_html( $this->template_html, array_merge( $args, $this->get_template_args( $args ) ) );
193 }
194
195 /**
196 * Gets the email plain text content.
197 *
198 * @since 2.0.0
199 *
200 * @return string plain text
201 */
202 public function get_content_plain() {
203 $args = array( 'plain_text' => true );
204 return wc_get_template_html( $this->template_plain, array_merge( $args, $this->get_template_args( $args ) ) );
205 }
206 }
207