PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.15.2
GiveWP – Donation Plugin and Fundraising Platform v4.15.2
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 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 All 253 releases
give / src / Campaigns / Blocks / DonateButton / render.php
render.php
52 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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