Completed
Pull Request — master (#1412)
by Ravinder
17:25
created

Give_Settings_Email   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 204
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 204
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
B get_settings() 0 167 4
A get_sections() 0 9 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 23 and the first side effect is on line 13.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Give Settings Page/Tab
4
 *
5
 * @package     Give
6
 * @subpackage  Classes/Give_Settings_Email
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
9
 * @since       1.8
10
 */
11
12
if ( ! defined( 'ABSPATH' ) ) {
13
	exit; // Exit if accessed directly
14
}
15
16
if ( ! class_exists( 'Give_Settings_Email' ) ) :
17
18
	/**
19
	 * Give_Settings_Email.
20
	 *
21
	 * @sine 1.8
22
	 */
23
	class Give_Settings_Email extends Give_Settings_Page {
24
25
		/**
26
		 * Constructor.
27
		 */
28
		public function __construct() {
29
			$this->id    = 'emails';
30
			$this->label = esc_html__( 'Emails', 'give' );
31
32
			$this->default_tab = 'email-settings';
33
34
			parent::__construct();
35
		}
36
37
		/**
38
		 * Get settings array.
39
		 *
40
		 * @since  1.8
41
		 * @return array
42
		 */
43
		public function get_settings() {
44
			$settings = array();
45
			$current_section = give_get_current_setting_section();
46
47
			switch ( $current_section ) {
48
				case 'email-settings' :
49
					$settings = array(
50
						// Section 1: Email
51
						array(
52
							'id'   => 'give_title_email_settings_1',
53
							'type' => 'title'
54
						),
55
						array(
56
							'id'      => 'email_template',
57
							'name'    => esc_html__( 'Email Template', 'give' ),
58
							'desc'    => esc_html__( 'Choose a template. Click "Save Changes" then "Preview Donation Receipt" to see the new template.', 'give' ),
59
							'type'    => 'select',
60
							'options' => give_get_email_templates()
61
						),
62
						array(
63
							'id'   => 'email_logo',
64
							'name' => esc_html__( 'Logo', 'give' ),
65
							'desc' => esc_html__( 'Upload or choose a logo to be displayed at the top of the donation receipt emails. Displayed on HTML emails only.', 'give' ),
66
							'type' => 'file'
67
						),
68
						array(
69
							'id'      => 'from_name',
70
							'name'    => esc_html__( 'From Name', 'give' ),
71
							'desc'    => esc_html__( 'The name which appears in the "From" field in donation receipt emails.', 'give' ),
72
							'default' => get_bloginfo( 'name' ),
73
							'type'    => 'text'
74
						),
75
						array(
76
							'id'      => 'from_email',
77
							'name'    => esc_html__( 'From Email', 'give' ),
78
							'desc'    => esc_html__( 'Email to send donation receipts from. This will act as the "from" and "reply-to" address.', 'give' ),
79
							'default' => get_bloginfo( 'admin_email' ),
80
							'type'    => 'text'
81
						),
82
                        array(
83
                            'name'  => esc_html__( 'Email Settings Docs Link', 'give' ),
84
                            'id'    => 'email_settings_docs_link',
85
                            'url'   => esc_url( 'http://docs.givewp.com/emailsettings' ),
86
                            'title' => __( 'Email Settings', 'give' ),
87
                            'type'  => 'give_docs_link',
88
                        ),
89
						array(
90
							'id'   => 'give_title_email_settings_1',
91
							'type' => 'sectionend'
92
						)
93
					);
94
					break;
95
96
				case 'donation-receipt':
97
					$settings = array(
98
						// Section 2: donation.
99
						array(
100
							'id'   => 'give_title_email_settings_2',
101
							'type' => 'title'
102
						),
103
						array(
104
							'id'      => 'donation_subject',
105
							'name'    => esc_html__( 'Donation Email Subject', 'give' ),
106
							'desc'    => esc_html__( 'Enter the subject line for the donation receipt email.', 'give' ),
107
							'default' => esc_attr__( 'Donation Receipt', 'give' ),
108
							'type'    => 'text'
109
						),
110
						array(
111
							'id'      => 'donation_receipt',
112
							'name'    => esc_html__( 'Donation Receipt', 'give' ),
113
							'desc'    => sprintf(
114
							/* translators: %s: emails tags list */
115
								esc_html__( 'Enter the email that is sent to users after completing a successful donation. HTML is accepted. Available template tags: %s', 'give' ),
116
								'<br/>'.give_get_emails_tags_list()
117
							),
118
							'type'    => 'wysiwyg',
119
							'default' => give_get_default_donation_receipt_email()
120
						),
121
                        array(
122
                            'name'  => esc_html__( 'Donation Receipt Settings Docs Link', 'give' ),
123
                            'id'    => 'donation_receipt_settings_docs_link',
124
                            'url'   => esc_url( 'http://docs.givewp.com/donationreceipt' ),
125
                            'title' => __( 'Donation Receipt Settings', 'give' ),
126
                            'type'  => 'give_docs_link',
127
                        ),
128
						array(
129
							'id'   => 'give_title_email_settings_2',
130
							'type' => 'sectionend'
131
						)
132
					);
133
					break;
134
135
				case 'new-donation-notification':
136
					$settings = array(
137
						// Section 3: New Donation.
138
						array(
139
							'id'   => 'give_title_email_settings_3',
140
							'type' => 'title'
141
						),
142
						array(
143
							'id'      => 'admin_notices',
144
							'name'    => esc_html__( 'Admin Notifications', 'give' ),
145
							'desc'    => esc_html__( 'Check this box if you do not want to receive emails when new donations are made.', 'give' ),
146
							'type'    => 'radio_inline',
147
							'default' => 'enabled',
148
							'options' => array(
149
								'enabled'  => __( 'Enabled', 'give' ),
150
								'disabled' => __( 'Disabled', 'give' ),
151
							)
152
						),
153
						array(
154
							'id'      => 'donation_notification_subject',
155
							'name'    => esc_html__( 'Donation Notification Subject', 'give' ),
156
							'desc'    => esc_html__( 'Enter the subject line for the donation notification email.', 'give' ),
157
							'type'    => 'text',
158
							'default' => esc_attr__( 'New Donation - #{payment_id}', 'give' )
159
						),
160
						array(
161
							'id'      => 'donation_notification',
162
							'name'    => esc_html__( 'Donation Notification', 'give' ),
163
							'desc'    => sprintf(
164
							/* translators: %s: emails tags list */
165
								esc_html__( 'Enter the email that is sent to donation notification emails after completion of a donation. HTML is accepted. Available template tags: %s', 'give' ),
166
								'<br/>'.give_get_emails_tags_list()
167
							),
168
							'type'    => 'wysiwyg',
169
							'default' => give_get_default_donation_notification_email()
170
						),
171
						array(
172
							'id'      => 'admin_notice_emails',
173
							'name'    => esc_html__( 'Donation Notification Emails', 'give' ),
174
							'desc'    => __( 'Enter the email address(es) that should receive a notification anytime a donation is made, please only enter <span class="give-underline">one email address per line</span> and <strong>not separated by commas</strong>.', 'give' ),
175
							'type'    => 'textarea',
176
							'default' => get_bloginfo( 'admin_email' )
177
						),
178
                        array(
179
                            'name'  => esc_html__( 'Donation Notification Settings Docs Link', 'give' ),
180
                            'id'    => 'donation_notification_settings_docs_link',
181
                            'url'   => esc_url( 'http://docs.givewp.com/donationnotification' ),
182
                            'title' => __( 'Donation Notification Settings', 'give' ),
183
                            'type'  => 'give_docs_link',
184
                        ),
185
						array(
186
							'id'   => 'give_title_email_settings_3',
187
							'type' => 'sectionend'
188
						)
189
					);
190
					break;
191
			}
192
193
			/**
194
			 * Filter the emails settings.
195
			 * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8
196
			 */
197
			$settings = apply_filters( 'give_settings_emails', $settings );
198
199
			/**
200
			 * Filter the settings.
201
			 *
202
			 * @since  1.8
203
			 * @param  array $settings
204
			 */
205
			$settings = apply_filters( 'give_get_settings_' . $this->id, $settings );
206
207
			// Output.
208
			return $settings;
209
		}
210
211
		/**
212
		 * Get sections.
213
		 *
214
		 * @since 1.8
215
		 * @return array
216
		 */
217
		public function get_sections() {
218
			$sections = array(
219
				'email-settings'            => esc_html__( 'Email Settings', 'give' ),
220
				'donation-receipt'          => esc_html__( 'Donation Receipt', 'give' ),
221
				'new-donation-notification' => esc_html__( 'New Donation Notification', 'give' )
222
			);
223
224
			return apply_filters( 'give_get_sections_' . $this->id, $sections );
225
		}
226
	}
227
228
endif;
229
230
return new Give_Settings_Email();
231