PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.0.0
GiveWP – Donation Plugin and Fundraising Platform v2.0.0
4.16.4 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 8 years ago ajax-handler.php 8 years ago backward-compatibility.php 8 years ago class-donation-receipt-email.php 8 years ago class-donor-register-email.php 8 years ago class-email-access-email.php 8 years ago class-email-notification-table.php 8 years ago class-email-notification-util.php 8 years ago class-email-notifications.php 8 years ago class-email-setting-field.php 8 years ago class-new-donation-email.php 8 years ago class-new-donor-register-email.php 8 years ago class-new-offline-donation-email.php 8 years ago class-offline-donation-instruction-email.php 8 years ago filters.php 8 years ago
class-email-setting-field.php
367 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 esc_html__( 'The email that is sent to users after completing a successful donation. HTML is accepted. Available template tags: %s', 'give' ),
236 $email_tag_list
237 );
238
239 }
240
241 return array(
242 'id' => self::get_prefix( $email, $form_id ) . 'email_message',
243 'name' => esc_html__( 'Email message', 'give' ),
244 'desc' => $desc,
245 'type' => 'wysiwyg',
246 'default' => $email->config['default_email_message'],
247 );
248 }
249
250 /**
251 * Get email message setting field.
252 *
253 * @since 2.0
254 * @access static
255 *
256 * @param Give_Email_Notification $email
257 * @param int $form_id
258 *
259 * @return array
260 */
261 public static function get_email_content_type_field( Give_Email_Notification $email, $form_id = null ) {
262 return array(
263 'id' => self::get_prefix( $email, $form_id ) . 'email_content_type',
264 'name' => esc_html__( 'Email Content Type', 'give' ),
265 'desc' => __( 'Choose email type.', 'give' ),
266 'type' => 'select',
267 'options' => array(
268 'text/html' => Give_Email_Notification_Util::get_formatted_email_type( 'text/html' ),
269 'text/plain' => Give_Email_Notification_Util::get_formatted_email_type( 'text/plain' ),
270 ),
271 'default' => $email->config['content_type'],
272 );
273 }
274
275
276 /**
277 * Get recipient setting field.
278 *
279 * @since 2.0
280 * @access static
281 * @todo check this field in form metabox setting after form api merge.
282 *
283 * @param Give_Email_Notification $email
284 * @param int $form_id
285 *
286 * @return array
287 */
288 public static function get_recipient_setting_field( Give_Email_Notification $email, $form_id = null ) {
289 $recipient = array(
290 'id' => self::get_prefix( $email, $form_id ) . 'recipient',
291 'name' => esc_html__( 'Email Recipients', 'give' ),
292 'desc' => __( 'Enter the email address(es) that should receive a notification.', 'give' ),
293 'type' => 'email',
294 'default' => get_bloginfo( 'admin_email' ),
295 'repeat' => true,
296 'repeat_btn_title' => esc_html__( 'Add Recipient', 'give' ),
297 );
298
299 if ( $form_id || give_is_add_new_form_page() ) {
300 $recipient['name'] = __( 'Email', 'give' );
301 $recipient['default'] = '';
302 $recipient['id'] = 'email';
303 $recipient['desc'] = __( 'Enter the email address that should receive a notification.', 'give' );
304
305 $recipient = array(
306 'id' => self::get_prefix( $email, $form_id ) . 'recipient',
307 'type' => 'group',
308 'options' => array(
309 'add_button' => __( 'Add Email', 'give' ),
310 'header_title' => __( 'Email Recipient', 'give' ),
311 'remove_button' => '<span class="dashicons dashicons-no"></span>',
312 ),
313 'fields' => array(
314 $recipient,
315 ),
316 );
317 }
318
319 return $recipient;
320 }
321
322 /**
323 * Get preview setting field.
324 *
325 * @param Give_Email_Notification $email Email Type.
326 * @param int $form_id Form ID.
327 *
328 * @since 2.0
329 * @access static
330 *
331 * @return array
332 */
333 public static function get_preview_setting_field( Give_Email_Notification $email, $form_id = null ) {
334 return array(
335 'name' => __( 'Preview Email', 'give' ),
336 '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.',
337 'give' ),
338 'id' => self::get_prefix( $email, $form_id ) . 'preview_buttons',
339 'type' => 'email_preview_buttons',
340 );
341 }
342
343
344 /**
345 * Get form metabox setting field prefix.
346 *
347 * @since 2.0
348 * @access static
349 *
350 * @param Give_Email_Notification $email
351 * @param int $form_id
352 *
353 * @return string
354 */
355 public static function get_prefix( Give_Email_Notification $email, $form_id = null ) {
356 $meta_key = "{$email->config['id']}_";
357
358 if( $form_id || give_is_add_new_form_page() ) {
359 $meta_key = "_give_{$email->config['id']}_";
360 }
361
362 return $meta_key;
363 }
364 }
365
366 // @todo: add per email sender options
367