Completed
Push — issues/611 ( b6e9e2...d123e1 )
by Ravinder
18:34
created

get_default_setting_fields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
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       1.9
11
 */
12
class Give_Email_Setting_Field {
13
	/**
14
	 * Get setting field.
15
	 *
16
	 * @since  1.9
17
	 * @access public
18
	 *
19
	 * @param Give_Email_Notification $email
20
	 *
21
	 * @return array|int
22
	 */
23
	public static function get_setting_fields( Give_Email_Notification $email ) {
24
		$setting_fields = self::get_default_setting_fields( $email );
25
26
		// Recipient field.
27
		if ( $email->has_recipient_field() ) {
28
			$setting_fields[] = self::get_recipient_setting_field( $email );
29
		}
30
31
		// Preview field.
32
		if ( $email->has_preview() ) {
33
			$setting_fields[] = self::get_preview_setting_field( $email );
34
		}
35
36
		// Add extra setting field.
37
		if ( $extra_setting_field = $email->get_extra_setting_fields() ) {
38
			$setting_fields = array_merge( $setting_fields, $extra_setting_field );
39
		}
40
41
		$setting_fields = self::add_section_end( $setting_fields, $email );
42
43
		return $setting_fields;
44
	}
45
46
47
	/**
48
	 * Check if email notification setting has section end or not.
49
	 *
50
	 * @since  1.9
51
	 * @access private
52
	 *
53
	 * @param $setting
54
	 *
55
	 * @return bool
56
	 */
57
	public static function has_section_end( $setting ) {
58
		$last_field      = end( $setting );
59
		$has_section_end = false;
60
61
		if ( 'sectionend' === $last_field['type'] ) {
62
			$has_section_end = true;
63
		}
64
65
		return $has_section_end;
66
	}
67
68
	/**
69
	 * Check if email notification setting has section end or not.
70
	 *
71
	 * @since  1.9
72
	 * @access private
73
	 *
74
	 * @param array                   $setting
75
	 * @param Give_Email_Notification $email
76
	 *
77
	 * @return array
78
	 */
79
	public static function add_section_end( $setting, Give_Email_Notification $email ) {
80
		if ( ! self::has_section_end( $setting ) ) {
81
			// Add section end field.
82
			$setting[] = array(
83
				'id'   => "give_title_email_settings_{$email->get_id()}",
84
				'type' => 'sectionend',
85
			);
86
		}
87
88
		return $setting;
89
	}
90
91
	/**
92
	 * Get default setting field.
93
	 *
94
	 * @since  1.9
95
	 * @access static
96
	 *
97
	 * @param Give_Email_Notification $email
98
	 *
99
	 * @return array
100
	 */
101
	public static function get_default_setting_fields( Give_Email_Notification $email ) {
102
		return array(
103
			array(
104
				'id'    => "give_title_email_settings_{$email->get_id()}",
105
				'type'  => 'title',
106
				'title' => $email->get_label(),
107
			),
108
			self::get_notification_status_field( $email ),
109
			self::get_email_subject_field( $email ),
110
			self::get_email_message_field( $email ),
111
		);
112
	}
113
114
	/**
115
	 * Get notification status setting field.
116
	 *
117
	 * @since  1.9
118
	 * @access static
119
	 *
120
	 * @param Give_Email_Notification $email
121
	 *
122
	 * @return array
123
	 */
124
	public static function get_notification_status_field( Give_Email_Notification $email ) {
125
		return array(
126
			'name'    => esc_html__( 'Notification', 'give' ),
127
			'desc'    => esc_html__( 'Choose option if you want to send email notification or not.', 'give' ),
128
			'id'      => "{$email->get_id()}_notification",
129
			'type'    => 'radio_inline',
130
			'default' => $email->get_notification_status(),
131
			'options' => array(
132
				'enabled'  => __( 'Enabled', 'give' ),
133
				'disabled' => __( 'Disabled', 'give' ),
134
			),
135
		);
136
	}
137
138
	/**
139
	 * Get email subject setting field.
140
	 *
141
	 * @since  1.9
142
	 * @access static
143
	 *
144
	 * @param Give_Email_Notification $email
145
	 *
146
	 * @return array
147
	 */
148
	public static function get_email_subject_field( Give_Email_Notification $email ) {
149
		return array(
150
			'id'      => "{$email->get_id()}_email_subject",
151
			'name'    => esc_html__( 'Email Subject', 'give' ),
152
			'desc'    => esc_html__( 'Enter the subject line for email.', 'give' ),
153
			'default' => $email->get_default_email_subject(),
154
			'type'    => 'text',
155
		);
156
	}
157
158
	/**
159
	 * Get email message setting field.
160
	 *
161
	 * @since  1.9
162
	 * @access static
163
	 *
164
	 * @param Give_Email_Notification $email
165
	 *
166
	 * @return array
167
	 */
168
	public static function get_email_message_field( Give_Email_Notification $email ) {
169
		return array(
170
			'id'      => "{$email->get_id()}_email_message",
171
			'name'    => esc_html__( 'Email message', 'give' ),
172
			'desc'    => $email->get_email_message_field_description(),
173
			'type'    => 'wysiwyg',
174
			'default' => $email->get_default_email_message(),
175
		);
176
	}
177
178
179
	/**
180
	 * Get recipient setting field.
181
	 *
182
	 * @since  1.9
183
	 * @access static
184
	 *
185
	 * @param Give_Email_Notification $email
186
	 *
187
	 * @return array
188
	 */
189
	public static function get_recipient_setting_field( Give_Email_Notification $email ) {
190
		return array(
191
			'id'               => "{$email->get_id()}_recipient",
192
			'name'             => esc_html__( 'Email Recipients', 'give' ),
193
			'desc'             => __( 'Enter the email address(es) that should receive a notification anytime a donation is made.', 'give' ),
194
			'type'             => 'email',
195
			'default'          => get_bloginfo( 'admin_email' ),
196
			'repeat'           => true,
197
			'repeat_btn_title' => esc_html__( 'Add Recipient', 'give' ),
198
		);
199
	}
200
201
	/**
202
	 * Get preview setting field.
203
	 *
204
	 * @since  1.9
205
	 * @access static
206
	 *
207
	 * @param Give_Email_Notification $email
208
	 *
209
	 * @return array
210
	 */
211
	public static function get_preview_setting_field( Give_Email_Notification $email ) {
212
		return array(
213
			'name' => esc_html__( 'Preview Email', 'give' ),
214
			'desc' => esc_html__( 'Click the buttons to preview emails.', 'give' ),
215
			'id'   => "{$email->get_id()}_preview_buttons",
216
			'type' => 'email_preview_buttons',
217
		);
218
	}
219
}