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 / DonorDashboards / Block.php

Block.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/DonorDashboards/Block.php

96 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\DonorDashboards;
4
5 use Give\DonorDashboards\App as DonorDashboard;
6
7 class Block
8 {
9
10 protected $donorDashboard;
11
12 public function __construct()
13 {
14 $this->donorDashboard = give(DonorDashboard::class);
15 }
16
17 /**
18 * Registers Donor Dashboard block
19 *
20 * @since 2.10.0
21 **/
22 public function addBlock()
23 {
24 register_block_type(
25 'give/donor-dashboard',
26 [
27 'render_callback' => [$this, 'renderCallback'],
28 'attributes' => [
29 'align' => [
30 'type' => 'string',
31 'default' => 'wide',
32 ],
33 'accent_color' => [
34 'type' => 'string',
35 'default' => '#68bb6c',
36 ],
37 ],
38 ]
39 );
40 }
41
42 /**
43 * Returns Donor Profile block markup
44 *
45 * @since 2.22.1 Add script for iframe onload event to activate gutenberg edit mode.
46 * Gutenberg block edit mode activates when focus set to block container.
47 * @since 2.10.0
48 **/
49 public function renderCallback($attributes)
50 {
51 $output = $this->donorDashboard->getOutput($attributes);
52
53 if( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
54 $output = str_replace(
55 'onload="',
56 sprintf(
57 'onload="%s;',
58 'const iframe = this;this.contentWindow.document.addEventListener(\'click\', function(){iframe.closest(\'[data-block]\').focus({preventScroll: true});})'
59 ),
60 $output
61 );
62 }
63
64 return $output;
65 }
66
67 /**
68 * Load Donor Profile frontend assets
69 *
70 * @since 2.10.0
71 **/
72 public function loadFrontendAssets()
73 {
74 if (has_block('give/donor-dashboard')) {
75 return $this->donorDashboard->loadAssets();
76 }
77 }
78
79 /**
80 * Load Donor Profile block editor assets
81 *
82 * @since 2.10.0
83 **/
84 public function loadEditorAssets()
85 {
86 wp_enqueue_script(
87 'give-donor-dashboards-block',
88 GIVE_PLUGIN_URL . 'build/assets/dist/js/donor-dashboards-block.js',
89 [],
90 GIVE_VERSION,
91 true
92 );
93 wp_set_script_translations( 'give-donor-dashboards-block', 'give' );
94 }
95 }
96