PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.19.6
GiveWP – Donation Plugin and Fundraising Platform v2.19.6
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 2.31.0 2.31.1 All 253 releases
give / src / MultiFormGoals / ProgressBar / Block.php
Block.php
111 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\MultiFormGoals\ProgressBar;
4
5 use Give\MultiFormGoals\ProgressBar\Model as ProgressBar;
6
7 class Block
8 {
9
10 /**
11 * Registers Multi-Form Goals block
12 *
13 * @since 2.9.0
14 **/
15 public function addBlock()
16 {
17 register_block_type(
18 'give/progress-bar',
19 [
20 'render_callback' => [$this, 'renderCallback'],
21 'attributes' => [
22 'ids' => [
23 'type' => 'array',
24 'default' => [],
25 ],
26 'categories' => [
27 'type' => 'array',
28 'default' => [],
29 ],
30 'tags' => [
31 'type' => 'array',
32 'default' => [],
33 ],
34 'goal' => [
35 'type' => 'string',
36 'default' => '1000',
37 ],
38 'enddate' => [
39 'type' => 'string',
40 'default' => '',
41 ],
42 'color' => [
43 'type' => 'string',
44 'default' => '#28c77b',
45 ],
46 ],
47
48 ]
49 );
50 }
51
52 /**
53 * Returns Progress Bar block markup
54 *
55 * @since 2.9.0
56 **/
57 public function renderCallback($attributes)
58 {
59 $progressBar = new ProgressBar(
60 [
61 'ids' => $attributes['ids'],
62 'tags' => $attributes['tags'],
63 'categories' => $attributes['categories'],
64 'goal' => $attributes['goal'],
65 'enddate' => $attributes['enddate'],
66 'color' => $attributes['color'],
67 ]
68 );
69
70 return $progressBar->getOutput();
71 }
72
73 public function localizeAssets()
74 {
75 $defaultColorPalette = [
76 [
77 'name' => __('Red', 'give'),
78 'color' => '#dd3333',
79 ],
80 [
81 'name' => __('Orange', 'give'),
82 'color' => '#dd9933',
83 ],
84 [
85 'name' => __('Green', 'give'),
86 'color' => '#28C77B',
87 ],
88 [
89 'name' => __('Blue', 'give'),
90 'color' => '#1e73be',
91 ],
92 [
93 'name' => __('Purple', 'give'),
94 'color' => '#8224e3',
95 ],
96 [
97 'name' => __('Grey', 'give'),
98 'color' => '#777777',
99 ],
100 ];
101 $editorColorPalette = get_theme_support('editor-color-palette'); // Return value is in a nested array.
102 wp_localize_script(
103 'give-blocks-js',
104 'giveProgressBarThemeSupport',
105 [
106 'editorColorPalette' => $editorColorPalette ? array_shift($editorColorPalette) : $defaultColorPalette,
107 ]
108 );
109 }
110 }
111