PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.10.0
GiveWP – Donation Plugin and Fundraising Platform v3.10.0
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / src / FormMigration / FormMetaDecorator.php
give / src / FormMigration Last commit date
Actions 2 years ago Commands 2 years ago Concerns 2 years ago Contracts 2 years ago Controllers 2 years ago DataTransferObjects 2 years ago Steps 2 years ago FormMetaDecorator.php 2 years ago Pipeline.php 2 years ago ServiceProvider.php 2 years ago StepProcessor.php 2 years ago functions.php 2 years ago
FormMetaDecorator.php
911 lines
1 <?php
2
3 namespace Give\FormMigration;
4
5 use Give\DonationForms\V2\Models\DonationForm;
6 use Give\DonationForms\ValueObjects\GoalType;
7 use Give\FormMigration\Contracts\FormModelDecorator;
8 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\StripePaymentElementGateway;
9 use Give_Email_Notification_Util;
10
11 class FormMetaDecorator extends FormModelDecorator
12 {
13 /**
14 * @var DonationForm
15 */
16 protected $form;
17
18 public function __construct(DonationForm $form)
19 {
20 $this->form = $form;
21 }
22
23 public function isLastNameRequired(): bool
24 {
25 return give_is_last_name_required($this->form->id);
26 }
27
28 public function isNameTitlePrefixEnabled(): bool
29 {
30 return give_is_name_title_prefix_enabled($this->form->id);
31 }
32
33 public function getNameTitlePrefixes(): array
34 {
35 return give_get_name_title_prefixes($this->form->id);
36 }
37
38 public function isUserRegistrationEnabled(): bool
39 {
40 // @note In v3 all donors are registered as users, so no need for a registration setting.
41 return in_array(
42 give_get_meta($this->form->id, '_give_show_register_form', true),
43 ['registration', 'login', 'both']
44 );
45 }
46
47 public function isUserLoginRequired(): bool
48 {
49 return !$this->isGuestDonationsEnabled();
50 }
51
52 public function isGuestDonationsEnabled(): bool
53 {
54 // @note The "Guest Donation" setting corresponds to the `_give_logged_in_only` meta, which seems backwards.
55 return give_is_setting_enabled(
56 give_get_meta($this->form->id, '_give_logged_in_only', true)
57 );
58 }
59
60 public function isCompanyFieldEnabled(): bool
61 {
62 return give_is_company_field_enabled($this->form->id);
63 }
64
65 public function isCompanyFieldRequired(): bool
66 {
67 // @note Forked from give/includes/process-donation.php:718
68 if (give_is_company_field_enabled($this->form->id)) {
69 $form_option = give_get_meta($this->form->id, '_give_company_field', true);
70 $global_setting = give_get_option('company_field');
71
72 if (!empty($form_option) && give_is_setting_enabled($form_option, ['required'])) {
73 return true;
74 } elseif ('global' === $form_option && give_is_setting_enabled($global_setting, ['required'])) {
75 return true;
76 } elseif (empty($form_option) && give_is_setting_enabled($global_setting, ['required'])) {
77 return true;
78 }
79 }
80
81 return false;
82 }
83
84 public function getFormTemplate(): string
85 {
86 return give_get_meta($this->form->id, '_give_form_template', true);
87 }
88
89 public function getFormTemplateSettings(): array
90 {
91 $template = $this->getFormTemplate();
92
93 $templateSettings = give_get_meta($this->form->id, "_give_{$template}_form_template_settings", true);
94
95 return is_array($templateSettings) ? $templateSettings : [];
96 }
97
98 public function isDonationGoalEnabled(): bool
99 {
100 return give_is_setting_enabled(
101 give_get_meta($this->form->id, '_give_goal_option', true)
102 );
103 }
104
105 public function getDonationGoalType(): GoalType
106 {
107 $onlyRecurringEnabled = $this->isGoalCountingOnlyRecurringDonations();
108
109 switch (give_get_form_goal_format($this->form->id)) {
110 case 'donors':
111 return $onlyRecurringEnabled ? GoalType::DONORS_FROM_SUBSCRIPTIONS() : GoalType::DONORS();
112 case 'donation': // @note v2: Singular
113 return $onlyRecurringEnabled ? GoalType::SUBSCRIPTIONS() : GoalType::DONATIONS();
114 // @note v3: Plural
115 case 'amount':
116 case 'percentage': // @note `percentage` is not supported in v3 - defaulting to `amount`
117 default:
118 return $onlyRecurringEnabled ? GoalType::AMOUNT_FROM_SUBSCRIPTIONS() : GoalType::AMOUNT();
119 }
120 }
121
122 /**
123 * @return mixed Goal of the form
124 */
125 public function getDonationGoalAmount()
126 {
127 return give_get_form_goal($this->form->id);
128 }
129
130 public function isAutoClosedEnabled()
131 {
132 return give_is_setting_enabled(
133 give_get_meta($this->form->id, '_give_close_form_when_goal_achieved', true, 'disabled')
134 );
135 }
136
137 public function getGoalAchievedMessage()
138 {
139 return give_get_meta($this->form->id, '_give_form_goal_achieved_message', true);
140 }
141
142 public function isTermsEnabled()
143 {
144 return give_is_terms_enabled($this->form->id);
145 }
146
147 public function getTermsAgreementLabel()
148 {
149 // @note Forked from give/includes/forms/template.php:1845
150 return ($label = give_get_meta($this->form->id, '_give_agree_label', true))
151 ? stripslashes($label)
152 : esc_html__('Agree to Terms?', 'give');
153 }
154
155 public function getTermsAgreementText()
156 {
157 return give_get_meta($this->form->id, '_give_agree_text', true);
158 }
159
160 public function isOfflineDonationsCustomized()
161 {
162 return give_is_setting_enabled(
163 give_get_meta($this->form->id, '_give_customize_offline_donations', true),
164 'custom'
165 );
166 }
167
168 public function isOfflineDonationsBillingFieldEnabled()
169 {
170 return give_is_setting_enabled(
171 give_get_meta($this->form->id, '_give_offline_donation_enable_billing_fields_single', true)
172 );
173 }
174
175 public function getOfflineDonationInstructions()
176 {
177 return give_get_meta($this->form->id, '_give_offline_checkout_notes', true);
178 }
179
180 public function isFormGridCustomized()
181 {
182 return give_is_setting_enabled(
183 give_get_meta($this->form->id, '_give_form_grid_option', true),
184 'custom'
185 );
186 }
187
188 public function getFormGridRedirectUrl()
189 {
190 return give_get_meta($this->form->id, '_give_form_grid_redirect_url', true);
191 }
192
193 public function getFormGridDonateButtonText()
194 {
195 return give_get_meta($this->form->id, '_give_form_grid_donate_button_text', true);
196 }
197
198 public function getEmailOptionsStatus(): string
199 {
200 return give_get_meta($this->form->id, '_give_email_options', true);
201 }
202
203 public function getEmailTemplate(): string
204 {
205 return give_get_meta($this->form->id, '_give_email_template', true);
206 }
207
208 public function getEmailLogo(): string
209 {
210 return Give_Email_Notification_Util::get_email_logo($this->form->id);
211 }
212
213 public function getEmailFromName(): string
214 {
215 return give_get_meta($this->form->id, '_give_from_name', true);
216 }
217
218 public function getEmailFromEmail(): string
219 {
220 return give_get_meta($this->form->id, '_give_from_email', true);
221 }
222
223 /**
224 * @since 3.0.0
225 * @return string 'multi', 'set'
226 */
227 public function getDonationOption(): string
228 {
229 return give()->form_meta->get_meta($this->form->id, '_give_price_option', true);
230 }
231
232 /**
233 * @since 3.0.0
234 * @return string 'multi', 'set'
235 */
236 public function isDonationOptionMulti(): string
237 {
238 return 'multi' === $this->getDonationOption();
239 }
240
241 /**
242 * @return string 'multi', 'set'
243 */
244 public function isDonationOptionSet(): string
245 {
246 return 'set' === $this->getDonationOption();
247 }
248
249 /**
250 * @since 3.0.0
251 */
252 public function getDonationLevels(): array
253 {
254 return give()->form_meta->get_meta($this->form->id, '_give_donation_levels', true);
255 }
256
257 /**
258 * @since 3.0.0
259 */
260 public function isRecurringDonationsEnabled(): bool
261 {
262 $_give_recurring = $this->getRecurringDonationsOption();
263
264 return !empty($_give_recurring) && 'no' !== $_give_recurring;
265 }
266
267 /**
268 * Recurring Donations = 'no', 'yes_donor', 'yes_admin'
269 *
270 * @since 3.0.0
271 */
272 public function getRecurringDonationsOption(): string
273 {
274 return give()->form_meta->get_meta($this->form->id, '_give_recurring', true);
275 }
276
277 /**
278 * @since 3.0.0
279 */
280 public function isRecurringDefaultCheckboxEnabled(): bool
281 {
282 return 'yes' === $this->getRecurringDefaultCheckboxOption();
283 }
284
285 /**
286 * 'day', 'week', 'month', 'year'
287 *
288 * @since 3.0.0
289 */
290 public function getRecurringPeriod(): string
291 {
292 return give()->form_meta->get_meta($this->form->id, '_give_period', true);
293 }
294
295 /**
296 * 'day', 'week', 'month', 'year'
297 *
298 * @since 3.0.0
299 */
300 public function getRecurringPeriodDefaultDonorsChoice(): string
301 {
302 return give()->form_meta->get_meta($this->form->id, '_give_period_default_donor_choice', true);
303 }
304
305 /**
306 * @since 3.0.0
307 */
308 public function getRecurringLengthOfTime(): int
309 {
310 return (int)give()->form_meta->get_meta($this->form->id, '_give_times', true);
311 }
312
313 /**
314 * @since 3.0.0
315 */
316 public function getRecurringBillingInterval(): int
317 {
318 return (int)give()->form_meta->get_meta($this->form->id, '_give_period_interval', true);
319 }
320
321 /**
322 * 'yes', 'no'
323 *
324 * @since 3.0.0
325 */
326 public function getRecurringDefaultCheckboxOption(): string
327 {
328 return give()->form_meta->get_meta($this->form->id, '_give_checkbox_default', true);
329 }
330
331 /**
332 * 'donors_choice', 'admin_choice', 'custom' (The "Donor's Choice" option allows the donor to select the time period (commonly also referred as the "frequency") of their subscription. The "Preset Period" option provides only the selected period for the donor's subscription.)
333 *
334 * @since 3.0.0
335 */
336 public function getRecurringPeriodFunctionality(): string
337 {
338 return give()->form_meta->get_meta($this->form->id, '_give_period_functionality', true);
339 }
340
341 /**
342 * @since 3.0.0
343 * @return string 'enabled', 'disabled'
344 */
345 public function getCustomAmountOption(): string
346 {
347 return give()->form_meta->get_meta($this->form->id, '_give_custom_amount', true);
348 }
349
350 /**
351 * @since 3.0.0
352 */
353 public function isCustomAmountOptionEnabled(): bool
354 {
355 return 'enabled' === $this->getCustomAmountOption();
356 }
357
358 /**
359 * @since 3.0.0
360 */
361 public function isRecurringPeriodFunctionalityDonorsChoice(): bool
362 {
363 return 'donors_choice' === $this->getRecurringPeriodFunctionality();
364 }
365
366 /**
367 * @since 3.0.0
368 */
369 public function isRecurringPeriodFunctionalityAdminChoice(): bool
370 {
371 return 'admin_choice' === $this->getRecurringPeriodFunctionality();
372 }
373
374 /**
375 * This used when donation option is 'multi' and custom amount is 'enabled'
376 *
377 * @since 3.0.0
378 */
379 public function getRecurringCustomAmountPeriod(): string
380 {
381 return give()->form_meta->get_meta($this->form->id, '_give_recurring_custom_amount_period', true);
382 }
383
384 /**
385 * This used when donation option is 'multi' and custom amount is 'enabled'
386 *
387 * @since 3.0.0
388 */
389 public function getRecurringCustomAmountInterval(): int
390 {
391 return give()->form_meta->get_meta($this->form->id, '_give_recurring_custom_amount_interval', true);
392 }
393
394 /**
395 * This used when donation option is 'multi' and custom amount is 'enabled'
396 *
397 * @since 3.0.0
398 */
399 public function getRecurringCustomAmountTimes(): int
400 {
401 return give()->form_meta->get_meta($this->form->id, '_give_recurring_custom_amount_times', true);
402 }
403
404 public function getStripeUseGlobalDefault(): bool
405 {
406 return (
407 give_get_meta($this->form->id, 'give_stripe_per_form_accounts', true) !== 'enabled'
408 );
409 }
410
411 public function getStripeAccountId(): string
412 {
413 return give_get_meta($this->form->id, '_give_stripe_default_account', true);
414 }
415
416 public function isGoalCountingOnlyRecurringDonations(): bool
417 {
418 return filter_var(give_get_meta($this->form->id, '_give_recurring_goal_format', true), FILTER_VALIDATE_BOOLEAN);
419 }
420
421 /**
422 * @return array{offlineEnabled: bool, offlineUseGlobalInstructions: bool, offlineDonationInstructions: string}
423 */
424 public function getOfflineAttributes(): array
425 {
426 $customization = give_get_meta($this->form->id, '_give_customize_offline_donations', true);
427 $instructions = give_get_meta($this->form->id, '_give_offline_checkout_notes', true);
428
429 return [
430 'offlineEnabled' => $customization !== 'disabled',
431 'offlineUseGlobalInstructions' => $customization === 'global',
432 'offlineDonationInstructions' => $instructions,
433 ];
434 }
435
436 /**
437 * @since 3.0.0
438 */
439 public function getFormFields(): array
440 {
441 return array_filter((array)give_get_meta($this->form->id, 'give-form-fields', true));
442 }
443
444 /**
445 * @since 3.0.0
446 */
447 public function getFormFieldsPlacement(): string
448 {
449 return give_get_meta($this->form->id, '_give_ffm_placement', true);
450 }
451
452 /**
453 * @since 3.0.2 set correct $gatewayId to be used in getMeta calls
454 * @since 3.0.0
455 */
456 public function getFeeRecoverySettings(): array
457 {
458 $feeRecoveryStatus = $this->getMeta('_form_give_fee_recovery');
459
460 if (empty($feeRecoveryStatus) || $feeRecoveryStatus === 'disabled') {
461 return [];
462 }
463
464 if ($feeRecoveryStatus === 'global') {
465 return [
466 'useGlobalSettings' => true,
467 ];
468 }
469
470 if ($feeRecoveryStatus !== 'enabled') {
471 return [];
472 }
473
474 $perGatewaySettings = [];
475 $gateways = give_get_ordered_payment_gateways(give_get_enabled_payment_gateways());
476 $gatewaysMap = [
477 'stripe' => StripePaymentElementGateway::id(),
478 ];
479
480 if ($gateways) {
481 foreach (array_keys($gateways) as $gatewayId) {
482 $v3GatewayId = $gatewayId;
483 if (array_key_exists($gatewayId, $gatewaysMap)) {
484 $v3GatewayId = $gatewaysMap[$gatewayId];
485 }
486
487 $perGatewaySettings[$v3GatewayId] = [
488 'enabled' => $this->getMeta('_form_gateway_fee_enable_' . $gatewayId) === 'enabled',
489 'feePercentage' => (float)$this->getMeta('_form_gateway_fee_percentage_' . $gatewayId, 2.9),
490 'feeBaseAmount' => (float)$this->getMeta('_form_gateway_fee_base_amount_' . $gatewayId, 0.30),
491 'maxFeeAmount' => (float)$this->getMeta(
492 '_form_gateway_fee_maximum_fee_amount_' . $gatewayId,
493 give_format_decimal(['amount' => '0.00'])
494 ),
495 ];
496 }
497 }
498
499 return [
500 'useGlobalSettings' => false,
501 'feeSupportForAllGateways' => $this->getMeta('_form_give_fee_configuration') === 'all_gateways',
502 'perGatewaySettings' => $perGatewaySettings,
503 'feePercentage' => (float)$this->getMeta('_form_give_fee_percentage'),
504 'feeBaseAmount' => (float)$this->getMeta('_form_give_fee_base_amount'),
505 'maxFeeAmount' => (float)$this->getMeta('_form_give_fee_maximum_fee_amount'),
506 'includeInDonationSummary' => $this->getMeta('_form_breakdown') === 'enabled',
507 'donorOptIn' => $this->getMeta('_form_give_fee_mode') === 'donor_opt_in',
508 'feeCheckboxLabel' => $this->getMeta('_form_give_fee_checkbox_label'),
509 'feeMessage' => $this->getMeta('_form_give_fee_explanation'),
510 ];
511 }
512
513 /**
514 * @since 3.7.0
515 */
516 public function isConstantContactEnabled(): bool
517 {
518 $isFormEnabled = give_is_setting_enabled($this->getMeta('_give_constant_contact_enable'),'true');
519
520 $isFormDisabled = give_is_setting_enabled($this->getMeta('_give_constant_contact_disable'),'true');
521
522 $isGloballyEnabled = give_is_setting_enabled(give_get_option('give_constant_contact_show_checkout_signup'), 'on');
523
524 return !($isFormDisabled || ( !$isGloballyEnabled && !$isFormEnabled));
525 }
526
527 /**
528 * @since 3.7.0
529 */
530 public function getConstantContactLabel(): string
531 {
532 $defaultMeta = give_get_option('give_constant_contact_label', __('Subscribe to our newsletter?'));
533
534 return $this->getMeta('_give_constant_contact_custom_label', $defaultMeta);
535 }
536
537 /**
538 * @since 3.7.0
539 */
540 public function getConstantContactDefaultChecked(): bool
541 {
542 $defaultMeta = give_is_setting_enabled(
543 give_get_option('give_constant_contact_checked_default',
544 true),
545 'on'
546 );
547
548 return $this->getMeta('_give_constant_contact_checked_default', $defaultMeta);
549 }
550
551 /**
552 * @since 3.7.0
553 */
554 public function getConstantContactSelectedLists(): array
555 {
556 $defaultMeta = give_get_option('give_constant_contact_list', []);
557
558 return (array)$this->getMeta('_give_constant_contact', $defaultMeta);
559 }
560
561 /**
562 * @since 3.3.0
563 */
564 public function isMailchimpEnabled(): bool
565 {
566 $isFormEnabled = give_is_setting_enabled($this->getMeta('_give_mailchimp_enable'), 'true');
567
568 $isFormDisabled = give_is_setting_enabled($this->getMeta('_give_mailchimp_disable'), 'true');
569
570 $isGloballyEnabled = give_is_setting_enabled(give_get_option('give_mailchimp_show_checkout_signup'), 'on');
571
572 return !($isFormDisabled || (!$isGloballyEnabled && !$isFormEnabled));
573 }
574
575 /**
576 * @since 3.3.0
577 */
578 public function getMailchimpLabel(): string
579 {
580 return $this->getMeta('_give_mailchimp_custom_label', give_get_option('give_mailchimp_label', __('Subscribe to newsletter?')));
581 }
582
583 /**
584 * @since 3.7.0 add global setting as default.
585 * @since 3.3.0
586 */
587 public function getMailchimpDefaultChecked(): bool
588 {
589 return give_is_setting_enabled($this->getMeta('_give_mailchimp_checked_default',
590 give_get_option('give_mailchimp_checked_default', true)));
591 }
592
593 /**
594 * @since 3.7.0 add global setting as default.
595 * @since 3.3.0
596 */
597 public function getMailchimpSendDonationData(): bool
598 {
599 return give_is_setting_enabled($this->getMeta('_give_mailchimp_send_donation_data',
600 give_get_option('give_mailchimp_donation_data', true)));
601 }
602
603 /**
604 * @since 3.7.0 add global setting as default.
605 * @since 3.3.0
606 */
607 public function getMailchimpSendFFMData(): bool
608 {
609 return give_is_setting_enabled($this->getMeta('_give_mailchimp_send_ffm',
610 give_get_option('give_mailchimp_ffm_pass_field')));
611 }
612
613 /**
614 * @since 3.3.0
615 */
616 public function getMailchimpDefaultAudiences(): array
617 {
618 return (array)$this->getMeta('_give_mailchimp', give_get_option('give_mailchimp_list', ['']));
619 }
620
621 /**
622 * @since 3.3.0
623 */
624 public function getMailchimpSubscriberTags():? array
625 {
626 return (array)$this->getMeta('_give_mailchimp_tags', null);
627 }
628
629
630 /**
631 * Retrieves metadata for the current form.
632 *
633 * This method acts as a wrapper for the give_get_meta function, reducing redundancy
634 * and improving code readability when fetching metadata related to the current form.
635 *
636 * @since 3.0.0
637 *
638 * @param string $key
639 * @param mixed $default
640 * @return mixed
641 */
642 private function getMeta(string $key, $default = null)
643 {
644 return give_get_meta($this->form->id, $key, true, $default);
645 }
646
647 /**
648 * @since 3.3.1 changed how is checked if the form has funds
649 * @since 3.3.0
650 */
651 public function hasFunds(): bool
652 {
653 $fundsAndDesignationsAttributes = $this->getFundsAndDesignationsAttributes();
654
655 return !empty($fundsAndDesignationsAttributes['fund']);
656 }
657
658 /**
659 * @since 3.3.1 changed how is checked if the form has fund options
660 * @since 3.3.0
661 */
662 public function hasFundOptions(): bool
663 {
664 $fundsAndDesignationsAttributes = $this->getFundsAndDesignationsAttributes();
665
666 return !empty($fundsAndDesignationsAttributes['options']);
667 }
668
669 /**
670 * @since 3.4.0 added additional checks to ensure that the form has funds and fund options
671 * @since 3.3.0
672 */
673 public function getFundsAndDesignationsAttributes(): array
674 {
675 $label = give_get_meta($this->form->id, 'give_funds_label', true);
676 $isAdminChoice = 'admin_choice' === give_get_meta($this->form->id, 'give_funds_form_choice', true);
677 $adminChoice = give_get_meta($this->form->id, 'give_funds_admin_choice', true);
678 $donorOptions = give_get_meta($this->form->id, 'give_funds_donor_choice', true);
679
680
681 $options = [];
682 if (!empty($donorOptions)) {
683 foreach ($donorOptions as $fundId) {
684 $options[] = [
685 'value' => $fundId,
686 'label' => $this->getFundLabel($fundId),
687 'checked' => $isAdminChoice ? $fundId === $adminChoice : true,
688 'isDefault' => $this->isDefaultFund($fundId),
689 ];
690 }
691 }
692
693 $fund = [];
694 if ($isAdminChoice) {
695 $fund = [
696 'value' => $adminChoice,
697 'label' => $this->getFundLabel($adminChoice),
698 'checked' => true,
699 'isDefault' => $this->isDefaultFund($adminChoice),
700 ];
701 } elseif (!empty($options)) {
702 $fund = $options[0];
703 }
704
705 return [
706 'label' => $label,
707 'fund' => $fund,
708 'options' => $options,
709 ];
710 }
711
712 /**
713 * @since 3.3.0
714 */
715 private function getFundLabel(int $fundId): string
716 {
717 global $wpdb;
718
719 $fund = $wpdb->get_row(
720 $wpdb->prepare("SELECT * FROM {$wpdb->give_funds} WHERE id = %d", $fundId)
721 );
722
723 if (!$fund) {
724 return '';
725 }
726
727 return $fund->title;
728 }
729
730 /**
731 * @since 3.3.0
732 */
733 private function isDefaultFund(int $fundId): bool
734 {
735 global $wpdb;
736
737 $fund = $wpdb->get_row("SELECT id FROM {$wpdb->give_funds} WHERE is_default = 1");
738
739 if (!$fund) {
740 return false;
741 }
742
743 return $fund->id === $fundId;
744 }
745
746 /**
747 * @since 3.4.0
748 *
749 * @return string 'global', 'enabled', 'disabled'
750 */
751 public function getGiftAidStatus(): string
752 {
753 return $this->getMeta('give_gift_aid_enable_disable');
754 }
755
756 /**
757 * @since 3.4.0
758 */
759 public function getGiftAidTitle(): string
760 {
761 return $this->getMeta('give_gift_aid_fieldset_title');
762 }
763
764 /**
765 * @since 3.4.0
766 */
767 public function getGiftAidDescription(): string
768 {
769 return $this->getMeta('give_gift_aid_explanation_content');
770 }
771
772 /**
773 * @since 3.4.0
774 */
775 public function getGiftAidLongExplanationEnabled(): bool
776 {
777 return $this->getMeta('give_gift_aid_long_explanation_enable_disable');
778 }
779
780 /**
781 * @since 3.4.0
782 */
783 public function getGiftAidLongExplanation(): string
784 {
785 return $this->getMeta('give_gift_aid_long_explanation_content');
786 }
787
788 /**
789 * @since 3.4.0
790 */
791 public function getGiftAidCheckboxLabel(): string
792 {
793 return $this->getMeta('give_gift_aid_checkbox_label');
794 }
795
796 /**
797 * @since 3.4.0
798 */
799 public function getGiftAidAgreementText(): string
800 {
801 return $this->getMeta('give_gift_aid_agreement');
802 }
803
804 /**
805 * @since 3.4.0
806 */
807 public function getGiftAidDeclarationForm(): string
808 {
809 return $this->getMeta('give_gift_aid_declaration_form');
810 }
811
812 /**
813 * @since 3.8.0
814 */
815 public function getDoubleTheDonationStatus(): string
816 {
817 return $this->getMeta('dtd_enable_disable');
818 }
819
820 /**
821 * @since 3.8.0
822 */
823 public function getDoubleTheDonationLabel(): string
824 {
825 return $this->getMeta('give_dtd_label');
826 }
827
828 /**
829 * @since 3.5.0
830 */
831 public function getFormFeaturedImage()
832 {
833 $templateSettings = $this->getFormTemplateSettings();
834
835 if ( ! empty($templateSettings['introduction']['image'])) {
836 // Sequoia Template (Multi-Step)
837 $featuredImage = $templateSettings['introduction']['image'];
838 } elseif ( ! empty($templateSettings['visual_appearance']['header_background_image'])) {
839 // Classic Template - it doesn't use the featured image from the WP default setting as a fallback
840 $featuredImage = $templateSettings['visual_appearance']['header_background_image'];
841 } elseif ( ! isset($templateSettings['visual_appearance']['header_background_image'])) {
842 // Legacy Template or Sequoia Template without the ['introduction']['image'] setting
843 $featuredImage = get_the_post_thumbnail_url($this->form->id, 'full');
844 } else {
845 $featuredImage = null;
846 }
847
848 return $featuredImage;
849 }
850
851 /**
852 * @since 3.10.0
853 */
854 public function isActiveCampaignEnabled(): bool
855 {
856 $isFormEnabled = give_is_setting_enabled($this->getMeta('activecampaign_per_form_options'), 'customized');
857
858 $isFormDisabled = give_is_setting_enabled($this->getMeta('activecampaign_per_form_options'), 'disabled');
859
860 $isGloballyEnabled = give_is_setting_enabled(give_get_option('give_activecampaign_globally_enabled'), 'on');
861
862 return !($isFormDisabled || (!$isGloballyEnabled && !$isFormEnabled));
863 }
864
865 /**
866 * @since 3.10.0
867 */
868 public function getActiveCampaignLabel(): string
869 {
870 $defaultMeta = get_option('give_activecampaign_label', __('Subscribe to our newsletter?', 'give'));
871
872 return $this->getMeta('give_activecampaign_label', $defaultMeta);
873 }
874
875 /**
876 * @since 3.10.0
877 */
878 public function getActiveCampaignDefaultChecked(): bool
879 {
880 $isFormEnabled = give_is_setting_enabled($this->getMeta('activecampaign_per_form_options'), 'customized');
881
882 $isGlobalChecked = give_is_setting_enabled(give_get_option('give_activecampaign_checkbox_default'), 'on');
883
884 $isFormChecked = give_is_setting_enabled($this->getMeta('give_activecampaign_checkbox_default'), 'on');
885
886 return $isFormEnabled ? $isFormChecked : $isGlobalChecked;
887 }
888
889 /**
890 * @since 3.10.0
891 */
892 public function getActiveCampaignSelectedLists(): array
893 {
894 $defaultMeta = give_get_option('give_activecampaign_lists', []);
895
896 return !empty($this->getMeta('give_activecampaign_lists')) ?
897 $this->getMeta('give_activecampaign_lists') : $defaultMeta;
898 }
899
900 /**
901 * @since 3.10.0
902 */
903 public function getActiveCampaignTags(): array
904 {
905 $defaultMeta = give_get_option('give_activecampaign_tags',[]);
906
907 return !empty($this->getMeta('give_activecampaign_tags')) ?
908 $this->getMeta('give_activecampaign_tags') : $defaultMeta;
909 }
910 }
911