| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\PaymentGateways\Gateways\Offline\Views; |
| 4 |
|
| 5 |
/** |
| 6 |
* Generates the markup for the legacy offline payment fields using the admin settings. |
| 7 |
* |
| 8 |
* @since 3.0.0 |
| 9 |
*/ |
| 10 |
class LegacyFormFieldMarkup |
| 11 |
{ |
| 12 |
/** |
| 13 |
* @since 3.0.0 |
| 14 |
*/ |
| 15 |
public function __invoke(int $formId, bool $includeBillingFields): string |
| 16 |
{ |
| 17 |
$offlineInstructions = stripslashes(give_get_offline_payment_instruction($formId, true)); |
| 18 |
$billingFields = $includeBillingFields ? $this->getBillingFieldsMarkup($formId) : ''; |
| 19 |
|
| 20 |
return trim( |
| 21 |
" |
| 22 |
{$billingFields} |
| 23 |
{$this->getBeforeFieldsHookOutput($formId)} |
| 24 |
<fieldset class='no-fields' id='give_offline_payment_info'> |
| 25 |
{$offlineInstructions} |
| 26 |
</fieldset> |
| 27 |
{$this->getAfterFieldsHookOutput($formId)} |
| 28 |
" |
| 29 |
); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @since 3.0.0 |
| 34 |
*/ |
| 35 |
private function getBeforeFieldsHookOutput(int $formId): string |
| 36 |
{ |
| 37 |
ob_start(); |
| 38 |
|
| 39 |
/** |
| 40 |
* Fires before the offline info fields. |
| 41 |
* |
| 42 |
* @since 1.0 |
| 43 |
* |
| 44 |
* @param int $form_id Give form id. |
| 45 |
*/ |
| 46 |
do_action('give_before_offline_info_fields', $formId); |
| 47 |
|
| 48 |
return ob_get_clean(); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* @since 3.0.0 |
| 53 |
*/ |
| 54 |
private function getAfterFieldsHookOutput(int $formId): string |
| 55 |
{ |
| 56 |
ob_start(); |
| 57 |
|
| 58 |
/** |
| 59 |
* Fires after the offline info fields. |
| 60 |
* |
| 61 |
* @since 1.0 |
| 62 |
* |
| 63 |
* @param int $form_id Give form id. |
| 64 |
*/ |
| 65 |
do_action('give_after_offline_info_fields', $formId); |
| 66 |
|
| 67 |
return ob_get_clean(); |
| 68 |
} |
| 69 |
|
| 70 |
private function getBillingFieldsMarkup(int $formId): string |
| 71 |
{ |
| 72 |
$post_offline_cc_fields = give_get_meta($formId, '_give_offline_donation_enable_billing_fields_single', true); |
| 73 |
$post_offline_customize_option = give_get_meta($formId, '_give_customize_offline_donations', true, 'global'); |
| 74 |
|
| 75 |
$global_offline_cc_fields = give_get_option('give_offline_donation_enable_billing_fields'); |
| 76 |
|
| 77 |
return (give_is_setting_enabled($post_offline_customize_option, 'global') && give_is_setting_enabled( |
| 78 |
$global_offline_cc_fields |
| 79 |
)) |
| 80 |
|| (give_is_setting_enabled($post_offline_customize_option, 'enabled') && give_is_setting_enabled( |
| 81 |
$post_offline_cc_fields |
| 82 |
)) ? give_default_cc_address_fields($formId, true) : ''; |
| 83 |
} |
| 84 |
} |
| 85 |
|