| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Campaigns\Shortcodes; |
| 4 |
|
| 5 |
use Give\Campaigns\Actions\LoadCampaignPublicOptions; |
| 6 |
use Give\Framework\Support\Facades\Scripts\ScriptAsset; |
| 7 |
use Give\Helpers\Language; |
| 8 |
|
| 9 |
/** |
| 10 |
* @since 4.7.0 |
| 11 |
*/ |
| 12 |
class CampaignGoalShortcode |
| 13 |
{ |
| 14 |
/** |
| 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/CampaignGoal/render.php'; |
| 27 |
|
| 28 |
return ShortcodeRenderController::renderWithBlockContext( |
| 29 |
$renderFile, |
| 30 |
'givewp/campaign-goal-block', |
| 31 |
$attributes |
| 32 |
); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* @since 4.7.0 |
| 37 |
*/ |
| 38 |
public function loadAssets(): void |
| 39 |
{ |
| 40 |
give(LoadCampaignPublicOptions::class)(); |
| 41 |
|
| 42 |
$handleName = 'givewp-campaign-goal-block-app'; |
| 43 |
$asset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/campaignGoalBlockApp.asset.php'); |
| 44 |
|
| 45 |
wp_enqueue_script( |
| 46 |
$handleName, |
| 47 |
GIVE_PLUGIN_URL . 'build/campaignGoalBlockApp.js', |
| 48 |
$asset['dependencies'], |
| 49 |
$asset['version'], |
| 50 |
true |
| 51 |
); |
| 52 |
|
| 53 |
Language::setScriptTranslations($handleName); |
| 54 |
|
| 55 |
wp_enqueue_style( |
| 56 |
$handleName, |
| 57 |
GIVE_PLUGIN_URL . 'build/campaignGoalBlockApp.css', |
| 58 |
[], |
| 59 |
$asset['version'] |
| 60 |
); |
| 61 |
|
| 62 |
wp_enqueue_style('givewp-design-system-foundation'); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* @since 4.7.0 |
| 67 |
*/ |
| 68 |
private function parseAttributes($atts): array |
| 69 |
{ |
| 70 |
$atts = shortcode_atts([ |
| 71 |
'campaign_id' => 0, |
| 72 |
], $atts, 'givewp_campaign_goal'); |
| 73 |
|
| 74 |
return [ |
| 75 |
'campaignId' => (int) $atts['campaign_id'], |
| 76 |
]; |
| 77 |
} |
| 78 |
} |
| 79 |
|