CampaignShortcode.php
1 year ago
app.tsx
1 year ago
block.json
1 year ago
edit.tsx
1 year ago
index.tsx
1 year ago
render.php
1 year ago
types.ts
1 year ago
CampaignShortcode.php
72 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Campaigns\Blocks\Campaign; |
| 4 | |
| 5 | /** |
| 6 | * @since 4.2.0 |
| 7 | */ |
| 8 | class CampaignShortcode |
| 9 | { |
| 10 | /** |
| 11 | * @since 4.2.0 |
| 12 | * |
| 13 | * @param array $atts |
| 14 | * |
| 15 | * @return string |
| 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/Campaign/render.php'; |
| 23 | |
| 24 | ob_start(); |
| 25 | include $renderFile; |
| 26 | return ob_get_clean(); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @since 4.2.0 |
| 31 | */ |
| 32 | public function loadAssets() |
| 33 | { |
| 34 | wp_enqueue_script( |
| 35 | 'givewp-campaign-block-app', |
| 36 | GIVE_PLUGIN_URL . 'build/campaignBlockApp.js', |
| 37 | [], |
| 38 | null, |
| 39 | true |
| 40 | ); |
| 41 | |
| 42 | wp_enqueue_style( |
| 43 | 'givewp-campaign-block-style', |
| 44 | GIVE_PLUGIN_URL . 'build/campaignBlockApp.css', |
| 45 | [], |
| 46 | null |
| 47 | ); |
| 48 | |
| 49 | wp_enqueue_style('givewp-design-system-foundation'); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @since 4.2.0 |
| 54 | */ |
| 55 | private function parseAttributes($atts): array |
| 56 | { |
| 57 | $atts = shortcode_atts([ |
| 58 | 'campaign_id' => '', |
| 59 | 'show_image' => true, |
| 60 | 'show_description' => true, |
| 61 | 'show_goal' => true, |
| 62 | ], $atts, 'givewp_campaign'); |
| 63 | |
| 64 | return [ |
| 65 | 'campaignId' => $atts['campaign_id'], |
| 66 | 'showImage' => filter_var($atts['show_image'], FILTER_VALIDATE_BOOLEAN), |
| 67 | 'showDescription' => filter_var($atts['show_description'], FILTER_VALIDATE_BOOLEAN), |
| 68 | 'showGoal' => filter_var($atts['show_goal'], FILTER_VALIDATE_BOOLEAN), |
| 69 | ]; |
| 70 | } |
| 71 | } |
| 72 |