PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.0.7
GiveWP – Donation Plugin and Fundraising Platform v2.0.7
4.16.3 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 7 years ago ajax-handler.php 7 years ago backward-compatibility.php 7 years ago class-donation-receipt-email.php 7 years ago class-donor-register-email.php 7 years ago class-email-access-email.php 7 years ago class-email-notification-table.php 7 years ago class-email-notification-util.php 7 years ago class-email-notifications.php 7 years ago class-email-setting-field.php 7 years ago class-new-donation-email.php 7 years ago class-new-donor-register-email.php 7 years ago class-new-offline-donation-email.php 7 years ago class-offline-donation-instruction-email.php 7 years ago filters.php 7 years ago
class-email-setting-field.php
375 lines
1 <?php
2
3 /**
4 * Email Notification Setting Fields
5 *
6 * @package Give
7 * @subpackage Classes/Emails
8 * @copyright Copyright (c) 2016, WordImpress
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 if ( Give_Email_Notification_Util::has_recipient_field( $email ) ) {
29 $setting_fields[] = self::get_recipient_setting_field( $email, $form_id );
30 }
31
32
33 // Add extra setting field.
34 if ( $extra_setting_field = $email->get_extra_setting_fields( $form_id ) ) {
35 $setting_fields = array_merge( $setting_fields, $extra_setting_field );
36 }
37
38 // Preview field.
39 if ( Give_Email_Notification_Util::has_preview( $email ) ) {
40 $setting_fields[] = self::get_preview_setting_field( $email, $form_id );
41 }
42
43 $setting_fields = self::add_section_end( $email, $setting_fields );
44
45 /**
46 * Filter the email notification settings.
47 *
48 * @since 2.0
49 */
50 return apply_filters( 'give_email_notification_setting_fields', $setting_fields, $email, $form_id );
51 }
52
53
54 /**
55 * Check if email notification setting has section end or not.
56 *
57 * @since 2.0
58 * @access private
59 *
60 * @param $setting
61 *
62 * @return bool
63 */
64 public static function has_section_end( $setting ) {
65 $last_field = end( $setting );
66 $has_section_end = false;
67
68 if ( 'sectionend' === $last_field['type'] ) {
69 $has_section_end = true;
70 }
71
72 return $has_section_end;
73 }
74
75 /**
76 * Check if email notification setting has section end or not.
77 *
78 * @since 2.0
79 * @access private
80 *
81 * @param Give_Email_Notification $email
82 * @param int $form_id
83 *
84 * @return array
85 */
86 public static function get_section_start( Give_Email_Notification $email, $form_id = null ) {
87 // Add section end field.
88 $setting = array(
89 'id' => "give_title_email_settings_{$email->config['id']}",
90 'type' => 'title',
91 'title' => $email->config['label'],
92 );
93
94 return $setting;
95 }
96
97 /**
98 * Check if email notification setting has section end or not.
99 *
100 * @since 2.0
101 * @access private
102 *
103 * @param array $setting
104 * @param Give_Email_Notification $email
105 *
106 * @return array
107 */
108 public static function add_section_end( Give_Email_Notification $email, $setting ) {
109 if ( ! self::has_section_end( $setting ) ) {
110 // Add section end field.
111 $setting[] = array(
112 'id' => "give_title_email_settings_{$email->config['id']}",
113 'type' => 'sectionend',
114 );
115 }
116
117 return $setting;
118 }
119
120 /**
121 * Get default setting field.
122 *
123 * @since 2.0
124 * @access static
125 *
126 * @param Give_Email_Notification $email
127 * @param int $form_id
128 *
129 * @return array
130 */
131 public static function get_default_setting_fields( Give_Email_Notification $email, $form_id = null ) {
132 $settings[] = self::get_section_start( $email, $form_id );
133 $settings[] = self::get_notification_status_field( $email, $form_id );
134
135 if ( ! Give_Email_Notification_Util::is_notification_status_editable( $email ) ) {
136 if( $form_id || give_is_add_new_form_page() ){
137 // Do not allow admin to disable notification on perform basis.
138 unset( $settings[1]['options']['disabled'] );
139 } else{
140 // Do not allow admin to edit notification status globally.
141 unset( $settings[1] );
142 }
143 }
144
145 $settings[] = self::get_email_subject_field( $email, $form_id );
146 $settings[] = self::get_email_message_field( $email, $form_id );
147
148 if( Give_Email_Notification_Util::is_content_type_editable( $email ) ) {
149 $settings[] = self::get_email_content_type_field( $email, $form_id );
150 }
151
152 return $settings;
153 }
154
155 /**
156 * Get notification status setting field.
157 *
158 * @since 2.0
159 * @access static
160 *
161 * @param Give_Email_Notification $email
162 * @param int $form_id
163 *
164 * @return array
165 */
166 public static function get_notification_status_field( Give_Email_Notification $email, $form_id = null ) {
167 $option = array(
168 'enabled' => __( 'Enabled', 'give' ),
169 'disabled' => __( 'Disabled', 'give' ),
170 );
171
172 $default_value = $email->get_notification_status();
173
174 // Add global options.
175 if ( $form_id || give_is_add_new_form_page() ) {
176 $option = array(
177 'global' => __( 'Global Options' ),
178 'enabled' => __( 'Customize', 'give' ),
179 'disabled' => __( 'Disabled', 'give' ),
180 );
181
182 $default_value = 'global';
183 }
184
185 $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 Give settings</a>. You may override them for this form here.', 'give' ), admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=emails' ) );
186
187 return array(
188 'name' => esc_html__( 'Notification', 'give' ),
189 'desc' => $description,
190 'id' => self::get_prefix( $email, $form_id ) . 'notification',
191 'type' => 'radio_inline',
192 'default' => $default_value,
193 'options' => $option,
194 'wrapper_class' => 'give_email_api_notification_status_setting',
195 );
196 }
197
198 /**
199 * Get email subject setting field.
200 *
201 * @since 2.0
202 * @access static
203 *
204 * @param Give_Email_Notification $email
205 * @param int $form_id
206 *
207 * @return array
208 */
209 public static function get_email_subject_field( Give_Email_Notification $email, $form_id = null ) {
210 return array(
211 'id' => self::get_prefix( $email, $form_id ) . 'email_subject',
212 'name' => esc_html__( 'Email Subject', 'give' ),
213 'desc' => esc_html__( 'Enter the email subject line.', 'give' ),
214 'default' => $email->config['default_email_subject'],
215 'type' => 'text',
216 );
217 }
218
219 /**
220 * Get email message setting field.
221 *
222 * @since 2.0
223 * @access static
224 *
225 * @param Give_Email_Notification $email
226 * @param int $form_id
227 *
228 * @return array
229 */
230 public static function get_email_message_field( Give_Email_Notification $email, $form_id = null ) {
231 $desc = esc_html__( 'Enter the email message.', 'give' );
232
233 if ( $email_tag_list = $email->get_allowed_email_tags( true ) ) {
234 $desc = sprintf(
235 '%1$s <br> %2$s: %3$s %4$s',
236 __( 'The email that is sent to users after completing a successful donation. HTML is accepted.', 'give' ),
237 __( 'Available template tags', 'give' ),
238 $email_tag_list,
239 sprintf(
240 '<br><a href="%1$s" target="_blank">%2$s</a> %3$s',
241 esc_url('http://docs.givewp.com/meta-email-tags'),
242 __( 'See our documentation', 'give' ),
243 __( 'for examples of how to use custom meta email tags to output additional donor or donation information in your Give emails.', 'give' )
244 )
245 );
246
247 }
248
249 return array(
250 'id' => self::get_prefix( $email, $form_id ) . 'email_message',
251 'name' => esc_html__( 'Email message', 'give' ),
252 'desc' => $desc,
253 'type' => 'wysiwyg',
254 'default' => $email->config['default_email_message'],
255 );
256 }
257
258 /**
259 * Get email message setting field.
260 *
261 * @since 2.0
262 * @access static
263 *
264 * @param Give_Email_Notification $email
265 * @param int $form_id
266 *
267 * @return array
268 */
269 public static function get_email_content_type_field( Give_Email_Notification $email, $form_id = null ) {
270 return array(
271 'id' => self::get_prefix( $email, $form_id ) . 'email_content_type',
272 'name' => esc_html__( 'Email Content Type', 'give' ),
273 'desc' => __( 'Choose email type.', 'give' ),
274 'type' => 'select',
275 'options' => array(
276 'text/html' => Give_Email_Notification_Util::get_formatted_email_type( 'text/html' ),
277 'text/plain' => Give_Email_Notification_Util::get_formatted_email_type( 'text/plain' ),
278 ),
279 'default' => $email->config['content_type'],
280 );
281 }
282
283
284 /**
285 * Get recipient setting field.
286 *
287 * @since 2.0
288 * @access static
289 * @todo check this field in form metabox setting after form api merge.
290 *
291 * @param Give_Email_Notification $email
292 * @param int $form_id
293 *
294 * @return array
295 */
296 public static function get_recipient_setting_field( Give_Email_Notification $email, $form_id = null ) {
297 $recipient = array(
298 'id' => self::get_prefix( $email, $form_id ) . 'recipient',
299 'name' => esc_html__( 'Email Recipients', 'give' ),
300 'desc' => __( 'Enter the email address(es) that should receive a notification.', 'give' ),
301 'type' => 'email',
302 'default' => get_bloginfo( 'admin_email' ),
303 'repeat' => true,
304 'repeat_btn_title' => esc_html__( 'Add Recipient', 'give' ),
305 );
306
307 if ( $form_id || give_is_add_new_form_page() ) {
308 $recipient['name'] = __( 'Email', 'give' );
309 $recipient['default'] = '';
310 $recipient['id'] = 'email';
311 $recipient['desc'] = __( 'Enter the email address that should receive a notification.', 'give' );
312
313 $recipient = array(
314 'id' => self::get_prefix( $email, $form_id ) . 'recipient',
315 'type' => 'group',
316 'options' => array(
317 'add_button' => __( 'Add Email', 'give' ),
318 'header_title' => __( 'Email Recipient', 'give' ),
319 'remove_button' => '<span class="dashicons dashicons-no"></span>',
320 ),
321 'fields' => array(
322 $recipient,
323 ),
324 );
325 }
326
327 return $recipient;
328 }
329
330 /**
331 * Get preview setting field.
332 *
333 * @param Give_Email_Notification $email Email Type.
334 * @param int $form_id Form ID.
335 *
336 * @since 2.0
337 * @access static
338 *
339 * @return array
340 */
341 public static function get_preview_setting_field( Give_Email_Notification $email, $form_id = null ) {
342 return array(
343 'name' => __( 'Preview Email', 'give' ),
344 'desc' => __( 'Click the "Preview Email" button to preview the email in your browser. Click the "Send Test Email" button to send a test email directly to your inbox.',
345 'give' ),
346 'id' => self::get_prefix( $email, $form_id ) . 'preview_buttons',
347 'type' => 'email_preview_buttons',
348 );
349 }
350
351
352 /**
353 * Get form metabox setting field prefix.
354 *
355 * @since 2.0
356 * @access static
357 *
358 * @param Give_Email_Notification $email
359 * @param int $form_id
360 *
361 * @return string
362 */
363 public static function get_prefix( Give_Email_Notification $email, $form_id = null ) {
364 $meta_key = "{$email->config['id']}_";
365
366 if( $form_id || give_is_add_new_form_page() ) {
367 $meta_key = "_give_{$email->config['id']}_";
368 }
369
370 return $meta_key;
371 }
372 }
373
374 // @todo: add per email sender options
375