PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.6.1
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.6.1
1.6.1 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 / fields / donor-comment-markup.php

donor-comment-markup.php in SureDonation – Donation Forms, Fundraising Campaigns & Donor Management 1.6.1, at inc/fields/donor-comment-markup.php

98 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * SureDonation Donor Comment Markup Class.
4 *
5 * @package SureDonation
6 * @since 1.6.0
7 */
8
9 namespace SureDonation\Inc\Fields;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 use SureDonation\Inc\Helper;
16
17 /**
18 * Donor Comment Markup Class.
19 *
20 * Renders the optional public message a donor can leave with their donation.
21 * The value rides the standard `fields[slug]` channel like every other field
22 * block — `Payment_Helper::get_mapped_donor_comment()` lifts it into the
23 * dedicated `donor_comment` column server-side.
24 *
25 * @since 1.6.0
26 */
27 class Donor_Comment_Markup extends Base {
28 /**
29 * Maximum length of text allowed for the comment.
30 *
31 * @var int
32 * @since 1.6.0
33 */
34 protected $max_length = 500;
35
36 /**
37 * Number of visible text rows.
38 *
39 * @var int
40 * @since 1.6.0
41 */
42 protected $rows = 4;
43
44 /**
45 * Initialize the properties based on block attributes.
46 *
47 * @param array<string, mixed> $attributes Block attributes.
48 * @since 1.6.0
49 */
50 public function __construct( $attributes ) {
51 $this->slug = 'donor-comment';
52 $this->max_length = isset( $attributes['maxLength'] ) ? absint( Helper::get_string_value( $attributes['maxLength'] ) ) : 500;
53
54 $this->set_properties( $attributes );
55 $this->set_unique_slug();
56 $this->set_markup_properties();
57 }
58
59 /**
60 * Render donor comment markup.
61 *
62 * @since 1.6.0
63 * @return string
64 */
65 public function markup() {
66 $classes = $this->get_field_classes();
67 $aria_desc = $this->get_aria_describedby();
68
69 ob_start();
70 ?>
71 <div data-block-id="<?php echo esc_attr( $this->block_id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
72 <?php echo wp_kses_post( $this->label_markup ); ?>
73 <?php echo wp_kses_post( $this->help_markup ); ?>
74 <div class="sd-block-wrap">
75 <textarea
76 class="sd-input-common sd-input-donor-comment"
77 name="<?php echo esc_attr( $this->field_name ); ?>"
78 id="<?php echo esc_attr( $this->unique_slug ); ?>"
79 data-slug="<?php echo esc_attr( $this->block_slug ? $this->block_slug : $this->unique_slug ); ?>"
80 rows="<?php echo esc_attr( (string) $this->rows ); ?>"
81 <?php if ( ! empty( $aria_desc ) ) { ?>
82 aria-describedby="<?php echo esc_attr( $aria_desc ); ?>"
83 <?php } ?>
84 data-required="<?php echo esc_attr( $this->data_require_attr ); ?>"
85 aria-required="<?php echo esc_attr( $this->data_require_attr ); ?>"
86 maxlength="<?php echo esc_attr( (string) $this->max_length ); ?>"
87 <?php if ( '' !== $this->placeholder ) { ?>
88 placeholder="<?php echo esc_attr( $this->placeholder ); ?>"
89 <?php } ?>
90 ></textarea>
91 </div>
92 <div class="sd-error-wrap"><?php echo wp_kses_post( $this->error_msg_markup ); ?></div>
93 </div>
94 <?php
95 return (string) ob_get_clean();
96 }
97 }
98