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 / Shortcodes / CampaignDonationsShortcode.php

CampaignDonationsShortcode.php in GiveWP – Donation Plugin and Fundraising Platform 4.15.2, at src/Campaigns/Shortcodes/CampaignDonationsShortcode.php

87 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Campaigns\Shortcodes;
4
5 use Give\Framework\Support\Facades\Scripts\ScriptAsset;
6 use Give\Helpers\Language;
7
8 /**
9 * @since 4.5.0
10 */
11 class CampaignDonationsShortcode
12 {
13 /**
14 * @since 4.7.0 updated to use ShortcodeRenderController
15 * @since 4.5.0
16 */
17 public function renderShortcode($atts): string
18 {
19 $this->loadAssets();
20 $attributes = $this->parseAttributes($atts);
21
22 $renderFile = GIVE_PLUGIN_DIR . 'src/Campaigns/Blocks/CampaignDonations/render.php';
23
24 return ShortcodeRenderController::renderWithBlockContext(
25 $renderFile,
26 'givewp/campaign-donations-block',
27 $attributes
28 );
29 }
30
31 /**
32 * @since 4.5.0
33 */
34 public function loadAssets()
35 {
36 $handleName = 'givewp-campaign-donations-block-app';
37 $asset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/campaignDonationsBlockApp.asset.php');
38
39 wp_enqueue_script(
40 $handleName,
41 GIVE_PLUGIN_URL . 'build/campaignDonationsBlockApp.js',
42 $asset['dependencies'],
43 $asset['version'],
44 true
45 );
46
47 Language::setScriptTranslations($handleName);
48
49 wp_enqueue_style(
50 $handleName,
51 GIVE_PLUGIN_URL . 'build/campaignDonationsBlockApp.css',
52 [],
53 $asset['version']
54 );
55
56 wp_enqueue_style('givewp-design-system-foundation');
57 }
58
59 /**
60 * @since 4.5.0
61 */
62 private function parseAttributes($atts): array
63 {
64 $atts = shortcode_atts([
65 'campaign_id' => 0,
66 'show_anonymous' => true,
67 'show_icon' => true,
68 'show_button' => true,
69 'donate_button_text' => __('Donate', 'give'),
70 'sort_by' => 'recent-donations',
71 'donations_per_page' => 5,
72 'load_more_button_text' => __('Load more', 'give'),
73 ], $atts, 'givewp_campaign_donations');
74
75 return [
76 'campaignId' => (int) $atts['campaign_id'],
77 'showAnonymous' => filter_var($atts['show_anonymous'], FILTER_VALIDATE_BOOLEAN),
78 'showIcon' => filter_var($atts['show_icon'], FILTER_VALIDATE_BOOLEAN),
79 'showButton' => filter_var($atts['show_button'], FILTER_VALIDATE_BOOLEAN),
80 'donateButtonText' => (string) $atts['donate_button_text'],
81 'sortBy' => (string) $atts['sort_by'],
82 'donationsPerPage' => (int) $atts['donations_per_page'],
83 'loadMoreButtonText' => (string) $atts['load_more_button_text'],
84 ];
85 }
86 }
87