app.tsx
1 year ago
block.json
6 months ago
edit.tsx
1 year ago
index.tsx
1 year ago
render.php
1 year ago
styles.scss
11 months ago
render.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | use Give\Campaigns\Models\Campaign; |
| 4 | use Give\Campaigns\Repositories\CampaignRepository; |
| 5 | |
| 6 | /** |
| 7 | * @var array $attributes |
| 8 | * @var Campaign $campaign |
| 9 | */ |
| 10 | |
| 11 | if (!isset($attributes['campaignId']) || !($campaign = give(CampaignRepository::class)->getById($attributes['campaignId']))) { |
| 12 | return; |
| 13 | } |
| 14 | |
| 15 | $blockInlineStyles = sprintf( |
| 16 | '--givewp-primary-color: %s;', |
| 17 | esc_attr($campaign->primaryColor) |
| 18 | ); |
| 19 | |
| 20 | $useDefaultForm = (bool)filter_var($attributes['useDefaultForm'], FILTER_VALIDATE_BOOLEAN); |
| 21 | $hasSelectedForm = isset($attributes['selectedForm']); |
| 22 | $selectedFormId = $hasSelectedForm ? (int)$attributes['selectedForm'] : null; |
| 23 | $formId = $useDefaultForm || ! $hasSelectedForm ? $campaign->defaultFormId : $selectedFormId; |
| 24 | $buttonText = esc_html($attributes['buttonText'] ?? __('Donate', 'give')); |
| 25 | $isEditor = defined('REST_REQUEST') && REST_REQUEST; |
| 26 | ?> |
| 27 | |
| 28 | <div <?php echo wp_kses_data(get_block_wrapper_attributes(['class' => 'givewp-campaign-donate-button-block', 'style' => esc_attr($blockInlineStyles)])); ?>> |
| 29 | <?php |
| 30 | ob_start(); |
| 31 | if ($isEditor) { |
| 32 | echo sprintf( |
| 33 | '<button type="button" class="givewp-donation-form-modal__open">%s</button>', |
| 34 | esc_html($buttonText) |
| 35 | ); |
| 36 | } else { |
| 37 | echo give_form_shortcode([ |
| 38 | 'id' => $formId, |
| 39 | 'campaign_id' => $campaign->id, |
| 40 | 'display_style' => 'modal', |
| 41 | 'continue_button_title' => $buttonText, |
| 42 | 'use_default_form' => $useDefaultForm, |
| 43 | 'button_color' => $campaign->primaryColor, |
| 44 | 'block_id' => $attributes['blockId'] ?? '', |
| 45 | ]); |
| 46 | } |
| 47 | |
| 48 | $final_output = ob_get_clean(); |
| 49 | echo $final_output; |
| 50 | ?> |
| 51 | </div> |
| 52 |