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

Give_Settings_General   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 237
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 237
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 200 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_General
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_General' ) ) :
17
18
	/**
19
	 * Give_Settings_General.
20
	 *
21
	 * @sine 1.8
22
	 */
23
	class Give_Settings_General extends Give_Settings_Page {
24
25
		/**
26
		 * Constructor.
27
		 */
28
		public function __construct() {
29
			$this->id    = 'general';
30
			$this->label = esc_html__( 'General', 'give' );
31
32
			$this->default_tab = 'general-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 'access-control':
49
					$settings = array(
50
						// Section 3: Access control.
51
						array(
52
							'id'   => 'give_title_session_control_1',
53
							'type' => 'title'
54
						),
55
						array(
56
							'id'      => 'session_lifetime',
57
							'name'    => esc_html__( 'Session Lifetime', 'give' ),
58
							'desc'    => esc_html__( 'The length of time a user\'s session is kept alive. Give starts a new session per user upon donation. Sessions allow donors to view their donation receipts without being logged in.', 'give' ),
59
							'type'    => 'select',
60
							'options' => array(
61
								'86400'  => esc_html__( '24 Hours', 'give' ),
62
								'172800' => esc_html__( '48 Hours', 'give' ),
63
								'259200' => esc_html__( '72 Hours', 'give' ),
64
								'604800' => esc_html__( '1 Week', 'give' ),
65
							)
66
						),
67
						array(
68
							'name'    => esc_html__( 'Email Access', 'give' ),
69
							'desc'    => esc_html__( 'Would you like your donors to be able to access their donation history using only email? Donors whose sessions have expired and do not have an account may still access their donation history via a temporary email access link.', 'give' ),
70
							'id'      => 'email_access',
71
							'type'    => 'radio_inline',
72
							'default' => 'disabled',
73
							'options' => array(
74
								'enabled'  => __( 'Enabled', 'give' ),
75
								'disabled' => __( 'Disabled', 'give' ),
76
							)
77
						),
78
						array(
79
							'id'      => 'recaptcha_key',
80
							'name'    => esc_html__( 'reCAPTCHA Site Key', 'give' ),
81
							/* translators: %s: https://www.google.com/recaptcha/ */
82
							'desc'    => sprintf( __( 'If you would like to prevent spam on the email access form navigate to <a href="%s" target="_blank">the reCAPTCHA website</a> and sign up for an API key. The reCAPTCHA uses Google\'s user-friendly single click verification method.', 'give' ), esc_url( 'https://www.google.com/recaptcha/' ) ),
83
							'default' => '',
84
							'type'    => 'text'
85
						),
86
						array(
87
							'id'      => 'recaptcha_secret',
88
							'name'    => esc_html__( 'reCAPTCHA Secret Key', 'give' ),
89
							'desc'    => esc_html__( 'Please paste the reCAPTCHA secret key here from your manage reCAPTCHA API Keys panel.', 'give' ),
90
							'default' => '',
91
							'type'    => 'text'
92
						),
93
						array(
94
							'id'   => 'give_title_session_control_1',
95
							'type' => 'sectionend'
96
						),
97
					);
98
					break;
99
100
				case 'currency-settings' :
101
					$settings = array(
102
						// Section 2: Currency
103
						array(
104
							'type' => 'title',
105
							'id'   => 'give_title_general_settings_2'
106
						),
107
						array(
108
							'name' => esc_html__( 'Currency Settings', 'give' ),
109
							'desc' => '',
110
							'type' => 'give_title',
111
							'id'   => 'give_title_general_settings_2'
112
						),
113
						array(
114
							'name'    => esc_html__( 'Currency', 'give' ),
115
							'desc'    => esc_html__( 'The donation currency. Note that some payment gateways have currency restrictions.', 'give' ),
116
							'id'      => 'currency',
117
							'type'    => 'select',
118
							'options' => give_get_currencies(),
119
							'default' => 'USD',
120
						),
121
						array(
122
							'name'    => esc_html__( 'Currency Position', 'give' ),
123
							'desc'    => esc_html__( 'The position of the currency symbol.', 'give' ),
124
							'id'      => 'currency_position',
125
							'type'    => 'select',
126
							'options' => array(
127
								/* translators: %s: currency symbol */
128
								'before' => sprintf( esc_html__( 'Before - %s10', 'give' ), give_currency_symbol( give_get_currency() ) ),
129
								/* translators: %s: currency symbol */
130
								'after'  => sprintf( esc_html__( 'After - 10%s', 'give' ), give_currency_symbol( give_get_currency() ) )
131
							),
132
							'default' => 'before',
133
						),
134
						array(
135
							'name'    => esc_html__( 'Thousands Separator', 'give' ),
136
							'desc'    => esc_html__( 'The symbol (typically , or .) to separate thousands.', 'give' ),
137
							'id'      => 'thousands_separator',
138
							'type'    => 'text',
139
							'default' => ',',
140
							'css'     => 'width:12em;',
141
						),
142
						array(
143
							'name'    => esc_html__( 'Decimal Separator', 'give' ),
144
							'desc'    => esc_html__( 'The symbol (usually , or .) to separate decimal points.', 'give' ),
145
							'id'      => 'decimal_separator',
146
							'type'    => 'text',
147
							'default' => '.',
148
							'css'     => 'width:12em;',
149
						),
150
						array(
151
							'name'            => __( 'Number of Decimals', 'give' ),
152
							'desc'            => __( 'The number of decimal points displayed in amounts.', 'give' ),
153
							'id'              => 'number_decimals',
154
							'type'            => 'text',
155
							'default'         => 2,
156
							'css'             => 'width:12em;',
157
						),
158
						array(
159
							'type' => 'title',
160
							'id'   => 'give_title_general_settings_2'
161
						)
162
					);
163
					break;
164
165
				case 'general-settings':
166
					$settings = array(
167
						// Section 1: General.
168
						array(
169
							'type' => 'title',
170
							'id'   => 'give_title_general_settings_1'
171
						),
172
						array(
173
							'name' => esc_html__( 'General Settings', 'give' ),
174
							'desc' => '',
175
							'type' => 'give_title',
176
							'id'   => 'give_title_general_settings_1'
177
						),
178
						array(
179
							'name'    => esc_html__( 'Success Page', 'give' ),
180
							/* translators: %s: [give_receipt] */
181
							'desc'    => sprintf( __( 'The page donors are sent to after completing their donations. The %s shortcode should be on this page.', 'give' ), '<code>[give_receipt]</code>' ),
182
							'id'      => 'success_page',
183
							'type'    => 'select',
184
							'options' => give_cmb2_get_post_options( array(
185
								'post_type'   => 'page',
186
								'numberposts' => - 1
187
							) ),
188
						),
189
						array(
190
							'name'    => esc_html__( 'Failed Donation Page', 'give' ),
191
							'desc'    => esc_html__( 'The page donors are sent to if their donation is cancelled or fails.', 'give' ),
192
							'id'      => 'failure_page',
193
							'type'    => 'select',
194
							'options' => give_cmb2_get_post_options( array(
195
								'post_type'   => 'page',
196
								'numberposts' => - 1
197
							) ),
198
						),
199
						array(
200
							'name'    => esc_html__( 'Donation History Page', 'give' ),
201
							/* translators: %s: [donation_history] */
202
							'desc'    => sprintf( __( 'The page showing a complete donation history for the current user. The %s shortcode should be on this page.', 'give' ), '<code>[donation_history]</code>' ),
203
							'id'      => 'history_page',
204
							'type'    => 'select',
205
							'options' => give_cmb2_get_post_options( array(
206
								'post_type'   => 'page',
207
								'numberposts' => - 1
208
							) ),
209
						),
210
						array(
211
							'name'    => esc_html__( 'Base Country', 'give' ),
212
							'desc'    => esc_html__( 'The country your site operates from.', 'give' ),
213
							'id'      => 'base_country',
214
							'type'    => 'select',
215
							'options' => give_get_country_list(),
216
						),
217
						array(
218
							'type' => 'sectionend',
219
							'id'   => 'give_title_general_settings_1'
220
						)
221
					);
222
					break;
223
			}
224
225
			/**
226
			 * Filter the general settings.
227
			 * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8
228
			 */
229
			$settings = apply_filters( 'give_settings_general', $settings );
230
231
			/**
232
			 * Filter the settings.
233
			 *
234
			 * @since  1.8
235
			 *
236
			 * @param  array $settings
237
			 */
238
			$settings = apply_filters( 'give_get_settings_' . $this->id, $settings );
239
240
			// Output.
241
			return $settings;
242
		}
243
244
		/**
245
		 * Get sections.
246
		 *
247
		 * @since 1.8
248
		 * @return array
249
		 */
250
		public function get_sections() {
251
			$sections = array(
252
				'general-settings'  => esc_html__( 'General', 'give' ),
253
				'currency-settings' => esc_html__( 'Currency', 'give' ),
254
				'access-control'    => esc_html__( 'Access Control', 'give' )
255
			);
256
257
			return apply_filters( 'give_get_sections_' . $this->id, $sections );
258
		}
259
	}
260
261
endif;
262
263
return new Give_Settings_General();
264