CampaignCommentsShortcode.php
1 month ago
CampaignDonationsShortcode.php
1 year ago
CampaignDonorsShortcode.php
1 year ago
CampaignFormShortcode.php
1 year ago
CampaignGoalShortcode.php
1 year ago
CampaignGridShortcode.php
1 year ago
CampaignShortcode.php
1 year ago
CampaignStatsShortcode.php
1 year ago
ShortcodeRenderController.php
1 year ago
CampaignFormShortcode.php
97 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.7.0 updated to use ShortcodeRenderController |
| 15 | * @since 4.3.0 |
| 16 | * |
| 17 | * @param array $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/CampaignForm/render.php'; |
| 27 | |
| 28 | return ShortcodeRenderController::renderWithBlockContext( |
| 29 | $renderFile, |
| 30 | 'givewp/campaign-form-block', |
| 31 | $attributes |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @since 4.3.0 |
| 37 | */ |
| 38 | public function loadAssets() |
| 39 | { |
| 40 | $handleName = 'givewp-campaign-form-app'; |
| 41 | $asset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/campaignFormBlockApp.asset.php'); |
| 42 | |
| 43 | wp_enqueue_script( |
| 44 | $handleName, |
| 45 | GIVE_PLUGIN_URL . 'build/campaignFormBlockApp.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/campaignFormBlockApp.css', |
| 56 | [], |
| 57 | $asset['version'] |
| 58 | ); |
| 59 | |
| 60 | wp_enqueue_style('givewp-design-system-foundation'); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @since 4.3.0 |
| 65 | */ |
| 66 | private function parseAttributes($atts): array |
| 67 | { |
| 68 | $atts = shortcode_atts([ |
| 69 | 'campaign_id' => 0, |
| 70 | 'block_id' => '', |
| 71 | 'prev_id' => 0, |
| 72 | 'id' => 0, |
| 73 | 'display_style' => 'onpage', |
| 74 | 'continue_button_title' => __('Donate Now', 'give'), |
| 75 | 'show_title' => true, |
| 76 | 'content_display' => 'above', |
| 77 | 'show_goal' => true, |
| 78 | 'show_content' => true, |
| 79 | 'use_default_form' => true, |
| 80 | ], $atts, 'givewp_campaign_form'); |
| 81 | |
| 82 | return [ |
| 83 | 'campaignId' => (int) $atts['campaign_id'], |
| 84 | 'blockId' => (string) $atts['block_id'], |
| 85 | 'prevId' => (int) $atts['prev_id'], |
| 86 | 'id' => (int) $atts['id'], |
| 87 | 'displayStyle' => $atts['display_style'], |
| 88 | 'continueButtonTitle' => sanitize_text_field($atts['continue_button_title']), |
| 89 | 'showTitle' => filter_var($atts['show_title'], FILTER_VALIDATE_BOOLEAN), |
| 90 | 'contentDisplay' => $atts['content_display'], |
| 91 | 'showGoal' => filter_var($atts['show_goal'], FILTER_VALIDATE_BOOLEAN), |
| 92 | 'showContent' => filter_var($atts['show_content'], FILTER_VALIDATE_BOOLEAN), |
| 93 | 'useDefaultForm' => filter_var($atts['use_default_form'], FILTER_VALIDATE_BOOLEAN), |
| 94 | ]; |
| 95 | } |
| 96 | } |
| 97 |