PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Campaigns / Actions / RegisterCampaignBlocks.php

RegisterCampaignBlocks.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Campaigns/Actions/RegisterCampaignBlocks.php

119 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Campaigns\Actions;
4
5 use Give\Framework\Support\Facades\Scripts\ScriptAsset;
6 use Give\Helpers\Language;
7 use WP_Block_Type;
8
9 /**
10 * @since 4.0.0
11 */
12 class RegisterCampaignBlocks
13 {
14 private $campaignBlocks = [];
15
16 /**
17 * @since 4.6.1 Load campaign public options on frontend
18 * @since 4.0.0
19 */
20 public function __invoke()
21 {
22 $blockPaths = glob(dirname(__DIR__) . '/Blocks/*', GLOB_ONLYDIR);
23
24 $this->campaignBlocks = array_filter(
25 array_map('register_block_type', $blockPaths),
26 function ($block) {
27 return $block instanceof WP_Block_Type;
28 }
29 );
30
31 $this->registerSharedStyles();
32 $this->loadCampaignPublicOptions();
33 }
34
35 /**
36 * @since 4.6.1 Load campaign admin options on block editor
37 * @since 4.3.0 set script translations
38 * @since 4.0.0
39 */
40 public function loadBlockEditorAssets(): void
41 {
42 if (!is_admin()) {
43 return;
44 }
45
46 give(LoadCampaignAdminOptions::class)();
47
48 $handleName = 'givewp-campaign-blocks';
49 $scriptAsset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/campaignBlocks.asset.php');
50
51 wp_register_script(
52 $handleName,
53 GIVE_PLUGIN_URL . 'build/campaignBlocks.js',
54 $scriptAsset['dependencies'],
55 $scriptAsset['version'],
56 true
57 );
58 wp_enqueue_script($handleName);
59
60 Language::setScriptTranslations($handleName);
61
62 wp_enqueue_style(
63 $handleName,
64 GIVE_PLUGIN_URL . 'build/campaignBlocks.css',
65 ['wp-components'],
66 $scriptAsset['version']
67 );
68
69 $handleName = 'givewp-campaign-landing-page-blocks';
70 $scriptAsset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/campaignBlocksLandingPage.asset.php');
71
72 wp_register_script(
73 $handleName,
74 GIVE_PLUGIN_URL . 'build/campaignBlocksLandingPage.js',
75 $scriptAsset['dependencies'],
76 $scriptAsset['version'],
77 true
78 );
79 wp_enqueue_script($handleName);
80
81 Language::setScriptTranslations($handleName);
82
83 wp_enqueue_style(
84 $handleName,
85 GIVE_PLUGIN_URL . 'build/campaignBlocksLandingPage.css',
86 ['wp-components'],
87 $scriptAsset['version']
88 );
89
90 }
91
92 /**
93 * @since 4.0.0
94 */
95 private function registerSharedStyles(): void
96 {
97 wp_enqueue_style('givewp-design-system-foundation');
98 wp_enqueue_style(
99 'givewp-campaign-blocks-fonts',
100 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap'
101 );
102 }
103
104 /**
105 * @since 4.6.1
106 */
107 private function loadCampaignPublicOptions(): void
108 {
109 add_action('wp_enqueue_scripts', function () {
110 foreach ($this->campaignBlocks as $block) {
111 if (has_block($block->name)) {
112 give(LoadCampaignPublicOptions::class)();
113 break;
114 }
115 }
116 });
117 }
118 }
119