PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.9 4.16.8.1 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 All 255 releases
give / src / Campaigns / Shortcodes / CampaignDonorsShortcode.php

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

91 lines 2.9 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 CampaignDonorsShortcode
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/CampaignDonors/render.php';
23
24 return ShortcodeRenderController::renderWithBlockContext(
25 $renderFile,
26 'givewp/campaign-donors-block',
27 $attributes
28 );
29 }
30
31 /**
32 * @since 4.5.0
33 */
34 public function loadAssets()
35 {
36 $handleName = 'givewp-campaign-donors-block-app';
37 $asset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/campaignDonorsBlockApp.asset.php');
38
39 wp_enqueue_script(
40 $handleName,
41 GIVE_PLUGIN_URL . 'build/campaignDonorsBlockApp.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/campaignDonorsBlockApp.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 'block_id' => '',
67 'show_anonymous' => true,
68 'show_company_name' => true,
69 'show_avatar' => true,
70 'show_button' => true,
71 'donate_button_text' => __('Join the list', 'give'),
72 'sort_by' => 'top-donors',
73 'donors_per_page' => 5,
74 'load_more_button_text' => __('Load more', 'give'),
75 ], $atts, 'givewp_campaign_donors');
76
77 return [
78 'campaignId' => (int) $atts['campaign_id'],
79 'blockId' => (string) $atts['block_id'],
80 'showAnonymous' => filter_var($atts['show_anonymous'], FILTER_VALIDATE_BOOLEAN),
81 'showCompanyName' => filter_var($atts['show_company_name'], FILTER_VALIDATE_BOOLEAN),
82 'showAvatar' => filter_var($atts['show_avatar'], FILTER_VALIDATE_BOOLEAN),
83 'showButton' => filter_var($atts['show_button'], FILTER_VALIDATE_BOOLEAN),
84 'donateButtonText' => (string) $atts['donate_button_text'],
85 'sortBy' => (string) $atts['sort_by'],
86 'donorsPerPage' => (int) $atts['donors_per_page'],
87 'loadMoreButtonText' => (string) $atts['load_more_button_text'],
88 ];
89 }
90 }
91