PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / trunk
GiveWP – Donation Plugin and Fundraising Platform vtrunk
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 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.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / emails / class-email-setting-field.php
give / includes / admin / emails Last commit date
abstract-email-notification.php 4 years ago ajax-handler.php 2 weeks ago backward-compatibility.php 6 years ago class-donation-receipt-email.php 4 years ago class-donor-note-email.php 6 years ago class-donor-register-email.php 3 years ago class-email-access-email.php 4 days ago class-email-notification-table.php 3 years ago class-email-notification-util.php 6 years ago class-email-notifications.php 5 months ago class-email-setting-field.php 3 years ago class-failed-donation-email.php 5 months ago class-new-donation-email.php 6 years ago class-new-donor-register-email.php 3 years ago class-new-offline-donation-email.php 9 months ago class-offline-donation-instruction-email.php 6 years ago filters.php 3 years ago
class-email-setting-field.php
415 lines
1 <?php
2
3 /**
4 * Email Notification Setting Fields
5 *
6 * @package Give
7 * @subpackage Classes/Emails
8 * @copyright Copyright (c) 2016, GiveWP
9 * @license https://opensource.org/licenses/gpl-license GNU Public License
10 * @since 2.0
11 */
12 class Give_Email_Setting_Field {
13 /**
14 * Get setting field.
15 *
16 * @since 2.0
17 * @access public
18 *
19 * @param Give_Email_Notification $email
20 * @param int $form_id
21 *
22 * @return array
23 */
24 public static function get_setting_fields( Give_Email_Notification $email, $form_id = null ) {
25 $setting_fields = self::get_default_setting_fields( $email, $form_id );
26
27 // Recipient field.
28 $setting_fields[] = self::get_recipient_setting_field( $email, $form_id, Give_Email_Notification_Util::has_recipient_field( $email ) );
29
30 // Add extra setting field.
31 if ( $extra_setting_field = $email->get_extra_setting_fields( $form_id ) ) {
32 $setting_fields = array_merge( $setting_fields, $extra_setting_field );
33 }
34
35 // Preview field.
36 if ( Give_Email_Notification_Util::has_preview( $email ) ) {
37 $setting_fields[] = self::get_preview_setting_field( $email, $form_id );
38 }
39
40 $setting_fields = self::add_section_end( $email, $setting_fields );
41
42 /**
43 * Filter the email notification settings.
44 *
45 * @since 2.0
46 */
47 return apply_filters( 'give_email_notification_setting_fields', $setting_fields, $email, $form_id );
48 }
49
50
51 /**
52 * Check if email notification setting has section end or not.
53 *
54 * @since 2.0
55 * @access private
56 *
57 * @param $setting
58 *
59 * @return bool
60 */
61 public static function has_section_end( $setting ) {
62 $last_field = end( $setting );
63 $has_section_end = false;
64
65 if ( 'sectionend' === $last_field['type'] ) {
66 $has_section_end = true;
67 }
68
69 return $has_section_end;
70 }
71
72 /**
73 * Check if email notification setting has section end or not.
74 *
75 * @since 2.0
76 * @access private
77 *
78 * @param Give_Email_Notification $email
79 * @param int $form_id
80 *
81 * @return array
82 */
83 public static function get_section_start( Give_Email_Notification $email, $form_id = null ) {
84 // Add section end field.
85 $setting = array(
86 'id' => "give_title_email_settings_{$email->config['id']}",
87 'type' => 'title',
88 'title' => $email->config['label'],
89 );
90
91 return $setting;
92 }
93
94 /**
95 * Check if email notification setting has section end or not.
96 *
97 * @since 2.0
98 * @access private
99 *
100 * @param array $setting
101 * @param Give_Email_Notification $email
102 *
103 * @return array
104 */
105 public static function add_section_end( Give_Email_Notification $email, $setting ) {
106 if ( ! self::has_section_end( $setting ) ) {
107 // Add section end field.
108 $setting[] = array(
109 'id' => "give_title_email_settings_{$email->config['id']}",
110 'type' => 'sectionend',
111 );
112 }
113
114 return $setting;
115 }
116
117 /**
118 * Get default setting field.
119 *
120 * @since 2.0
121 * @access static
122 *
123 * @param Give_Email_Notification $email
124 * @param int $form_id
125 *
126 * @return array
127 */
128 public static function get_default_setting_fields( Give_Email_Notification $email, $form_id = null ) {
129 $settings[] = self::get_section_start( $email, $form_id );
130 $settings[] = self::get_notification_status_field( $email, $form_id );
131
132 if ( ! Give_Email_Notification_Util::is_notification_status_editable( $email ) ) {
133 if ( $form_id || give_is_add_new_form_page() ) {
134 // Do not allow admin to disable notification on perform basis.
135 unset( $settings[1]['options']['disabled'] );
136 } else {
137 // Do not allow admin to edit notification status globally.
138 unset( $settings[1] );
139 }
140 }
141
142 $settings[] = self::get_email_subject_field( $email, $form_id );
143 $settings[] = self::get_email_header_field( $email, $form_id );
144 $settings[] = self::get_email_message_field( $email, $form_id );
145
146 if ( Give_Email_Notification_Util::is_content_type_editable( $email ) ) {
147 $settings[] = self::get_email_content_type_field( $email, $form_id );
148 }
149
150 return $settings;
151 }
152
153 /**
154 * Get notification status setting field.
155 *
156 * @since 2.0
157 * @access static
158 *
159 * @param Give_Email_Notification $email
160 * @param int $form_id
161 *
162 * @return array
163 */
164 public static function get_notification_status_field( Give_Email_Notification $email, $form_id = null ) {
165 $option = array(
166 'enabled' => __( 'Enabled', 'give' ),
167 'disabled' => __( 'Disabled', 'give' ),
168 );
169
170 $default_value = $email->get_notification_status();
171
172 // Add global options.
173 if ( $form_id || give_is_add_new_form_page() ) {
174 $option = array(
175 'global' => __( 'Global Options', 'give' ),
176 'enabled' => __( 'Customize', 'give' ),
177 'disabled' => __( 'Disabled', 'give' ),
178 );
179
180 $default_value = 'global';
181 }
182
183 $description = isset( $_GET['page'] ) && 'give-settings' === $_GET['page'] ? __( 'Choose whether you want this email enabled or not.', 'give' ) : sprintf( __( 'Global Options are set <a href="%s">in GiveWP settings</a>. You may override them for this form here.', 'give' ), admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=emails' ) );
184
185 return array(
186 'name' => esc_html__( 'Notification', 'give' ),
187 'desc' => $description,
188 'id' => self::get_prefix( $email, $form_id ) . 'notification',
189 'type' => 'radio_inline',
190 'default' => $default_value,
191 'options' => $option,
192 'wrapper_class' => 'give_email_api_notification_status_setting',
193 );
194 }
195
196 /**
197 * Get email subject setting field.
198 *
199 * @since 2.0
200 * @access static
201 *
202 * @param Give_Email_Notification $email
203 * @param int $form_id
204 *
205 * @return array
206 */
207 public static function get_email_subject_field( Give_Email_Notification $email, $form_id = null ) {
208 return array(
209 'id' => self::get_prefix( $email, $form_id ) . 'email_subject',
210 'name' => esc_html__( 'Email Subject', 'give' ),
211 'desc' => esc_html__( 'Enter the email subject line.', 'give' ),
212 'default' => $email->config['default_email_subject'],
213 'type' => 'text',
214 );
215 }
216
217 /**
218 * Get email header setting field.
219 *
220 * @since 2.1.3
221 *
222 * @param Give_Email_Notification $email The email object.
223 * @param int $form_id The Form ID.
224 *
225 * @return array
226 */
227 public static function get_email_header_field( Give_Email_Notification $email, $form_id = null ) {
228 return array(
229 'id' => self::get_prefix( $email, $form_id ) . 'email_header',
230 'name' => esc_html__( 'Email Header', 'give' ),
231 'desc' => esc_html__( 'Enter the email header that appears at the top of the email.', 'give' ),
232 'default' => $email->config['default_email_header'],
233 'type' => 'text',
234 );
235 }
236
237 /**
238 * Get email message setting field.
239 *
240 * @since 2.0
241 * @access static
242 *
243 * @param Give_Email_Notification $email
244 * @param int $form_id
245 *
246 * @return array
247 */
248 public static function get_email_message_field( Give_Email_Notification $email, $form_id = null ) {
249 $desc = esc_html__( 'Enter the email message.', 'give' );
250
251 if ( $email_tag_list = $email->get_allowed_email_tags( true ) ) {
252 $desc = sprintf(
253 '%1$s <br> %2$s %3$s',
254 __( 'Available template tags for this email. HTML is accepted.', 'give' ),
255 $email_tag_list,
256 sprintf(
257 '<br><a href="%1$s" target="_blank">%2$s</a> %3$s',
258 esc_url( 'http://docs.givewp.com/meta-email-tags' ),
259 __( 'See our documentation', 'give' ),
260 __( 'for examples of how to use custom meta email tags to output additional donor or donation information in your GiveWP emails.', 'give' )
261 )
262 );
263
264 }
265
266 return array(
267 'id' => self::get_prefix( $email, $form_id ) . 'email_message',
268 'name' => esc_html__( 'Email message', 'give' ),
269 'desc' => $desc,
270 'type' => 'wysiwyg',
271 'default' => $email->config['default_email_message'],
272 );
273 }
274
275 /**
276 * Get email message setting field.
277 *
278 * @since 2.0
279 * @access static
280 *
281 * @param Give_Email_Notification $email
282 * @param int $form_id
283 *
284 * @return array
285 */
286 public static function get_email_content_type_field( Give_Email_Notification $email, $form_id = null ) {
287 return array(
288 'id' => self::get_prefix( $email, $form_id ) . 'email_content_type',
289 'name' => esc_html__( 'Email Content Type', 'give' ),
290 'desc' => __( 'Choose email type.', 'give' ),
291 'type' => 'select',
292 'options' => array(
293 'text/html' => Give_Email_Notification_Util::get_formatted_email_type( 'text/html' ),
294 'text/plain' => Give_Email_Notification_Util::get_formatted_email_type( 'text/plain' ),
295 ),
296 'default' => $email->config['content_type'],
297 );
298 }
299
300
301 /**
302 * Get recipient setting field.
303 *
304 * @since 2.0
305 * @access public
306 * @todo check this field in form metabox setting after form api merge.
307 *
308 * @param Give_Email_Notification $email
309 * @param int $form_id
310 * @param bool $edit_recipient
311 *
312 * @return array
313 */
314 public static function get_recipient_setting_field( Give_Email_Notification $email, $form_id = null, $edit_recipient = true ) {
315 $recipient = array(
316 'id' => self::get_prefix( $email, $form_id ) . 'recipient',
317 'name' => esc_html__( 'Email Recipients', 'give' ),
318 'desc' => __( 'Enter the email address(es) that should receive a notification.', 'give' ),
319 'type' => 'email',
320 'default' => get_bloginfo( 'admin_email' ),
321 'repeat' => true,
322 'repeat_btn_title' => esc_html__( 'Add Recipient', 'give' ),
323 );
324
325 if ( $form_id || give_is_add_new_form_page() ) {
326 $recipient['name'] = __( 'Email', 'give' );
327 $recipient['default'] = '';
328 $recipient['id'] = 'email';
329 $recipient['desc'] = __( 'Enter the email address that should receive a notification.', 'give' );
330
331 $recipient = array(
332 'id' => self::get_prefix( $email, $form_id ) . 'recipient',
333 'type' => 'group',
334 'options' => array(
335 'add_button' => __( 'Add Email', 'give' ),
336 'header_title' => __( 'Email Recipient', 'give' ),
337 'remove_button' => '<span class="dashicons dashicons-no"></span>',
338 ),
339 'fields' => array(
340 $recipient,
341 ),
342 );
343 }
344
345 // Disable field if email donor has recipient field.
346 // @see https://github.com/impress-org/give/issues/2657
347 if ( ! $edit_recipient ) {
348 if ('group' == $recipient['type']) {
349 $recipient = current($recipient['fields']);
350 $recipient['type'] = 'text';
351 }
352
353 $recipient['attributes']['disabled'] = 'disabled';
354 $recipient['value'] = $recipient['default'] = '{donor_email}';
355 $recipient['repeat'] = false;
356 $recipient['desc'] = __('This email is automatically sent to the donor and the recipient cannot be customized.',
357 'give');
358 }
359
360 /**
361 * @since 2.23.0
362 */
363 return apply_filters('give_get_recipient_setting_field', $recipient, $email, $form_id, $edit_recipient);
364 }
365
366 /**
367 * Get preview setting field.
368 *
369 * @param Give_Email_Notification $email Email Type.
370 * @param int $form_id Form ID.
371 *
372 * @since 2.0
373 * @access static
374 *
375 * @return array
376 */
377 public static function get_preview_setting_field( Give_Email_Notification $email, $form_id = null ) {
378 return array(
379 'name' => __( 'Preview Email', 'give' ),
380 'desc' => sprintf(
381 '%1$s<br />%2$s <code>%3$s</code>.',
382 esc_html__( 'Click the "Preview Email" button to preview the email in your browser.', 'give' ),
383 esc_html__( 'Click the "Send Test Email" button to send a test email to yourself at', 'give' ),
384 wp_get_current_user()->user_email
385 ),
386 'id' => self::get_prefix( $email, $form_id ) . 'preview_buttons',
387 'type' => 'email_preview_buttons',
388 );
389 }
390
391
392 /**
393 * Get form metabox setting field prefix.
394 *
395 * @since 2.0
396 * @access static
397 *
398 * @param Give_Email_Notification $email
399 * @param int $form_id
400 *
401 * @return string
402 */
403 public static function get_prefix( Give_Email_Notification $email, $form_id = null ) {
404 $meta_key = "{$email->config['id']}_";
405
406 if ( $form_id || give_is_add_new_form_page() ) {
407 $meta_key = "_give_{$email->config['id']}_";
408 }
409
410 return $meta_key;
411 }
412 }
413
414 // @todo: add per email sender options
415