PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.4.0
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.4.0
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-donations.php

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

121 lines 2.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: Campaign Donations.
4 *
5 * @package SureDonation
6 * @since 1.2.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_Donations class.
19 *
20 * @since 1.2.0
21 */
22 class Campaign_Donations extends Base_Element {
23 /**
24 * Element name.
25 *
26 * @since 1.2.0
27 * @var string
28 */
29 public $name = 'suredonation-campaign-donations';
30
31 /**
32 * Element icon.
33 *
34 * @since 1.2.0
35 * @var string
36 */
37 public $icon = 'ti-list';
38
39 /**
40 * Element label shown in the builder panel.
41 *
42 * @since 1.2.0
43 * @return string
44 */
45 public function get_label() {
46 return esc_html__( 'Campaign Donations', 'suredonation' );
47 }
48
49 /**
50 * {@inheritDoc}
51 */
52 public function get_keywords() {
53 return array_merge( parent::get_keywords(), [ 'donations', 'recent' ] );
54 }
55
56 /**
57 * Register the element controls.
58 *
59 * @since 1.2.0
60 * @return void
61 */
62 public function set_controls() {
63 $this->add_campaign_control();
64
65 $this->controls['donationsToShow'] = [
66 'tab' => 'content',
67 'label' => esc_html__( 'Number of donations', 'suredonation' ),
68 'type' => 'number',
69 'default' => 5,
70 'min' => 1,
71 'max' => 50,
72 ];
73
74 // Inverted (default-off) control — see Base_Element::setting_bool():
75 // an untouched default-true checkbox would otherwise flip the block's
76 // Gutenberg default. Absent = anonymous donations shown.
77 $this->controls['hideAnonymous'] = [
78 'tab' => 'content',
79 'label' => esc_html__( 'Hide anonymous donations', 'suredonation' ),
80 'type' => 'checkbox',
81 ];
82
83 $this->controls['showButton'] = [
84 'tab' => 'content',
85 'label' => esc_html__( 'Show button', 'suredonation' ),
86 'type' => 'checkbox',
87 ];
88
89 $this->controls['buttonText'] = [
90 'tab' => 'content',
91 'label' => esc_html__( 'Button text', 'suredonation' ),
92 'type' => 'text',
93 'default' => esc_html__( 'Donate', 'suredonation' ),
94 'required' => [ 'showButton', '=', true ],
95 ];
96 }
97
98 /**
99 * {@inheritDoc}
100 */
101 protected function block_name() {
102 return 'suredonation/campaign-donations';
103 }
104
105 /**
106 * Map the element settings to the block attributes.
107 *
108 * @since 1.2.0
109 * @param array<string, mixed> $settings Element settings.
110 * @return array<string, mixed>
111 */
112 protected function get_block_attrs( $settings ) {
113 return [
114 'donationsToShow' => max( 1, min( 50, $this->setting_int( $settings, 'donationsToShow', 5 ) ) ),
115 'showAnonymous' => ! $this->setting_bool( $settings, 'hideAnonymous' ),
116 'showButton' => $this->setting_bool( $settings, 'showButton' ),
117 'buttonText' => $this->setting_string( $settings, 'buttonText', __( 'Donate', 'suredonation' ) ),
118 ];
119 }
120 }
121