| Conditions | 7 |
| Paths | 8 |
| Total Lines | 322 |
| Code Lines | 230 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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' => __( 'Session Lifetime', 'give' ), |
||
| 58 | 'desc' => __( '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' => __( '24 Hours', 'give' ), |
||
| 62 | '172800' => __( '48 Hours', 'give' ), |
||
| 63 | '259200' => __( '72 Hours', 'give' ), |
||
| 64 | '604800' => __( '1 Week', 'give' ), |
||
| 65 | ), |
||
| 66 | ), |
||
| 67 | array( |
||
| 68 | 'id' => 'limit_display_donations', |
||
| 69 | 'name' => __( 'Limit Donations Displayed', 'give' ), |
||
| 70 | 'desc' => __( 'Adjusts the number of donations displayed to a non logged-in user when they attempt to access the Donation History page without an active session. For security reasons, it\'s best to leave this at 1-3 donations.', 'give' ), |
||
| 71 | 'default' => '1', |
||
| 72 | 'type' => 'number', |
||
| 73 | 'css' => 'width:50px;', |
||
| 74 | 'attributes' => array( |
||
| 75 | 'min' => '1', |
||
| 76 | 'max' => '10', |
||
| 77 | ), |
||
| 78 | ), |
||
| 79 | array( |
||
| 80 | 'name' => __( 'Email Access', 'give' ), |
||
| 81 | 'desc' => __( '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' ), |
||
| 82 | 'id' => 'email_access', |
||
| 83 | 'type' => 'radio_inline', |
||
| 84 | 'default' => 'disabled', |
||
| 85 | 'options' => array( |
||
| 86 | 'enabled' => __( 'Enabled', 'give' ), |
||
| 87 | 'disabled' => __( 'Disabled', 'give' ), |
||
| 88 | ), |
||
| 89 | ), |
||
| 90 | array( |
||
| 91 | 'name' => __( 'Enable reCAPTCHA', 'give' ), |
||
| 92 | 'desc' => __( 'Would you like to enable the reCAPTCHA feature?', 'give' ), |
||
| 93 | 'id' => 'enable_recaptcha', |
||
| 94 | 'type' => 'radio_inline', |
||
| 95 | 'default' => 'disabled', |
||
| 96 | 'options' => array( |
||
| 97 | 'enabled' => __( 'Enabled', 'give' ), |
||
| 98 | 'disabled' => __( 'Disabled', 'give' ), |
||
| 99 | ), |
||
| 100 | ), |
||
| 101 | array( |
||
| 102 | 'id' => 'recaptcha_key', |
||
| 103 | 'name' => __( 'reCAPTCHA Site Key', 'give' ), |
||
| 104 | /* translators: %s: https://www.google.com/recaptcha/ */ |
||
| 105 | '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 and paste your reCAPTCHA site key here. The reCAPTCHA uses Google\'s user-friendly single click verification method.', 'give' ), esc_url( 'http://docs.givewp.com/recaptcha' ) ), |
||
| 106 | 'default' => '', |
||
| 107 | 'type' => 'text', |
||
| 108 | ), |
||
| 109 | array( |
||
| 110 | 'id' => 'recaptcha_secret', |
||
| 111 | 'name' => __( 'reCAPTCHA Secret Key', 'give' ), |
||
| 112 | 'desc' => __( 'Please paste the reCAPTCHA secret key here from your reCAPTCHA API Keys panel.', 'give' ), |
||
| 113 | 'default' => '', |
||
| 114 | 'type' => 'text', |
||
| 115 | ), |
||
| 116 | array( |
||
| 117 | 'name' => __( 'Access Control Docs Link', 'give' ), |
||
| 118 | 'id' => 'access_control_docs_link', |
||
| 119 | 'url' => esc_url( 'http://docs.givewp.com/settings-access-control' ), |
||
| 120 | 'title' => __( 'Access Control', 'give' ), |
||
| 121 | 'type' => 'give_docs_link', |
||
| 122 | ), |
||
| 123 | array( |
||
| 124 | 'id' => 'give_title_session_control_1', |
||
| 125 | 'type' => 'sectionend', |
||
| 126 | ), |
||
| 127 | ); |
||
| 128 | break; |
||
| 129 | |||
| 130 | case 'currency-settings' : |
||
| 131 | $currency_position_before = __( 'Before - %s‎10', 'give' ); |
||
| 132 | $currency_position_after = __( 'After - 10%s‏', 'give' ); |
||
| 133 | |||
| 134 | $settings = array( |
||
| 135 | // Section 2: Currency |
||
| 136 | array( |
||
| 137 | 'type' => 'title', |
||
| 138 | 'id' => 'give_title_general_settings_2', |
||
| 139 | ), |
||
| 140 | array( |
||
| 141 | 'name' => __( 'Currency Settings', 'give' ), |
||
| 142 | 'desc' => '', |
||
| 143 | 'type' => 'give_title', |
||
| 144 | 'id' => 'give_title_general_settings_2', |
||
| 145 | ), |
||
| 146 | array( |
||
| 147 | 'name' => __( 'Currency', 'give' ), |
||
| 148 | 'desc' => __( 'The donation currency. Note that some payment gateways have currency restrictions.', 'give' ), |
||
| 149 | 'id' => 'currency', |
||
| 150 | 'class' => 'give-select-chosen', |
||
| 151 | 'type' => 'select', |
||
| 152 | 'options' => give_get_currencies(), |
||
| 153 | 'default' => 'USD', |
||
| 154 | ), |
||
| 155 | array( |
||
| 156 | 'name' => __( 'Currency Position', 'give' ), |
||
| 157 | 'desc' => __( 'The position of the currency symbol.', 'give' ), |
||
| 158 | 'id' => 'currency_position', |
||
| 159 | 'type' => 'select', |
||
| 160 | 'options' => array( |
||
| 161 | /* translators: %s: currency symbol */ |
||
| 162 | 'before' => sprintf( $currency_position_before, give_currency_symbol( give_get_currency() ) ), |
||
| 163 | /* translators: %s: currency symbol */ |
||
| 164 | 'after' => sprintf( $currency_position_after, give_currency_symbol( give_get_currency() ) ), |
||
| 165 | ), |
||
| 166 | 'default' => 'before', |
||
| 167 | 'attributes' => array( |
||
| 168 | 'data-before-template' => sprintf( $currency_position_before, '{currency_pos}' ), |
||
| 169 | 'data-after-template' => sprintf( $currency_position_after, '{currency_pos}' ), |
||
| 170 | ), |
||
| 171 | ), |
||
| 172 | array( |
||
| 173 | 'name' => __( 'Thousands Separator', 'give' ), |
||
| 174 | 'desc' => __( 'The symbol (typically , or .) to separate thousands.', 'give' ), |
||
| 175 | 'id' => 'thousands_separator', |
||
| 176 | 'type' => 'text', |
||
| 177 | 'default' => ',', |
||
| 178 | 'css' => 'width:12em;', |
||
| 179 | ), |
||
| 180 | array( |
||
| 181 | 'name' => __( 'Decimal Separator', 'give' ), |
||
| 182 | 'desc' => __( 'The symbol (usually , or .) to separate decimal points.', 'give' ), |
||
| 183 | 'id' => 'decimal_separator', |
||
| 184 | 'type' => 'text', |
||
| 185 | 'default' => '.', |
||
| 186 | 'css' => 'width:12em;', |
||
| 187 | ), |
||
| 188 | array( |
||
| 189 | 'name' => __( 'Number of Decimals', 'give' ), |
||
| 190 | 'desc' => __( 'The number of decimal points displayed in amounts.', 'give' ), |
||
| 191 | 'id' => 'number_decimals', |
||
| 192 | 'type' => 'text', |
||
| 193 | 'default' => 2, |
||
| 194 | 'css' => 'width:12em;', |
||
| 195 | ), |
||
| 196 | array( |
||
| 197 | 'name' => __( 'Currency Options Docs Link', 'give' ), |
||
| 198 | 'id' => 'currency_settings_docs_link', |
||
| 199 | 'url' => esc_url( 'http://docs.givewp.com/settings-currency' ), |
||
| 200 | 'title' => __( 'Currency Settings', 'give' ), |
||
| 201 | 'type' => 'give_docs_link', |
||
| 202 | ), |
||
| 203 | array( |
||
| 204 | 'type' => 'sectionend', |
||
| 205 | 'id' => 'give_title_general_settings_2', |
||
| 206 | ), |
||
| 207 | ); |
||
| 208 | |||
| 209 | break; |
||
| 210 | |||
| 211 | case 'general-settings': |
||
| 212 | // Get default country code. |
||
| 213 | $country = give_get_country(); |
||
| 214 | |||
| 215 | // get the list of the states of which default country is selected. |
||
| 216 | $states = give_get_states( $country ); |
||
| 217 | |||
| 218 | // Get the country list that does not have any states init. |
||
| 219 | $no_states_country = give_no_states_country_list(); |
||
| 220 | |||
| 221 | $settings = array( |
||
| 222 | // Section 1: General. |
||
| 223 | array( |
||
| 224 | 'type' => 'title', |
||
| 225 | 'id' => 'give_title_general_settings_1', |
||
| 226 | ), |
||
| 227 | array( |
||
| 228 | 'name' => __( 'General Settings', 'give' ), |
||
| 229 | 'desc' => '', |
||
| 230 | 'type' => 'give_title', |
||
| 231 | 'id' => 'give_title_general_settings_1', |
||
| 232 | ), |
||
| 233 | array( |
||
| 234 | 'name' => __( 'Success Page', 'give' ), |
||
| 235 | /* translators: %s: [give_receipt] */ |
||
| 236 | '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>' ), |
||
| 237 | 'id' => 'success_page', |
||
| 238 | 'type' => 'select', |
||
| 239 | 'options' => give_cmb2_get_post_options( array( |
||
| 240 | 'post_type' => 'page', |
||
| 241 | 'numberposts' => 999, |
||
|
|
|||
| 242 | ) ), |
||
| 243 | ), |
||
| 244 | array( |
||
| 245 | 'name' => __( 'Failed Donation Page', 'give' ), |
||
| 246 | 'desc' => __( 'The page donors are sent to if their donation is cancelled or fails.', 'give' ), |
||
| 247 | 'id' => 'failure_page', |
||
| 248 | 'type' => 'select', |
||
| 249 | 'options' => give_cmb2_get_post_options( array( |
||
| 250 | 'post_type' => 'page', |
||
| 251 | 'numberposts' => 999, |
||
| 252 | ) ), |
||
| 253 | ), |
||
| 254 | array( |
||
| 255 | 'name' => __( 'Donation History Page', 'give' ), |
||
| 256 | /* translators: %s: [donation_history] */ |
||
| 257 | '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>' ), |
||
| 258 | 'id' => 'history_page', |
||
| 259 | 'type' => 'select', |
||
| 260 | 'options' => give_cmb2_get_post_options( array( |
||
| 261 | 'post_type' => 'page', |
||
| 262 | 'numberposts' => 999, |
||
| 263 | ) ), |
||
| 264 | ), |
||
| 265 | array( |
||
| 266 | 'name' => __( 'Base Country', 'give' ), |
||
| 267 | 'desc' => __( 'The country your site operates from.', 'give' ), |
||
| 268 | 'id' => 'base_country', |
||
| 269 | 'type' => 'select', |
||
| 270 | 'options' => give_get_country_list(), |
||
| 271 | ), |
||
| 272 | /** |
||
| 273 | * Add base state to give setting |
||
| 274 | * |
||
| 275 | * @since 1.8.14 |
||
| 276 | */ |
||
| 277 | array( |
||
| 278 | 'wrapper_class' => ( array_key_exists( $country, $no_states_country ) ? 'give-hidden' : '' ), |
||
| 279 | 'name' => __( 'Base State/Province', 'give' ), |
||
| 280 | 'desc' => __( 'The state/province your site operates from.', 'give' ), |
||
| 281 | 'id' => 'base_state', |
||
| 282 | 'type' => ( empty( $states ) ? 'text' : 'select' ), |
||
| 283 | 'options' => $states, |
||
| 284 | ), |
||
| 285 | array( |
||
| 286 | 'name' => __( 'General Options Docs Link', 'give' ), |
||
| 287 | 'id' => 'general_options_docs_link', |
||
| 288 | 'url' => esc_url( 'http://docs.givewp.com/settings-general' ), |
||
| 289 | 'title' => __( 'General Options', 'give' ), |
||
| 290 | 'type' => 'give_docs_link', |
||
| 291 | ), |
||
| 292 | array( |
||
| 293 | 'type' => 'sectionend', |
||
| 294 | 'id' => 'give_title_general_settings_1', |
||
| 295 | ), |
||
| 296 | ); |
||
| 297 | break; |
||
| 298 | |||
| 299 | case 'sequential-donation': |
||
| 300 | $settings = array( |
||
| 301 | // Section 4: Sequential donation |
||
| 302 | |||
| 303 | array( |
||
| 304 | 'id' => 'give_title_general_settings_4', |
||
| 305 | 'type' => 'title' |
||
| 306 | ), |
||
| 307 | array( |
||
| 308 | 'name' => __( 'Sequential Donation', 'give' ), |
||
| 309 | 'id' => "{$current_section}_status", |
||
| 310 | 'desc' => '', |
||
| 311 | 'type' => 'radio_inline', |
||
| 312 | 'default' => 'disabled', |
||
| 313 | 'options' => array( |
||
| 314 | 'enabled' => __( 'Enabled', 'give' ), |
||
| 315 | 'disabled' => __( 'Disabled', 'give' ) |
||
| 316 | ) |
||
| 317 | ), |
||
| 318 | array( |
||
| 319 | 'name' => __( 'Sequential Starting Number', 'give' ), |
||
| 320 | 'id' => "{$current_section}_number", |
||
| 321 | 'type' => 'text' |
||
| 322 | ), |
||
| 323 | array( |
||
| 324 | 'name' => __( 'Sequential Number Prefix', 'give' ), |
||
| 325 | 'id' => "{$current_section}_number_prefix", |
||
| 326 | 'type' => 'text', |
||
| 327 | 'confirm_before_save' => true |
||
| 328 | ), |
||
| 329 | array( |
||
| 330 | 'name' => __( 'Sequential Number Suffix', 'give' ), |
||
| 331 | 'id' => "{$current_section}_number_suffix", |
||
| 332 | 'type' => 'text' |
||
| 333 | ), |
||
| 334 | array( |
||
| 335 | 'name' => __( 'Number Padding', 'give' ), |
||
| 336 | 'id' => "{$current_section}_number_padding", |
||
| 337 | 'type' => 'text', |
||
| 338 | 'default' => '0', |
||
| 339 | ), |
||
| 340 | array( |
||
| 341 | 'id' => 'give_title_general_settings_4', |
||
| 342 | 'type' => 'sectionend' |
||
| 343 | ) |
||
| 344 | ); |
||
| 345 | } |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Filter the general settings. |
||
| 349 | * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8 |
||
| 350 | */ |
||
| 351 | $settings = apply_filters( 'give_settings_general', $settings ); |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Filter the settings. |
||
| 355 | * |
||
| 356 | * @since 1.8 |
||
| 357 | * |
||
| 358 | * @param array $settings |
||
| 359 | */ |
||
| 360 | $settings = apply_filters( 'give_get_settings_' . $this->id, $settings ); |
||
| 361 | |||
| 362 | // Output. |
||
| 363 | return $settings; |
||
| 364 | } |
||
| 365 | |||
| 387 |