Conditions | 4 |
Paths | 4 |
Total Lines | 436 |
Code Lines | 306 |
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 |
||
87 | function get_settings() { |
||
88 | $post_id = give_get_admin_post_id(); |
||
89 | $price = give_get_form_price( $post_id ); |
||
90 | $custom_amount_minimum = give_get_form_minimum_price( $post_id ); |
||
91 | $goal = give_get_form_goal( $post_id ); |
||
92 | |||
93 | // No empty prices - min. 1.00 for new forms |
||
94 | if ( empty( $price ) && is_null( $post_id ) ) { |
||
95 | $price = esc_attr( give_format_decimal( '1.00' ) ); |
||
96 | } |
||
97 | |||
98 | // Min. $1.00 for new forms |
||
99 | if ( empty( $custom_amount_minimum ) ) { |
||
100 | $custom_amount_minimum = esc_attr( give_format_decimal( '1.00' ) ); |
||
101 | } |
||
102 | |||
103 | // Start with an underscore to hide fields from custom fields list |
||
104 | $prefix = '_give_'; |
||
105 | |||
106 | $settings = array( |
||
107 | /** |
||
108 | * Repeatable Field Groups |
||
109 | */ |
||
110 | 'form_field_options' => apply_filters( 'give_forms_field_options', array( |
||
111 | 'id' => 'form_field_options', |
||
112 | 'title' => esc_html__( 'Donation Options', 'give' ), |
||
113 | 'fields' => apply_filters( 'give_forms_donation_form_metabox_fields', array( |
||
114 | // Donation Option |
||
115 | array( |
||
116 | 'name' => esc_html__( 'Donation Option', 'give' ), |
||
117 | 'description' => esc_html__( 'Do you want this form to have one set donation price or multiple levels (for example, $10, $20, $50)?', 'give' ), |
||
118 | 'id' => $prefix . 'price_option', |
||
119 | 'type' => 'radio_inline', |
||
120 | 'default' => 'set', |
||
121 | 'options' => apply_filters( 'give_forms_price_options', array( |
||
122 | 'set' => esc_html__( 'Set Donation', 'give' ), |
||
123 | 'multi' => esc_html__( 'Multi-level Donation', 'give' ), |
||
124 | ) ), |
||
125 | ), |
||
126 | array( |
||
127 | 'name' => esc_html__( 'Set Donation', 'give' ), |
||
128 | 'description' => esc_html__( 'This is the set donation amount for this form. If you have a "Custom Amount Minimum" set, make sure it is less than this amount.', 'give' ), |
||
129 | 'id' => $prefix . 'set_price', |
||
130 | 'type' => 'text_small', |
||
131 | 'data_type' => 'price', |
||
132 | 'attributes' => array( |
||
133 | 'placeholder' => give_format_decimal( '1.00' ), |
||
134 | 'value' => give_format_decimal( $price ), |
||
135 | 'class' => 'give-money-field', |
||
136 | ), |
||
137 | ), |
||
138 | // Donation Levels: Repeatable CMB2 Group |
||
139 | array( |
||
140 | 'id' => $prefix . 'donation_levels', |
||
141 | 'type' => 'group', |
||
142 | 'options' => array( |
||
143 | 'add_button' => esc_html__( 'Add Level', 'give' ), |
||
144 | 'header_title' => esc_html__( 'Donation Level', 'give' ), |
||
145 | 'remove_button' => '<span class="dashicons dashicons-no"></span>', |
||
146 | ), |
||
147 | // Fields array works the same, except id's only need to be unique for this group. |
||
148 | // Prefix is not needed. |
||
149 | 'fields' => apply_filters( 'give_donation_levels_table_row', array( |
||
150 | array( |
||
151 | 'name' => esc_html__( 'ID', 'give' ), |
||
152 | 'id' => $prefix . 'id', |
||
153 | 'type' => 'levels_id', |
||
154 | ), |
||
155 | array( |
||
156 | 'name' => esc_html__( 'Amount', 'give' ), |
||
157 | 'id' => $prefix . 'amount', |
||
158 | 'type' => 'text_small', |
||
159 | 'data_type' => 'price', |
||
160 | 'attributes' => array( |
||
161 | 'placeholder' => give_format_decimal( '1.00' ), |
||
162 | 'class' => 'give-money-field', |
||
163 | ), |
||
164 | ), |
||
165 | array( |
||
166 | 'name' => esc_html__( 'Text', 'give' ), |
||
167 | 'id' => $prefix . 'text', |
||
168 | 'type' => 'text', |
||
169 | 'attributes' => array( |
||
170 | 'placeholder' => esc_html__( 'Donation Level', 'give' ), |
||
171 | 'class' => 'give-multilevel-text-field', |
||
172 | ), |
||
173 | ), |
||
174 | array( |
||
175 | 'name' => esc_html__( 'Default', 'give' ), |
||
176 | 'id' => $prefix . 'default', |
||
177 | 'type' => 'give_default_radio_inline', |
||
178 | ), |
||
179 | ) ), |
||
180 | ), |
||
181 | // Display Style |
||
182 | array( |
||
183 | 'name' => esc_html__( 'Display Style', 'give' ), |
||
184 | 'description' => esc_html__( 'Set how the donations levels will display on the form.', 'give' ), |
||
185 | 'id' => $prefix . 'display_style', |
||
186 | 'type' => 'radio_inline', |
||
187 | 'default' => 'buttons', |
||
188 | 'options' => array( |
||
189 | 'buttons' => esc_html__( 'Buttons', 'give' ), |
||
190 | 'radios' => esc_html__( 'Radios', 'give' ), |
||
191 | 'dropdown' => esc_html__( 'Dropdown', 'give' ), |
||
192 | ), |
||
193 | ), |
||
194 | // Custom Amount |
||
195 | array( |
||
196 | 'name' => esc_html__( 'Custom Amount', 'give' ), |
||
197 | 'description' => esc_html__( 'Do you want the user to be able to input their own donation amount?', 'give' ), |
||
198 | 'id' => $prefix . 'custom_amount', |
||
199 | 'type' => 'radio_inline', |
||
200 | 'default' => 'disabled', |
||
201 | 'options' => array( |
||
202 | 'enabled' => esc_html__( 'Enabled', 'give' ), |
||
203 | 'disabled' => esc_html__( 'Disabled', 'give' ), |
||
204 | ), |
||
205 | ), |
||
206 | array( |
||
207 | 'name' => esc_html__( 'Minimum Amount', 'give' ), |
||
208 | 'description' => esc_html__( 'Enter the minimum custom donation amount.', 'give' ), |
||
209 | 'id' => $prefix . 'custom_amount_minimum', |
||
210 | 'type' => 'text_small', |
||
211 | 'data_type' => 'price', |
||
212 | 'attributes' => array( |
||
213 | 'placeholder' => give_format_decimal( '1.00' ), |
||
214 | 'value' => give_format_decimal( $custom_amount_minimum ), |
||
215 | 'class' => 'give-money-field', |
||
216 | ), |
||
217 | ), |
||
218 | array( |
||
219 | 'name' => esc_html__( 'Custom Amount Text', 'give' ), |
||
220 | 'description' => esc_html__( 'This text appears as a label below the custom amount field for set donation forms. For multi-level forms the text will appear as it\'s own level (ie button, radio, or select option).', 'give' ), |
||
221 | 'id' => $prefix . 'custom_amount_text', |
||
222 | 'type' => 'text', |
||
223 | 'attributes' => array( |
||
224 | 'rows' => 3, |
||
225 | 'placeholder' => esc_attr__( 'Give a Custom Amount', 'give' ), |
||
226 | ), |
||
227 | ), |
||
228 | array( |
||
229 | 'name' => 'donation_options_docs', |
||
230 | 'type' => 'docs_link', |
||
231 | 'url' => 'http://docs.givewp.com/donationoptions', |
||
232 | 'title' => esc_html__( 'Donation Options', 'give' ), |
||
233 | ), |
||
234 | ), |
||
235 | $post_id |
||
236 | ), |
||
237 | ) ), |
||
238 | |||
239 | /** |
||
240 | * Display Options |
||
241 | */ |
||
242 | 'form_display_options' => apply_filters( 'give_form_display_options', array( |
||
243 | 'id' => 'form_display_options', |
||
244 | 'title' => esc_html__( 'Form Display', 'give' ), |
||
245 | 'fields' => apply_filters( 'give_forms_display_options_metabox_fields', array( |
||
246 | array( |
||
247 | 'name' => esc_html__( 'Display Options', 'give' ), |
||
248 | 'desc' => sprintf( __( 'How would you like to display donation information for this form?', 'give' ), '#' ), |
||
249 | 'id' => $prefix . 'payment_display', |
||
250 | 'type' => 'radio_inline', |
||
251 | 'options' => array( |
||
252 | 'onpage' => esc_html__( 'All Fields', 'give' ), |
||
253 | 'modal' => esc_html__( 'Modal', 'give' ), |
||
254 | 'reveal' => esc_html__( 'Reveal', 'give' ), |
||
255 | 'button' => esc_html__( 'Button', 'give' ), |
||
256 | ), |
||
257 | 'default' => 'onpage', |
||
258 | ), |
||
259 | array( |
||
260 | 'id' => $prefix . 'reveal_label', |
||
261 | 'name' => esc_html__( 'Continue Button', 'give' ), |
||
262 | 'desc' => esc_html__( 'The button label for displaying the additional payment fields.', 'give' ), |
||
263 | 'type' => 'text_small', |
||
264 | 'attributes' => array( |
||
265 | 'placeholder' => esc_attr__( 'Donate Now', 'give' ), |
||
266 | ), |
||
267 | ), |
||
268 | array( |
||
269 | 'id' => $prefix . 'checkout_label', |
||
270 | 'name' => esc_html__( 'Submit Button', 'give' ), |
||
271 | 'desc' => esc_html__( 'The button label for completing a donation.', 'give' ), |
||
272 | 'type' => 'text_small', |
||
273 | 'attributes' => array( |
||
274 | 'placeholder' => esc_html__( 'Donate Now', 'give' ), |
||
275 | ), |
||
276 | ), |
||
277 | array( |
||
278 | 'name' => esc_html__( 'Default Gateway', 'give' ), |
||
279 | 'desc' => esc_html__( 'By default, the gateway for this form will inherit the global default gateway (set under Give > Settings > Payment Gateways). This option allows you to customize the default gateway for this form only.', 'give' ), |
||
280 | 'id' => $prefix . 'default_gateway', |
||
281 | 'type' => 'default_gateway', |
||
282 | ), |
||
283 | array( |
||
284 | 'name' => esc_html__( 'Guest Donations', 'give' ), |
||
285 | 'desc' => esc_html__( 'Do you want to enable non-logged-in users to make donations?', 'give' ), |
||
286 | 'id' => $prefix . 'logged_in_only', |
||
287 | 'type' => 'radio_inline', |
||
288 | 'default' => 'enabled', |
||
289 | 'options' => array( |
||
290 | 'enabled' => esc_html__( 'Enabled', 'give' ), |
||
291 | 'disabled' => esc_html__( 'Disabled', 'give' ), |
||
292 | ), |
||
293 | ), |
||
294 | array( |
||
295 | 'name' => esc_html__( 'Registration', 'give' ), |
||
296 | 'desc' => esc_html__( 'Display the registration and login forms in the payment section for non-logged-in users.', 'give' ), |
||
297 | 'id' => $prefix . 'show_register_form', |
||
298 | 'type' => 'radio', |
||
299 | 'options' => array( |
||
300 | 'none' => esc_html__( 'None', 'give' ), |
||
301 | 'registration' => esc_html__( 'Registration', 'give' ), |
||
302 | 'login' => esc_html__( 'Login', 'give' ), |
||
303 | 'both' => esc_html__( 'Registration + Login', 'give' ), |
||
304 | ), |
||
305 | 'default' => 'none', |
||
306 | ), |
||
307 | array( |
||
308 | 'name' => esc_html__( 'Floating Labels', 'give' ), |
||
309 | /* translators: %s: forms https://givewp.com/documentation/core/give-forms/creating-give-forms/#floating-labels */ |
||
310 | 'desc' => sprintf( __( 'Select the <a href="%s" target="_blank">floating labels</a> setting for this Give form. Be aware that if you have the "Disable CSS" option enabled, you will need to style the floating labels yourself.', 'give' ), esc_url( 'https://givewp.com/documentation/core/give-forms/creating-give-forms/#floating-labels' ) ), |
||
311 | 'id' => $prefix . 'form_floating_labels', |
||
312 | 'type' => 'radio_inline', |
||
313 | 'options' => array( |
||
314 | 'global' => esc_html__( 'Global Options', 'give' ), |
||
315 | 'enabled' => esc_html__( 'Enabled', 'give' ), |
||
316 | 'disabled' => esc_html__( 'Disabled', 'give' ), |
||
317 | ), |
||
318 | 'default' => 'global', |
||
319 | ), |
||
320 | array( |
||
321 | 'name' => 'form_display_docs', |
||
322 | 'type' => 'docs_link', |
||
323 | 'url' => 'http://docs.givewp.com/formdisplay', |
||
324 | 'title' => esc_html__( 'Form Display', 'give' ), |
||
325 | ), |
||
326 | ), |
||
327 | $post_id |
||
328 | ), |
||
329 | ) |
||
330 | ), |
||
331 | |||
332 | /** |
||
333 | * Donation Goals |
||
334 | */ |
||
335 | 'donation_goal_options' => apply_filters( 'give_donation_goal_options', array( |
||
336 | 'id' => 'donation_goal_options', |
||
337 | 'title' => esc_html__( 'Donation Goal', 'give' ), |
||
338 | 'fields' => apply_filters( 'give_forms_donation_goal_metabox_fields', array( |
||
339 | // Goals |
||
340 | array( |
||
341 | 'name' => esc_html__( 'Donation Goal', 'give' ), |
||
342 | 'description' => esc_html__( 'Do you want to set a donation goal for this form?', 'give' ), |
||
343 | 'id' => $prefix . 'goal_option', |
||
344 | 'type' => 'radio_inline', |
||
345 | 'default' => 'disabled', |
||
346 | 'options' => array( |
||
347 | 'enabled' => esc_html__( 'Enabled', 'give' ), |
||
348 | 'disabled' => esc_html__( 'Disabled', 'give' ), |
||
349 | ), |
||
350 | ), |
||
351 | array( |
||
352 | 'name' => esc_html__( 'Goal Amount', 'give' ), |
||
353 | 'description' => esc_html__( 'This is the monetary goal amount you want to reach for this form.', 'give' ), |
||
354 | 'id' => $prefix . 'set_goal', |
||
355 | 'type' => 'text_small', |
||
356 | 'data_type' => 'price', |
||
357 | 'attributes' => array( |
||
358 | 'placeholder' => give_format_decimal( '0.00' ), |
||
359 | 'value' => give_format_decimal( $goal ), |
||
360 | 'class' => 'give-money-field', |
||
361 | ), |
||
362 | ), |
||
363 | |||
364 | array( |
||
365 | 'name' => esc_html__( 'Goal Format', 'give' ), |
||
366 | 'description' => esc_html__( 'Do you want to display the total amount raised based on your monetary goal or a percentage? For instance, "$500 of $1,000 raised" or "50% funded".', 'give' ), |
||
367 | 'id' => $prefix . 'goal_format', |
||
368 | 'type' => 'radio_inline', |
||
369 | 'default' => 'amount', |
||
370 | 'options' => array( |
||
371 | 'amount' => esc_html__( 'Amount', 'give' ), |
||
372 | 'percentage' => esc_html__( 'Percentage', 'give' ), |
||
373 | ), |
||
374 | ), |
||
375 | array( |
||
376 | 'name' => esc_html__( 'Progress Bar Color', 'give' ), |
||
377 | 'desc' => esc_html__( 'Customize the color of the goal progress bar.', 'give' ), |
||
378 | 'id' => $prefix . 'goal_color', |
||
379 | 'type' => 'colorpicker', |
||
380 | 'default' => '#2bc253', |
||
381 | ), |
||
382 | |||
383 | array( |
||
384 | 'name' => esc_html__( 'Close Form', 'give' ), |
||
385 | 'desc' => esc_html__( 'Do you want to close the donation forms and stop accepting donations once this goal has been met?', 'give' ), |
||
386 | 'id' => $prefix . 'close_form_when_goal_achieved', |
||
387 | 'type' => 'radio_inline', |
||
388 | 'default' => 'disabled', |
||
389 | 'options' => array( |
||
390 | 'enabled' => esc_html__( 'Enabled', 'give' ), |
||
391 | 'disabled' => esc_html__( 'Disabled', 'give' ), |
||
392 | ), |
||
393 | ), |
||
394 | array( |
||
395 | 'name' => esc_html__( 'Goal Achieved Message', 'give' ), |
||
396 | 'desc' => esc_html__( 'Do you want to display a custom message when the goal is closed? If none is provided the default message will be displayed', 'give' ), |
||
397 | 'id' => $prefix . 'form_goal_achieved_message', |
||
398 | 'type' => 'textarea', |
||
399 | 'attributes' => array( |
||
400 | 'placeholder' => esc_attr__( 'Thank you to all our donors, we have met our fundraising goal.', 'give' ), |
||
401 | ), |
||
402 | ), |
||
403 | array( |
||
404 | 'name' => 'donation_goal_docs', |
||
405 | 'type' => 'docs_link', |
||
406 | 'url' => 'http://docs.givewp.com/donationgoal', |
||
407 | 'title' => esc_html__( 'Donation Goal', 'give' ), |
||
408 | ), |
||
409 | ), |
||
410 | $post_id |
||
411 | ), |
||
412 | ) ), |
||
413 | |||
414 | /** |
||
415 | * Content Field |
||
416 | */ |
||
417 | 'form_content_options' => apply_filters( 'give_forms_content_options', array( |
||
418 | 'id' => 'form_content_options', |
||
419 | 'title' => esc_html__( 'Form Content', 'give' ), |
||
420 | 'fields' => apply_filters( 'give_forms_content_options_metabox_fields', array( |
||
421 | |||
422 | // Donation content. |
||
423 | array( |
||
424 | 'name' => esc_html__( 'Display Content', 'give' ), |
||
425 | 'description' => esc_html__( 'Do you want to add custom content to this form?', 'give' ), |
||
426 | 'id' => $prefix . 'display_content', |
||
427 | 'type' => 'radio_inline', |
||
428 | 'options' => array( |
||
429 | 'enabled' => esc_html__( 'Enabled', 'give' ), |
||
430 | 'disabled' => esc_html__( 'Disabled', 'give' ), |
||
431 | ), |
||
432 | 'default' => 'disabled', |
||
433 | ), |
||
434 | |||
435 | // Content placement. |
||
436 | array( |
||
437 | 'name' => esc_html__( 'Content Placement', 'give' ), |
||
438 | 'description' => esc_html__( 'This option controls where the content appears within the donation form.', 'give' ), |
||
439 | 'id' => $prefix . 'content_placement', |
||
440 | 'type' => 'radio_inline', |
||
441 | 'options' => apply_filters( 'give_forms_content_options_select', array( |
||
442 | 'give_pre_form' => esc_html__( 'Above fields', 'give' ), |
||
443 | 'give_post_form' => esc_html__( 'Below fields', 'give' ), |
||
444 | ) |
||
445 | ), |
||
446 | 'default' => 'give_pre_form', |
||
447 | ), |
||
448 | array( |
||
449 | 'name' => esc_html__( 'Content', 'give' ), |
||
450 | 'description' => esc_html__( 'This content will display on the single give form page.', 'give' ), |
||
451 | 'id' => $prefix . 'form_content', |
||
452 | 'type' => 'wysiwyg', |
||
453 | ), |
||
454 | array( |
||
455 | 'name' => 'form_content_docs', |
||
456 | 'type' => 'docs_link', |
||
457 | 'url' => 'http://docs.givewp.com/formcontent', |
||
458 | 'title' => esc_html__( 'Form Content', 'give' ), |
||
459 | ), |
||
460 | ), |
||
461 | $post_id |
||
462 | ), |
||
463 | ) ), |
||
464 | |||
465 | /** |
||
466 | * Terms & Conditions |
||
467 | */ |
||
468 | 'form_terms_options' => apply_filters( 'give_forms_terms_options', array( |
||
469 | 'id' => 'form_terms_options', |
||
470 | 'title' => esc_html__( 'Terms & Conditions', 'give' ), |
||
471 | 'fields' => apply_filters( 'give_forms_terms_options_metabox_fields', array( |
||
472 | // Donation Option |
||
473 | array( |
||
474 | 'name' => esc_html__( 'Terms & Conditions', 'give' ), |
||
475 | 'description' => esc_html__( 'Do you want to require the donor to accept terms prior to being able to complete their donation?', 'give' ), |
||
476 | 'id' => $prefix . 'terms_option', |
||
477 | 'type' => 'radio_inline', |
||
478 | 'options' => apply_filters( 'give_forms_content_options_select', array( |
||
479 | 'global' => esc_html__( 'Global Options', 'give' ), |
||
480 | 'enabled' => esc_html__( 'Customize', 'give' ), |
||
481 | 'disabled' => esc_html__( 'Disable', 'give' ), |
||
482 | ) |
||
483 | ), |
||
484 | 'default' => 'global', |
||
485 | ), |
||
486 | array( |
||
487 | 'id' => $prefix . 'agree_label', |
||
488 | 'name' => esc_html__( 'Agreement Label', 'give' ), |
||
489 | 'desc' => esc_html__( 'The label shown next to the agree to terms check box. Add your own to customize or leave blank to use the default text placeholder.', 'give' ), |
||
490 | 'type' => 'text', |
||
491 | 'size' => 'regular', |
||
492 | 'attributes' => array( |
||
493 | 'placeholder' => esc_attr__( 'Agree to Terms?', 'give' ), |
||
494 | ), |
||
495 | ), |
||
496 | array( |
||
497 | 'id' => $prefix . 'agree_text', |
||
498 | 'name' => esc_html__( 'Agreement Text', 'give' ), |
||
499 | 'desc' => esc_html__( 'This is the actual text which the user will have to agree to in order to make a donation.', 'give' ), |
||
500 | 'type' => 'wysiwyg', |
||
501 | ), |
||
502 | array( |
||
503 | 'name' => 'terms_docs', |
||
504 | 'type' => 'docs_link', |
||
505 | 'url' => 'http://docs.givewp.com/form-terms', |
||
506 | 'title' => esc_html__( 'Terms & Conditions', 'give' ), |
||
507 | ), |
||
508 | ), |
||
509 | $post_id |
||
510 | ), |
||
511 | ) ), |
||
512 | ); |
||
513 | |||
514 | |||
515 | /** |
||
516 | * Filter the metabox tabbed panel settings. |
||
517 | */ |
||
518 | $settings = apply_filters( 'give_metabox_form_data_settings', $settings, $post_id ); |
||
519 | |||
520 | // Output. |
||
521 | return $settings; |
||
522 | } |
||
523 | |||
1063 |
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.