PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.1.0
GiveWP – Donation Plugin and Fundraising Platform v4.1.0
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 / DonationForms / Shortcodes / GiveFormShortcode.php
GiveFormShortcode.php
56 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\DonationForms\Shortcodes;
4
5 use Give\DonationForms\Actions\GenerateDonationFormViewRouteUrl;
6 use Give\DonationForms\Blocks\DonationFormBlock\Controllers\BlockRenderController;
7
8 class GiveFormShortcode
9 {
10 /**
11 * @var int $instance
12 */
13 public static $instance = 0;
14
15 /**
16 * @since 3.2.0 include v3 block attributes for shortcode.
17 * @since 3.1.1 use static instance ID to simulate blockId attribute
18 * @since 3.0.0
19 */
20 public function __invoke(string $output, array $atts): string
21 {
22 self::$instance++;
23
24 $formId = absint($atts['id']);
25 $isV3Form = (bool)give()->form_meta->get_meta($formId, 'formBuilderSettings', true);
26
27 if (!$formId || !$isV3Form) {
28 return $output;
29 }
30
31 $controller = new BlockRenderController();
32 $blockAttributes = [
33 'formId' => $formId,
34 'blockId' => 'give-form-shortcode-' . self::$instance,
35 'formFormat' => $atts['display_style'] ?? null,
36 'openFormButton' => $atts['continue_button_title'] ?? null
37 ];
38
39 $output = $controller->render($blockAttributes);
40
41 if (!$output) {
42 $viewUrl = (new GenerateDonationFormViewRouteUrl())($formId);
43 $output = sprintf(
44 "<iframe
45 src='%s'
46 style='width: 1px;min-width: 100%%;border: 0;transition: height 0.25s;'
47 onload='if( \"undefined\" !== typeof Give ) { Give.initializeIframeResize(this) }'
48 ></iframe>",
49 esc_url($viewUrl)
50 );
51 }
52
53 return $output;
54 }
55 }
56