Completed
Push — issues/1122 ( 0db41a )
by Ravinder
16:39
created

Give_Settings_Email   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 183
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 183
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 146 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
							'id'   => 'give_title_email_settings_1',
84
							'type' => 'sectionend'
85
						)
86
					);
87
					break;
88
89
				case 'donation-receipt':
90
					$settings = array(
91
						// Section 2: donation.
92
						array(
93
							'id'   => 'give_title_email_settings_2',
94
							'type' => 'title'
95
						),
96
						array(
97
							'id'      => 'donation_subject',
98
							'name'    => esc_html__( 'Donation Email Subject', 'give' ),
99
							'desc'    => esc_html__( 'Enter the subject line for the donation receipt email.', 'give' ),
100
							'default' => esc_attr__( 'Donation Receipt', 'give' ),
101
							'type'    => 'text'
102
						),
103
						array(
104
							'id'      => 'donation_receipt',
105
							'name'    => esc_html__( 'Donation Receipt', 'give' ),
106
							'desc'    => sprintf(
107
							/* translators: %s: emails tags list */
108
								esc_html__( 'Enter the email that is sent to users after completing a successful donation. HTML is accepted. Available template tags: %s', 'give' ),
109
								'<br/>'.give_get_emails_tags_list()
110
							),
111
							'type'    => 'wysiwyg',
112
							'default' => give_get_default_donation_receipt_email()
113
						),
114
						array(
115
							'id'   => 'give_title_email_settings_2',
116
							'type' => 'sectionend'
117
						)
118
					);
119
					break;
120
121
				case 'new-donation-notification':
122
					$settings = array(
123
						// Section 3: New Donation.
124
						array(
125
							'id'   => 'give_title_email_settings_3',
126
							'type' => 'title'
127
						),
128
						array(
129
							'id'      => 'admin_notices',
130
							'name'    => esc_html__( 'Admin Notifications', 'give' ),
131
							'desc'    => esc_html__( 'Check this box if you do not want to receive emails when new donations are made.', 'give' ),
132
							'type'    => 'radio_inline',
133
							'default' => 'enabled',
134
							'options' => array(
135
								'enabled'  => __( 'Enabled', 'give' ),
136
								'disabled' => __( 'Disabled', 'give' ),
137
							)
138
						),
139
						array(
140
							'id'      => 'donation_notification_subject',
141
							'name'    => esc_html__( 'Donation Notification Subject', 'give' ),
142
							'desc'    => esc_html__( 'Enter the subject line for the donation notification email.', 'give' ),
143
							'type'    => 'text',
144
							'default' => esc_attr__( 'New Donation - #{payment_id}', 'give' )
145
						),
146
						array(
147
							'id'      => 'donation_notification',
148
							'name'    => esc_html__( 'Donation Notification', 'give' ),
149
							'desc'    => sprintf(
150
							/* translators: %s: emails tags list */
151
								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' ),
152
								'<br/>'.give_get_emails_tags_list()
153
							),
154
							'type'    => 'wysiwyg',
155
							'default' => give_get_default_donation_notification_email()
156
						),
157
						array(
158
							'id'      => 'admin_notice_emails',
159
							'name'    => esc_html__( 'Donation Notification Emails', 'give' ),
160
							'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' ),
161
							'type'    => 'textarea',
162
							'default' => get_bloginfo( 'admin_email' )
163
						),
164
						array(
165
							'id'   => 'give_title_email_settings_3',
166
							'type' => 'sectionend'
167
						)
168
					);
169
					break;
170
			}
171
172
			/**
173
			 * Filter the emails settings.
174
			 * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8
175
			 */
176
			$settings = apply_filters( 'give_settings_emails', $settings );
177
178
			/**
179
			 * Filter the settings.
180
			 *
181
			 * @since  1.8
182
			 * @param  array $settings
183
			 */
184
			$settings = apply_filters( 'give_get_settings_' . $this->id, $settings );
185
186
			// Output.
187
			return $settings;
188
		}
189
190
		/**
191
		 * Get sections.
192
		 *
193
		 * @since 1.8
194
		 * @return array
195
		 */
196
		public function get_sections() {
197
			$sections = array(
198
				'email-settings'            => esc_html__( 'Email Settings', 'give' ),
199
				'donation-receipt'          => esc_html__( 'Donation Receipt', 'give' ),
200
				'new-donation-notification' => esc_html__( 'New Donation Notification', 'give' )
201
			);
202
203
			return apply_filters( 'give_get_sections_' . $this->id, $sections );
204
		}
205
	}
206
207
endif;
208
209
return new Give_Settings_Email();
210