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
CampaignFormShortcode.php
94 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.3.0 |
| 10 | */ |
| 11 | class CampaignFormShortcode |
| 12 | { |
| 13 | /** |
| 14 | * @since 4.3.0 |
| 15 | * |
| 16 | * @param array $atts |
| 17 | * |
| 18 | * @return string |
| 19 | */ |
| 20 | public function renderShortcode($atts): string |
| 21 | { |
| 22 | $this->loadAssets(); |
| 23 | $attributes = $this->parseAttributes($atts); |
| 24 | |
| 25 | $renderFile = GIVE_PLUGIN_DIR . 'src/Campaigns/Blocks/CampaignForm/render.php'; |
| 26 | |
| 27 | ob_start(); |
| 28 | include $renderFile; |
| 29 | return ob_get_clean(); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @since 4.3.0 |
| 34 | */ |
| 35 | public function loadAssets() |
| 36 | { |
| 37 | $handleName = 'givewp-campaign-form-app'; |
| 38 | $asset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/campaignFormBlockApp.asset.php'); |
| 39 | |
| 40 | wp_enqueue_script( |
| 41 | $handleName, |
| 42 | GIVE_PLUGIN_URL . 'build/campaignFormBlockApp.js', |
| 43 | $asset['dependencies'], |
| 44 | $asset['version'], |
| 45 | true |
| 46 | ); |
| 47 | |
| 48 | Language::setScriptTranslations($handleName); |
| 49 | |
| 50 | wp_enqueue_style( |
| 51 | $handleName, |
| 52 | GIVE_PLUGIN_URL . 'build/campaignFormBlockApp.css', |
| 53 | [], |
| 54 | $asset['version'] |
| 55 | ); |
| 56 | |
| 57 | wp_enqueue_style('givewp-design-system-foundation'); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @since 4.3.0 |
| 62 | */ |
| 63 | private function parseAttributes($atts): array |
| 64 | { |
| 65 | $atts = shortcode_atts([ |
| 66 | 'campaign_id' => 0, |
| 67 | 'block_id' => '', |
| 68 | 'prev_id' => 0, |
| 69 | 'id' => 0, |
| 70 | 'display_style' => 'onpage', |
| 71 | 'continue_button_title' => __('Donate Now', 'give'), |
| 72 | 'show_title' => true, |
| 73 | 'content_display' => 'above', |
| 74 | 'show_goal' => true, |
| 75 | 'show_content' => true, |
| 76 | 'use_default_form' => true, |
| 77 | ], $atts, 'givewp_campaign_form'); |
| 78 | |
| 79 | return [ |
| 80 | 'campaignId' => (int) $atts['campaign_id'], |
| 81 | 'blockId' => (string) $atts['block_id'], |
| 82 | 'prevId' => (int) $atts['prev_id'], |
| 83 | 'id' => (int) $atts['id'], |
| 84 | 'displayStyle' => $atts['display_style'], |
| 85 | 'continueButtonTitle' => sanitize_text_field($atts['continue_button_title']), |
| 86 | 'showTitle' => filter_var($atts['show_title'], FILTER_VALIDATE_BOOLEAN), |
| 87 | 'contentDisplay' => $atts['content_display'], |
| 88 | 'showGoal' => filter_var($atts['show_goal'], FILTER_VALIDATE_BOOLEAN), |
| 89 | 'showContent' => filter_var($atts['show_content'], FILTER_VALIDATE_BOOLEAN), |
| 90 | 'useDefaultForm' => filter_var($atts['use_default_form'], FILTER_VALIDATE_BOOLEAN), |
| 91 | ]; |
| 92 | } |
| 93 | } |
| 94 |