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 / page-builders / bricks / elements / campaign-donor-comments.php

campaign-donor-comments.php in SureDonation – Donation Forms, Fundraising Campaigns & Donor Management 1.6.1, at inc/page-builders/bricks/elements/campaign-donor-comments.php

146 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Bricks element: Donor Comments.
4 *
5 * @package SureDonation
6 * @since 1.6.0
7 */
8
9 namespace SureDonation\Inc\Page_Builders\Bricks\Elements;
10
11 use SureDonation\Inc\Page_Builders\Bricks\Base_Element;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 /**
18 * Campaign_Donor_Comments class.
19 *
20 * @since 1.6.0
21 */
22 class Campaign_Donor_Comments extends Base_Element {
23 /**
24 * Element name.
25 *
26 * @since 1.6.0
27 * @var string
28 */
29 public $name = 'suredonation-campaign-donor-comments';
30
31 /**
32 * Element icon.
33 *
34 * @since 1.6.0
35 * @var string
36 */
37 public $icon = 'ti-comments';
38
39 /**
40 * Element label shown in the builder panel.
41 *
42 * @since 1.6.0
43 * @return string
44 */
45 public function get_label() {
46 return esc_html__( 'Donor Comments', 'suredonation' );
47 }
48
49 /**
50 * {@inheritDoc}
51 */
52 public function get_keywords() {
53 return array_merge( parent::get_keywords(), [ 'comments', 'messages', 'wall' ] );
54 }
55
56 /**
57 * Register the element controls.
58 *
59 * @since 1.6.0
60 * @return void
61 */
62 public function set_controls() {
63 $this->add_campaign_control();
64
65 $this->controls['commentsToShow'] = [
66 'tab' => 'content',
67 'label' => esc_html__( 'Number of comments', 'suredonation' ),
68 'type' => 'number',
69 'default' => 5,
70 'min' => 1,
71 'max' => 50,
72 ];
73
74 // Inverted (default-off) controls — see Base_Element::setting_bool():
75 // an untouched default-true checkbox would otherwise flip the block's
76 // Gutenberg default. Absent = the corresponding element is shown.
77 $this->controls['hideAnonymous'] = [
78 'tab' => 'content',
79 'label' => esc_html__( 'Hide comments on anonymous donations', 'suredonation' ),
80 'description' => esc_html__( 'By default the comment is kept and the donor name is shown as Anonymous.', 'suredonation' ),
81 'type' => 'checkbox',
82 ];
83
84 $this->controls['hideAvatar'] = [
85 'tab' => 'content',
86 'label' => esc_html__( 'Hide avatar', 'suredonation' ),
87 'type' => 'checkbox',
88 ];
89
90 $this->controls['hideAmount'] = [
91 'tab' => 'content',
92 'label' => esc_html__( 'Hide amount', 'suredonation' ),
93 'type' => 'checkbox',
94 ];
95
96 $this->controls['hideDate'] = [
97 'tab' => 'content',
98 'label' => esc_html__( 'Hide date', 'suredonation' ),
99 'type' => 'checkbox',
100 ];
101
102 $this->controls['commentLength'] = [
103 'tab' => 'content',
104 'label' => esc_html__( 'Comment length', 'suredonation' ),
105 'description' => esc_html__( 'Longer comments are trimmed to this many characters with a read-more link. Set to 0 to always show the whole comment.', 'suredonation' ),
106 'type' => 'number',
107 'default' => 150,
108 'min' => 0,
109 'max' => 1000,
110 ];
111
112 $this->controls['readMoreText'] = [
113 'tab' => 'content',
114 'label' => esc_html__( 'Read more text', 'suredonation' ),
115 'type' => 'text',
116 'default' => esc_html__( 'Read more', 'suredonation' ),
117 ];
118 }
119
120 /**
121 * {@inheritDoc}
122 */
123 protected function block_name() {
124 return 'suredonation/campaign-donor-comments';
125 }
126
127 /**
128 * Map the element settings to the block attributes.
129 *
130 * @since 1.6.0
131 * @param array<string, mixed> $settings Element settings.
132 * @return array<string, mixed>
133 */
134 protected function get_block_attrs( $settings ) {
135 return [
136 'commentsToShow' => max( 1, min( 50, $this->setting_int( $settings, 'commentsToShow', 5 ) ) ),
137 'showAnonymous' => ! $this->setting_bool( $settings, 'hideAnonymous' ),
138 'showAvatar' => ! $this->setting_bool( $settings, 'hideAvatar' ),
139 'showAmount' => ! $this->setting_bool( $settings, 'hideAmount' ),
140 'showDate' => ! $this->setting_bool( $settings, 'hideDate' ),
141 'commentLength' => min( 1000, $this->setting_int( $settings, 'commentLength', 150 ) ),
142 'readMoreText' => $this->setting_string( $settings, 'readMoreText', __( 'Read more', 'suredonation' ) ),
143 ];
144 }
145 }
146