CampaignCommentsShortcode.php
11 months ago
CampaignDonationsShortcode.php
11 months ago
CampaignDonorsShortcode.php
11 months ago
CampaignFormShortcode.php
11 months ago
CampaignGridShortcode.php
11 months ago
CampaignShortcode.php
11 months ago
CampaignDonationsShortcode.php
84 lines
| 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.5.0 |
| 15 | */ |
| 16 | public function renderShortcode($atts): string |
| 17 | { |
| 18 | $this->loadAssets(); |
| 19 | $attributes = $this->parseAttributes($atts); |
| 20 | |
| 21 | $renderFile = GIVE_PLUGIN_DIR . 'src/Campaigns/Blocks/CampaignDonations/render.php'; |
| 22 | |
| 23 | ob_start(); |
| 24 | include $renderFile; |
| 25 | return ob_get_clean(); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @since 4.5.0 |
| 30 | */ |
| 31 | public function loadAssets() |
| 32 | { |
| 33 | $handleName = 'givewp-campaign-donations-block-app'; |
| 34 | $asset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/campaignDonationsBlockApp.asset.php'); |
| 35 | |
| 36 | wp_enqueue_script( |
| 37 | $handleName, |
| 38 | GIVE_PLUGIN_URL . 'build/campaignDonationsBlockApp.js', |
| 39 | $asset['dependencies'], |
| 40 | $asset['version'], |
| 41 | true |
| 42 | ); |
| 43 | |
| 44 | Language::setScriptTranslations($handleName); |
| 45 | |
| 46 | wp_enqueue_style( |
| 47 | $handleName, |
| 48 | GIVE_PLUGIN_URL . 'build/campaignDonationsBlockApp.css', |
| 49 | [], |
| 50 | $asset['version'] |
| 51 | ); |
| 52 | |
| 53 | wp_enqueue_style('givewp-design-system-foundation'); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @since 4.5.0 |
| 58 | */ |
| 59 | private function parseAttributes($atts): array |
| 60 | { |
| 61 | $atts = shortcode_atts([ |
| 62 | 'campaign_id' => 0, |
| 63 | 'show_anonymous' => true, |
| 64 | 'show_icon' => true, |
| 65 | 'show_button' => true, |
| 66 | 'donate_button_text' => __('Donate', 'give'), |
| 67 | 'sort_by' => 'recent-donations', |
| 68 | 'donations_per_page' => 5, |
| 69 | 'load_more_button_text' => __('Load more', 'give'), |
| 70 | ], $atts, 'givewp_campaign_donations'); |
| 71 | |
| 72 | return [ |
| 73 | 'campaignId' => (int) $atts['campaign_id'], |
| 74 | 'showAnonymous' => filter_var($atts['show_anonymous'], FILTER_VALIDATE_BOOLEAN), |
| 75 | 'showIcon' => filter_var($atts['show_icon'], FILTER_VALIDATE_BOOLEAN), |
| 76 | 'showButton' => filter_var($atts['show_button'], FILTER_VALIDATE_BOOLEAN), |
| 77 | 'donateButtonText' => (string) $atts['donate_button_text'], |
| 78 | 'sortBy' => (string) $atts['sort_by'], |
| 79 | 'donationsPerPage' => (int) $atts['donations_per_page'], |
| 80 | 'loadMoreButtonText' => (string) $atts['load_more_button_text'], |
| 81 | ]; |
| 82 | } |
| 83 | } |
| 84 |