PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 4.13.0
GiveWP – Donation Plugin and Fundraising Platform v4.13.0
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 8 months ago Commands 2 years ago Concerns 2 years ago Contracts 2 years ago Controllers 1 year ago DataTransferObjects 1 year ago Steps 1 year ago FormMetaDecorator.php 9 months ago Pipeline.php 2 years ago ServiceProvider.php 1 year ago StepProcessor.php 2 years ago functions.php 2 years ago
FormMetaDecorator.php
1034 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(
523 give_get_option('givewp_constant_contact_show_checkout_signup'),
524 'on'
525 );
526
527 return ! ($isFormDisabled || ( ! $isGloballyEnabled && ! $isFormEnabled));
528 }
529
530 /**
531 * @since 3.7.0
532 */
533 public function getConstantContactLabel(): string
534 {
535 $defaultMeta = give_get_option('givewp_constant_contact_label', __('Subscribe to our newsletter?', 'give'));
536
537 return $this->getMeta('_give_constant_contact_custom_label', $defaultMeta);
538 }
539
540 /**
541 * @since 3.7.0
542 */
543 public function getConstantContactDefaultChecked(): bool
544 {
545 $defaultMeta = give_is_setting_enabled(
546 give_get_option(
547 'givewp_constant_contact_checked_default',
548 true
549 ),
550 'on'
551 );
552
553 return $this->getMeta('_give_constant_contact_checked_default', $defaultMeta);
554 }
555
556 /**
557 * @since 3.7.0
558 */
559 public function getConstantContactSelectedLists(): array
560 {
561 $defaultMeta = give_get_option('givewp_constant_contact_list', []);
562
563 return (array)$this->getMeta('_give_constant_contact', $defaultMeta);
564 }
565
566 /**
567 * @since 3.3.0
568 */
569 public function isMailchimpEnabled(): bool
570 {
571 $isFormEnabled = give_is_setting_enabled($this->getMeta('_give_mailchimp_enable'), 'true');
572
573 $isFormDisabled = give_is_setting_enabled($this->getMeta('_give_mailchimp_disable'), 'true');
574
575 $isGloballyEnabled = give_is_setting_enabled(give_get_option('give_mailchimp_show_checkout_signup'), 'on');
576
577 return ! ($isFormDisabled || ( ! $isGloballyEnabled && ! $isFormEnabled));
578 }
579
580 /**
581 * @since 3.3.0
582 */
583 public function getMailchimpLabel(): string
584 {
585 return $this->getMeta(
586 '_give_mailchimp_custom_label',
587 give_get_option('give_mailchimp_label', __('Subscribe to newsletter?', 'give'))
588 );
589 }
590
591 /**
592 * @since 3.7.0 add global setting as default.
593 * @since 3.3.0
594 */
595 public function getMailchimpDefaultChecked(): bool
596 {
597 return give_is_setting_enabled(
598 $this->getMeta(
599 '_give_mailchimp_checked_default',
600 give_get_option('give_mailchimp_checked_default', true)
601 )
602 );
603 }
604
605 /**
606 * @since 3.7.0 add global setting as default.
607 * @since 3.3.0
608 */
609 public function getMailchimpSendDonationData(): bool
610 {
611 return give_is_setting_enabled(
612 $this->getMeta(
613 '_give_mailchimp_send_donation_data',
614 give_get_option('give_mailchimp_donation_data', true)
615 )
616 );
617 }
618
619 /**
620 * @since 3.7.0 add global setting as default.
621 * @since 3.3.0
622 */
623 public function getMailchimpSendFFMData(): bool
624 {
625 return give_is_setting_enabled(
626 $this->getMeta(
627 '_give_mailchimp_send_ffm',
628 give_get_option('give_mailchimp_ffm_pass_field')
629 )
630 );
631 }
632
633 /**
634 * @since 3.3.0
635 */
636 public function getMailchimpDefaultAudiences(): array
637 {
638 return (array)$this->getMeta('_give_mailchimp', give_get_option('give_mailchimp_list', ['']));
639 }
640
641 /**
642 * @since 3.3.0
643 */
644 public function getMailchimpSubscriberTags(): ?array
645 {
646 return (array)$this->getMeta('_give_mailchimp_tags', null);
647 }
648
649
650 /**
651 * Retrieves metadata for the current form.
652 *
653 * This method acts as a wrapper for the give_get_meta function, reducing redundancy
654 * and improving code readability when fetching metadata related to the current form.
655 *
656 * @since 3.0.0
657 *
658 * @param string $key
659 * @param mixed $default
660 *
661 * @return mixed
662 */
663 private function getMeta(string $key, $default = null)
664 {
665 return give_get_meta($this->form->id, $key, true, $default);
666 }
667
668 /**
669 * @since 3.3.1 changed how is checked if the form has funds
670 * @since 3.3.0
671 */
672 public function hasFunds(): bool
673 {
674 $fundsAndDesignationsAttributes = $this->getFundsAndDesignationsAttributes();
675
676 return ! empty($fundsAndDesignationsAttributes['fund']);
677 }
678
679 /**
680 * @since 3.3.1 changed how is checked if the form has fund options
681 * @since 3.3.0
682 */
683 public function hasFundOptions(): bool
684 {
685 $fundsAndDesignationsAttributes = $this->getFundsAndDesignationsAttributes();
686
687 return ! empty($fundsAndDesignationsAttributes['options']);
688 }
689
690 /**
691 * @since 3.4.0 added additional checks to ensure that the form has funds and fund options
692 * @since 3.3.0
693 */
694 public function getFundsAndDesignationsAttributes(): array
695 {
696 $label = give_get_meta($this->form->id, 'give_funds_label', true);
697 $isAdminChoice = 'admin_choice' === give_get_meta($this->form->id, 'give_funds_form_choice', true);
698 $adminChoice = give_get_meta($this->form->id, 'give_funds_admin_choice', true);
699 $donorOptions = give_get_meta($this->form->id, 'give_funds_donor_choice', true);
700
701
702 $options = [];
703 if ( ! empty($donorOptions)) {
704 foreach ($donorOptions as $fundId) {
705 $options[] = [
706 'value' => $fundId,
707 'label' => $this->getFundLabel($fundId),
708 'checked' => $isAdminChoice ? $fundId === $adminChoice : true,
709 'isDefault' => $this->isDefaultFund($fundId),
710 ];
711 }
712 }
713
714 $fund = [];
715 if ($isAdminChoice) {
716 $fund = [
717 'value' => $adminChoice,
718 'label' => $this->getFundLabel($adminChoice),
719 'checked' => true,
720 'isDefault' => $this->isDefaultFund($adminChoice),
721 ];
722 } elseif ( ! empty($options)) {
723 $fund = $options[0];
724 }
725
726 return [
727 'label' => $label,
728 'fund' => $fund,
729 'options' => $options,
730 ];
731 }
732
733 /**
734 * @since 3.3.0
735 */
736 private function getFundLabel(int $fundId): string
737 {
738 global $wpdb;
739
740 $fund = $wpdb->get_row(
741 $wpdb->prepare("SELECT * FROM {$wpdb->give_funds} WHERE id = %d", $fundId)
742 );
743
744 if ( ! $fund) {
745 return '';
746 }
747
748 return $fund->title;
749 }
750
751 /**
752 * @since 3.3.0
753 */
754 private function isDefaultFund(int $fundId): bool
755 {
756 global $wpdb;
757
758 $fund = $wpdb->get_row("SELECT id FROM {$wpdb->give_funds} WHERE is_default = 1");
759
760 if ( ! $fund) {
761 return false;
762 }
763
764 return $fund->id === $fundId;
765 }
766
767 /**
768 * @since 3.4.0
769 *
770 * @return string 'global', 'enabled', 'disabled'
771 */
772 public function getGiftAidStatus(): string
773 {
774 return $this->getMeta('give_gift_aid_enable_disable');
775 }
776
777 /**
778 * @since 3.4.0
779 */
780 public function getGiftAidTitle(): string
781 {
782 return $this->getMeta('give_gift_aid_fieldset_title');
783 }
784
785 /**
786 * @since 3.4.0
787 */
788 public function getGiftAidDescription(): string
789 {
790 return $this->getMeta('give_gift_aid_explanation_content');
791 }
792
793 /**
794 * @since 3.4.0
795 */
796 public function getGiftAidLongExplanationEnabled(): bool
797 {
798 return $this->getMeta('give_gift_aid_long_explanation_enable_disable');
799 }
800
801 /**
802 * @since 3.4.0
803 */
804 public function getGiftAidLongExplanation(): string
805 {
806 return $this->getMeta('give_gift_aid_long_explanation_content');
807 }
808
809 /**
810 * @since 3.4.0
811 */
812 public function getGiftAidCheckboxLabel(): string
813 {
814 return $this->getMeta('give_gift_aid_checkbox_label');
815 }
816
817 /**
818 * @since 3.4.0
819 */
820 public function getGiftAidAgreementText(): string
821 {
822 return $this->getMeta('give_gift_aid_agreement');
823 }
824
825 /**
826 * @since 3.4.0
827 */
828 public function getGiftAidDeclarationForm(): string
829 {
830 return $this->getMeta('give_gift_aid_declaration_form');
831 }
832
833 /**
834 * @since 3.8.0
835 */
836 public function getDoubleTheDonationStatus(): string
837 {
838 return $this->getMeta('dtd_enable_disable');
839 }
840
841 /**
842 * @since 3.8.0
843 */
844 public function getDoubleTheDonationLabel(): string
845 {
846 return $this->getMeta('give_dtd_label');
847 }
848
849 /**
850 * @since 3.5.0
851 */
852 public function getFormFeaturedImage()
853 {
854 $templateSettings = $this->getFormTemplateSettings();
855
856 if ( ! empty($templateSettings['introduction']['image'])) {
857 // Sequoia Template (Multi-Step)
858 $featuredImage = $templateSettings['introduction']['image'];
859 } elseif ( ! empty($templateSettings['visual_appearance']['header_background_image'])) {
860 // Classic Template - it doesn't use the featured image from the WP default setting as a fallback
861 $featuredImage = $templateSettings['visual_appearance']['header_background_image'];
862 } elseif ( ! isset($templateSettings['visual_appearance']['header_background_image'])) {
863 // Legacy Template or Sequoia Template without the ['introduction']['image'] setting
864 $featuredImage = get_the_post_thumbnail_url($this->form->id, 'full');
865 } else {
866 $featuredImage = null;
867 }
868
869 return $featuredImage;
870 }
871
872 /**
873 * @since 3.10.0
874 */
875 public function isConvertKitEnabled(): bool
876 {
877 $isFormEnabled = $this->getMeta('_give_convertkit_override_option') === 'customize';
878
879 $isFormDisabled = $this->getMeta('_give_convertkit_override_option') === 'disabled';
880
881 $isGloballyEnabled = $this->getMeta('_give_convertkit_override_option') === 'default' &&
882 give_is_setting_enabled(give_get_option('give_convertkit_show_subscribe_checkbox'));
883
884 return ! ($isFormDisabled || ( ! $isGloballyEnabled && ! $isFormEnabled));
885 }
886
887 /**
888 * @since 3.11.0
889 */
890 public function getConvertKitLabel(): string
891 {
892 $defaultMeta = give_get_option('give_convertkit_label', __('Subscribe to newsletter?', 'give'));
893
894 return $this->getMeta('_give_convertkit_custom_label', $defaultMeta);
895 }
896
897 /**
898 * @since 3.11.0
899 */
900 public function getConvertKitDefaultChecked(): bool
901 {
902 $defaultMeta = give_get_option('give_convertkit_checked_default');
903
904 return give_is_setting_enabled($this->getMeta('_give_convertkit_checked_default', $defaultMeta));
905 }
906
907 /**
908 * @since 3.11.0
909 */
910 public function getConvertKitTags(): ?array
911 {
912 $defaultMeta = give_get_option('_give_convertkit_tags', []);
913
914 return ! empty($this->getMeta('_give_convertkit_tags')) ?
915 $this->getMeta('_give_convertkit_tags') :
916 $defaultMeta;
917 }
918
919 /**
920 * @since 3.11.0
921 */
922 public function getConvertKitSelectedForm(): string
923 {
924 $defaultMeta = give_get_option('give_convertkit_list', '');
925
926 return $this->getMeta('_give_convertkit', $defaultMeta);
927 }
928
929 public function isActiveCampaignEnabled(): bool
930 {
931 $isFormEnabled = give_is_setting_enabled($this->getMeta('activecampaign_per_form_options'), 'customized');
932
933 $isFormDisabled = give_is_setting_enabled($this->getMeta('activecampaign_per_form_options'), 'disabled');
934
935 $isGloballyEnabled = give_is_setting_enabled(give_get_option('give_activecampaign_globally_enabled'), 'on');
936
937 return ! ($isFormDisabled || ( ! $isGloballyEnabled && ! $isFormEnabled));
938 }
939
940 /**
941 * @since 3.10.0
942 */
943 public function getActiveCampaignLabel(): string
944 {
945 $defaultMeta = get_option('give_activecampaign_label', __('Subscribe to our newsletter?', 'give'));
946
947 return $this->getMeta('give_activecampaign_label', $defaultMeta);
948 }
949
950 /**
951 * @since 3.10.0
952 */
953 public function getActiveCampaignDefaultChecked(): bool
954 {
955 $isFormEnabled = give_is_setting_enabled($this->getMeta('activecampaign_per_form_options'), 'customized');
956
957 $isGlobalChecked = give_is_setting_enabled(give_get_option('give_activecampaign_checkbox_default'), 'on');
958
959 $isFormChecked = give_is_setting_enabled($this->getMeta('give_activecampaign_checkbox_default'), 'on');
960
961 return $isFormEnabled ? $isFormChecked : $isGlobalChecked;
962 }
963
964 /**
965 * @since 3.10.0
966 */
967 public function getActiveCampaignSelectedLists(): array
968 {
969 $defaultMeta = give_get_option('give_activecampaign_lists', []);
970
971 return ! empty($this->getMeta('give_activecampaign_lists')) ?
972 $this->getMeta('give_activecampaign_lists') : $defaultMeta;
973 }
974
975 /**
976 * @since 3.10.0
977 */
978 public function getActiveCampaignTags(): array
979 {
980 $defaultMeta = give_get_option('give_activecampaign_tags', []);
981
982 return ! empty($this->getMeta('give_activecampaign_tags')) ?
983 $this->getMeta('give_activecampaign_tags') : $defaultMeta;
984 }
985
986 /**
987 * @since 3.13.0
988 */
989 public function getCurrencySwitcherStatus(): string
990 {
991 return $this->getMeta('cs_status', 'global');
992 }
993
994 /**
995 * @since 3.13.0
996 */
997 public function getCurrencySwitcherMessage(): string
998 {
999 return $this->getMeta(
1000 'cs_message',
1001 sprintf(
1002 __('The current exchange rate is 1.00 %1$s equals %2$s %3$s.', 'give-currency-switcher'),
1003 '{base_currency}',
1004 '{new_currency_rate}',
1005 '{new_currency}'
1006 )
1007 );
1008 }
1009
1010 /**
1011 * @since 3.13.0
1012 */
1013 public function getCurrencySwitcherDefaultCurrency(): string
1014 {
1015 return $this->getMeta('give_cs_default_currency', '');
1016 }
1017
1018 /**
1019 * @since 3.13.0
1020 */
1021 public function getCurrencySwitcherSupportedCurrencies(): array
1022 {
1023 return (array)$this->getMeta('cs_supported_currency', []);
1024 }
1025
1026 /**
1027 * @since 3.14.0
1028 */
1029 public function isRazorpayPerFormSettingsEnabled(): bool
1030 {
1031 return give_is_setting_enabled($this->getMeta('razorpay_per_form_account_options'));
1032 }
1033 }
1034