PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.6.1
GiveWP – Donation Plugin and Fundraising Platform v3.6.1
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
790 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.3.0
515 */
516 public function isMailchimpEnabled(): bool
517 {
518 $isFormEnabled = give_is_setting_enabled($this->getMeta('_give_mailchimp_enable'), 'true');
519
520 $isFormDisabled = give_is_setting_enabled($this->getMeta('_give_mailchimp_disable'), 'true');
521
522 $isGloballyEnabled = give_is_setting_enabled(give_get_option('give_mailchimp_show_checkout_signup'), 'on');
523
524 return !($isFormDisabled || (!$isGloballyEnabled && !$isFormEnabled));
525 }
526
527 /**
528 * @since 3.3.0
529 */
530 public function getMailchimpLabel()
531 {
532 $value = $this->getMeta('_give_mailchimp_custom_label');
533 return $value === '' ? null : $value;
534 }
535
536 /**
537 * @since 3.3.0
538 */
539 public function getMailchimpDefaultChecked(): bool
540 {
541 return $this->getMeta('_give_mailchimp_checked_default');
542 }
543
544 /**
545 * @since 3.3.0
546 */
547 public function getMailchimpDoubleOptIn(): bool
548 {
549 return $this->getMeta('_give_mailchimp_double_opt_in');
550 }
551
552 /**
553 * @since 3.3.0
554 */
555 public function getMailchimpSendDonationData(): bool
556 {
557 return $this->getMeta('_give_mailchimp_send_donation');
558 }
559
560 /**
561 * @since 3.3.0
562 */
563 public function getMailchimpSendFFMData(): bool
564 {
565 return $this->getMeta('_give_mailchimp_send_ffm');
566 }
567
568 /**
569 * @since 3.3.0
570 */
571 public function getMailchimpDefaultAudiences(): array
572 {
573 return $this->getMeta('_give_mailchimp');
574 }
575
576 /**
577 * @since 3.3.0
578 */
579 public function getMailchimpSubscriberTags(): array
580 {
581 return $this->getMeta('_give_mailchimp_tags');
582 }
583
584
585 /**
586 * Retrieves metadata for the current form.
587 *
588 * This method acts as a wrapper for the give_get_meta function, reducing redundancy
589 * and improving code readability when fetching metadata related to the current form.
590 *
591 * @since 3.0.0
592 *
593 * @param string $key
594 * @param mixed $default
595 * @return mixed
596 */
597 private function getMeta(string $key, $default = null)
598 {
599 return give_get_meta($this->form->id, $key, true, $default);
600 }
601
602 /**
603 * @since 3.3.1 changed how is checked if the form has funds
604 * @since 3.3.0
605 */
606 public function hasFunds(): bool
607 {
608 $fundsAndDesignationsAttributes = $this->getFundsAndDesignationsAttributes();
609
610 return !empty($fundsAndDesignationsAttributes['fund']);
611 }
612
613 /**
614 * @since 3.3.1 changed how is checked if the form has fund options
615 * @since 3.3.0
616 */
617 public function hasFundOptions(): bool
618 {
619 $fundsAndDesignationsAttributes = $this->getFundsAndDesignationsAttributes();
620
621 return !empty($fundsAndDesignationsAttributes['options']);
622 }
623
624 /**
625 * @since 3.4.0 added additional checks to ensure that the form has funds and fund options
626 * @since 3.3.0
627 */
628 public function getFundsAndDesignationsAttributes(): array
629 {
630 $label = give_get_meta($this->form->id, 'give_funds_label', true);
631 $isAdminChoice = 'admin_choice' === give_get_meta($this->form->id, 'give_funds_form_choice', true);
632 $adminChoice = give_get_meta($this->form->id, 'give_funds_admin_choice', true);
633 $donorOptions = give_get_meta($this->form->id, 'give_funds_donor_choice', true);
634
635
636 $options = [];
637 if (!empty($donorOptions)) {
638 foreach ($donorOptions as $fundId) {
639 $options[] = [
640 'value' => $fundId,
641 'label' => $this->getFundLabel($fundId),
642 'checked' => $isAdminChoice ? $fundId === $adminChoice : true,
643 'isDefault' => $this->isDefaultFund($fundId),
644 ];
645 }
646 }
647
648 $fund = [];
649 if ($isAdminChoice) {
650 $fund = [
651 'value' => $adminChoice,
652 'label' => $this->getFundLabel($adminChoice),
653 'checked' => true,
654 'isDefault' => $this->isDefaultFund($adminChoice),
655 ];
656 } elseif (!empty($options)) {
657 $fund = $options[0];
658 }
659
660 return [
661 'label' => $label,
662 'fund' => $fund,
663 'options' => $options,
664 ];
665 }
666
667 /**
668 * @since 3.3.0
669 */
670 private function getFundLabel(int $fundId): string
671 {
672 global $wpdb;
673
674 $fund = $wpdb->get_row(
675 $wpdb->prepare("SELECT * FROM {$wpdb->give_funds} WHERE id = %d", $fundId)
676 );
677
678 if (!$fund) {
679 return '';
680 }
681
682 return $fund->title;
683 }
684
685 /**
686 * @since 3.3.0
687 */
688 private function isDefaultFund(int $fundId): bool
689 {
690 global $wpdb;
691
692 $fund = $wpdb->get_row("SELECT id FROM {$wpdb->give_funds} WHERE is_default = 1");
693
694 if (!$fund) {
695 return false;
696 }
697
698 return $fund->id === $fundId;
699 }
700
701 /**
702 * @since 3.4.0
703 *
704 * @return string 'global', 'enabled', 'disabled'
705 */
706 public function getGiftAidStatus(): string
707 {
708 return $this->getMeta('give_gift_aid_enable_disable');
709 }
710
711 /**
712 * @since 3.4.0
713 */
714 public function getGiftAidTitle(): string
715 {
716 return $this->getMeta('give_gift_aid_fieldset_title');
717 }
718
719 /**
720 * @since 3.4.0
721 */
722 public function getGiftAidDescription(): string
723 {
724 return $this->getMeta('give_gift_aid_explanation_content');
725 }
726
727 /**
728 * @since 3.4.0
729 */
730 public function getGiftAidLongExplanationEnabled(): bool
731 {
732 return $this->getMeta('give_gift_aid_long_explanation_enable_disable');
733 }
734
735 /**
736 * @since 3.4.0
737 */
738 public function getGiftAidLongExplanation(): string
739 {
740 return $this->getMeta('give_gift_aid_long_explanation_content');
741 }
742
743 /**
744 * @since 3.4.0
745 */
746 public function getGiftAidCheckboxLabel(): string
747 {
748 return $this->getMeta('give_gift_aid_checkbox_label');
749 }
750
751 /**
752 * @since 3.4.0
753 */
754 public function getGiftAidAgreementText(): string
755 {
756 return $this->getMeta('give_gift_aid_agreement');
757 }
758
759 /**
760 * @since 3.4.0
761 */
762 public function getGiftAidDeclarationForm(): string
763 {
764 return $this->getMeta('give_gift_aid_declaration_form');
765 }
766
767 /**
768 * @since 3.5.0
769 */
770 public function getFormFeaturedImage()
771 {
772 $templateSettings = $this->getFormTemplateSettings();
773
774 if ( ! empty($templateSettings['introduction']['image'])) {
775 // Sequoia Template (Multi-Step)
776 $featuredImage = $templateSettings['introduction']['image'];
777 } elseif ( ! empty($templateSettings['visual_appearance']['header_background_image'])) {
778 // Classic Template - it doesn't use the featured image from the WP default setting as a fallback
779 $featuredImage = $templateSettings['visual_appearance']['header_background_image'];
780 } elseif ( ! isset($templateSettings['visual_appearance']['header_background_image'])) {
781 // Legacy Template or Sequoia Template without the ['introduction']['image'] setting
782 $featuredImage = get_the_post_thumbnail_url($this->form->id, 'full');
783 } else {
784 $featuredImage = null;
785 }
786
787 return $featuredImage;
788 }
789 }
790