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 / CampaignStatsShortcode.php

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

79 lines 1.8 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.7.0
10 */
11 class CampaignStatsShortcode
12 {
13 /**
14 * @since 4.7.0 updated to use ShortcodeRenderController
15 * @since 4.7.0
16 *
17 * @param array<string, mixed> $atts
18 *
19 * @return string
20 */
21 public function renderShortcode($atts): string
22 {
23 $this->loadAssets();
24 $attributes = $this->parseAttributes($atts);
25
26 $renderFile = GIVE_PLUGIN_DIR . 'src/Campaigns/Blocks/CampaignStats/render.php';
27
28 return ShortcodeRenderController::renderWithBlockContext(
29 $renderFile,
30 'givewp/campaign-stats-block',
31 $attributes
32 );
33 }
34
35 /**
36 * @since 4.7.0
37 */
38 public function loadAssets(): void
39 {
40 $handleName = 'givewp-campaign-stats-block-app';
41 $asset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/campaignStatsBlockApp.asset.php');
42
43 wp_enqueue_script(
44 $handleName,
45 GIVE_PLUGIN_URL . 'build/campaignStatsBlockApp.js',
46 $asset['dependencies'],
47 $asset['version'],
48 true
49 );
50
51 Language::setScriptTranslations($handleName);
52
53 wp_enqueue_style(
54 $handleName,
55 GIVE_PLUGIN_URL . 'build/campaignStatsBlockApp.css',
56 [],
57 $asset['version']
58 );
59
60 wp_enqueue_style('givewp-design-system-foundation');
61 }
62
63 /**
64 * @since 4.7.0
65 */
66 private function parseAttributes($atts): array
67 {
68 $atts = shortcode_atts([
69 'campaign_id' => 0,
70 'statistic' => 'top-donation',
71 ], $atts, 'givewp_campaign_stats');
72
73 return [
74 'campaignId' => (int) $atts['campaign_id'],
75 'statistic' => $atts['statistic'],
76 ];
77 }
78 }
79