PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.1.0
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.1.0
1.6.0 1.5.1 1.5.0 1.4.0 1.3.0 trunk 0.0.1 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0
suredonation / inc / blocks / campaign-donate-button / block.php

block.php in SureDonation – Donation Forms, Fundraising Campaigns & Donor Management 1.1.0, at inc/blocks/campaign-donate-button/block.php

87 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PHP render for the Campaign Donate Button block.
4 *
5 * @package SureDonation
6 * @since 1.0.0
7 */
8
9 namespace SureDonation\Inc\Blocks\Campaign_Donate_Button;
10
11 use SureDonation\Inc\Blocks\Base;
12 use SureDonation\Inc\Campaigns\Campaign_Page;
13 use SureDonation\Inc\Campaigns\Campaign_Stats;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Campaign Donate Button block.
21 *
22 * @since 1.0.0
23 */
24 class Block extends Base {
25 /**
26 * Render the block.
27 *
28 * @param array<string, mixed> $attributes Block attributes.
29 * @param string $content Block content.
30 * @return string
31 * @since 1.0.0
32 */
33 public function render( $attributes, $content = '' ) {
34 unset( $content );
35
36 $campaign_id = Campaign_Page::resolve_campaign_id( $attributes );
37 if ( ! $campaign_id ) {
38 return '';
39 }
40
41 wp_enqueue_style( 'suredonation-campaign-blocks' );
42
43 $text = ! empty( $attributes['buttonText'] ) ? (string) $attributes['buttonText'] : __( 'Donate', 'suredonation' );
44 $stats = Campaign_Stats::get_cached_stats( $campaign_id );
45 $status = isset( $stats['campaign_status'] ) ? (string) $stats['campaign_status'] : 'active';
46
47 // A paused or completed campaign should not invite new donations.
48 $is_active = 'active' === $status;
49
50 if ( ! $is_active ) {
51 $disabled_text = 'completed' === $status
52 ? __( 'Campaign ended', 'suredonation' )
53 : __( 'Donations paused', 'suredonation' );
54
55 $wrapper = get_block_wrapper_attributes(
56 [ 'class' => 'suredonation-campaign-donate-button suredonation-campaign-donate-button--disabled' ]
57 );
58
59 ob_start();
60 ?>
61 <div <?php echo $wrapper; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() returns escaped markup. ?>>
62 <span class="suredonation-campaign-donate-button__link suredonation-campaign-donate-button__link--disabled" aria-disabled="true">
63 <?php echo esc_html( $disabled_text ); ?>
64 </span>
65 </div>
66 <?php
67 $output = ob_get_clean();
68
69 return false !== $output ? $output : '';
70 }
71
72 $wrapper = get_block_wrapper_attributes( [ 'class' => 'suredonation-campaign-donate-button' ] );
73
74 ob_start();
75 ?>
76 <div <?php echo $wrapper; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() returns escaped markup. ?>>
77 <a class="suredonation-campaign-donate-button__link" href="#<?php echo esc_attr( Campaign_Page::FORM_ANCHOR ); ?>">
78 <?php echo esc_html( $text ); ?>
79 </a>
80 </div>
81 <?php
82 $output = ob_get_clean();
83
84 return false !== $output ? $output : '';
85 }
86 }
87