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

Give_Settings_General::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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( 'http://docs.givewp.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
                            'name'  => esc_html__( 'Access Control Docs Link', 'give' ),
95
                            'id'    => 'access_control_docs_link',
96
                            'url'   => esc_url( 'http://docs.givewp.com/accesscontrol' ),
97
                            'title' => __( 'Access Control', 'give' ),
98
                            'type'  => 'give_docs_link',
99
                        ),
100
						array(
101
							'id'   => 'give_title_session_control_1',
102
							'type' => 'sectionend'
103
						),
104
					);
105
					break;
106
107
				case 'currency-settings' :
108
					$settings = array(
109
						// Section 2: Currency
110
						array(
111
							'type' => 'title',
112
							'id'   => 'give_title_general_settings_2'
113
						),
114
						array(
115
							'name' => esc_html__( 'Currency Settings', 'give' ),
116
							'desc' => '',
117
							'type' => 'give_title',
118
							'id'   => 'give_title_general_settings_2'
119
						),
120
						array(
121
							'name'    => esc_html__( 'Currency', 'give' ),
122
							'desc'    => esc_html__( 'The donation currency. Note that some payment gateways have currency restrictions.', 'give' ),
123
							'id'      => 'currency',
124
							'type'    => 'select',
125
							'options' => give_get_currencies(),
126
							'default' => 'USD',
127
						),
128
						array(
129
							'name'    => esc_html__( 'Currency Position', 'give' ),
130
							'desc'    => esc_html__( 'The position of the currency symbol.', 'give' ),
131
							'id'      => 'currency_position',
132
							'type'    => 'select',
133
							'options' => array(
134
								/* translators: %s: currency symbol */
135
								'before' => sprintf( esc_html__( 'Before - %s10', 'give' ), give_currency_symbol( give_get_currency() ) ),
136
								/* translators: %s: currency symbol */
137
								'after'  => sprintf( esc_html__( 'After - 10%s', 'give' ), give_currency_symbol( give_get_currency() ) )
138
							),
139
							'default' => 'before',
140
						),
141
						array(
142
							'name'    => esc_html__( 'Thousands Separator', 'give' ),
143
							'desc'    => esc_html__( 'The symbol (typically , or .) to separate thousands.', 'give' ),
144
							'id'      => 'thousands_separator',
145
							'type'    => 'text',
146
							'default' => ',',
147
							'css'     => 'width:12em;',
148
						),
149
						array(
150
							'name'    => esc_html__( 'Decimal Separator', 'give' ),
151
							'desc'    => esc_html__( 'The symbol (usually , or .) to separate decimal points.', 'give' ),
152
							'id'      => 'decimal_separator',
153
							'type'    => 'text',
154
							'default' => '.',
155
							'css'     => 'width:12em;',
156
						),
157
						array(
158
							'name'            => __( 'Number of Decimals', 'give' ),
159
							'desc'            => __( 'The number of decimal points displayed in amounts.', 'give' ),
160
							'id'              => 'number_decimals',
161
							'type'            => 'text',
162
							'default'         => 2,
163
							'css'             => 'width:12em;',
164
						),
165
                        array(
166
                            'name'  => esc_html__( 'Currency Options Docs Link', 'give' ),
167
                            'id'    => 'currency_settings_docs_link',
168
                            'url'   => esc_url( 'http://docs.givewp.com/currencysettings' ),
169
                            'title' => __( 'Currency Settings', 'give' ),
170
                            'type'  => 'give_docs_link',
171
                        ),
172
						array(
173
							'type' => 'title',
174
							'id'   => 'give_title_general_settings_2'
175
						)
176
					);
177
					break;
178
179
				case 'general-settings':
180
					$settings = array(
181
						// Section 1: General.
182
						array(
183
							'type' => 'title',
184
							'id'   => 'give_title_general_settings_1'
185
						),
186
						array(
187
							'name' => esc_html__( 'General Settings', 'give' ),
188
							'desc' => '',
189
							'type' => 'give_title',
190
							'id'   => 'give_title_general_settings_1'
191
						),
192
						array(
193
							'name'    => esc_html__( 'Success Page', 'give' ),
194
							/* translators: %s: [give_receipt] */
195
							'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>' ),
196
							'id'      => 'success_page',
197
							'type'    => 'select',
198
							'options' => give_cmb2_get_post_options( array(
199
								'post_type'   => 'page',
200
								'numberposts' => - 1
201
							) ),
202
						),
203
						array(
204
							'name'    => esc_html__( 'Failed Donation Page', 'give' ),
205
							'desc'    => esc_html__( 'The page donors are sent to if their donation is cancelled or fails.', 'give' ),
206
							'id'      => 'failure_page',
207
							'type'    => 'select',
208
							'options' => give_cmb2_get_post_options( array(
209
								'post_type'   => 'page',
210
								'numberposts' => - 1
211
							) ),
212
						),
213
						array(
214
							'name'    => esc_html__( 'Donation History Page', 'give' ),
215
							/* translators: %s: [donation_history] */
216
							'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>' ),
217
							'id'      => 'history_page',
218
							'type'    => 'select',
219
							'options' => give_cmb2_get_post_options( array(
220
								'post_type'   => 'page',
221
								'numberposts' => - 1
222
							) ),
223
						),
224
						array(
225
							'name'    => esc_html__( 'Base Country', 'give' ),
226
							'desc'    => esc_html__( 'The country your site operates from.', 'give' ),
227
							'id'      => 'base_country',
228
							'type'    => 'select',
229
							'options' => give_get_country_list(),
230
						),
231
                        array(
232
                            'name'  => esc_html__( 'General Options Docs Link', 'give' ),
233
                            'id'    => 'general_options_docs_link',
234
                            'url'   => esc_url( 'http://docs.givewp.com/generaloptions' ),
235
                            'title' => __( 'General Options', 'give' ),
236
                            'type'  => 'give_docs_link',
237
                        ),
238
						array(
239
							'type' => 'sectionend',
240
							'id'   => 'give_title_general_settings_1'
241
						)
242
					);
243
					break;
244
			}
245
246
			/**
247
			 * Filter the general settings.
248
			 * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8
249
			 */
250
			$settings = apply_filters( 'give_settings_general', $settings );
251
252
			/**
253
			 * Filter the settings.
254
			 *
255
			 * @since  1.8
256
			 *
257
			 * @param  array $settings
258
			 */
259
			$settings = apply_filters( 'give_get_settings_' . $this->id, $settings );
260
261
			// Output.
262
			return $settings;
263
		}
264
265
		/**
266
		 * Get sections.
267
		 *
268
		 * @since 1.8
269
		 * @return array
270
		 */
271
		public function get_sections() {
272
			$sections = array(
273
				'general-settings'  => esc_html__( 'General', 'give' ),
274
				'currency-settings' => esc_html__( 'Currency', 'give' ),
275
				'access-control'    => esc_html__( 'Access Control', 'give' )
276
			);
277
278
			return apply_filters( 'give_get_sections_' . $this->id, $sections );
279
		}
280
	}
281
282
endif;
283
284
return new Give_Settings_General();
285