PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.5.1
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.5.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-social-sharing.php

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

157 lines 4.2 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 Social Sharing.
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_Social_Sharing class.
19 *
20 * @since 1.2.0
21 */
22 class Campaign_Social_Sharing extends Base_Element {
23 /**
24 * Default networks (matches the block.json default).
25 *
26 * @since 1.2.0
27 */
28 private const DEFAULT_NETWORKS = [ 'twitter', 'facebook', 'linkedin', 'pinterest', 'bluesky' ];
29
30 /**
31 * All valid network keys (must match the control options and the block's
32 * get_networks()).
33 *
34 * @since 1.2.0
35 */
36 private const VALID_NETWORKS = [ 'twitter', 'facebook', 'linkedin', 'pinterest', 'mastodon', 'threads', 'bluesky' ];
37
38 /**
39 * Element name.
40 *
41 * @since 1.2.0
42 * @var string
43 */
44 public $name = 'suredonation-campaign-social-sharing';
45
46 /**
47 * Element icon.
48 *
49 * @since 1.2.0
50 * @var string
51 */
52 public $icon = 'ti-share';
53
54 /**
55 * Element label shown in the builder panel.
56 *
57 * @since 1.2.0
58 * @return string
59 */
60 public function get_label() {
61 return esc_html__( 'Campaign Social Sharing', 'suredonation' );
62 }
63
64 /**
65 * {@inheritDoc}
66 */
67 public function get_keywords() {
68 return array_merge( parent::get_keywords(), [ 'social', 'share', 'sharing' ] );
69 }
70
71 /**
72 * Register the element controls.
73 *
74 * @since 1.2.0
75 * @return void
76 */
77 public function set_controls() {
78 $this->add_campaign_control();
79
80 $this->controls['headline'] = [
81 'tab' => 'content',
82 'label' => esc_html__( 'Headline', 'suredonation' ),
83 'type' => 'text',
84 'default' => esc_html__( 'Share:', 'suredonation' ),
85 ];
86
87 $this->controls['networks'] = [
88 'tab' => 'content',
89 'label' => esc_html__( 'Social networks', 'suredonation' ),
90 'type' => 'select',
91 'multiple' => true,
92 'options' => [
93 'twitter' => esc_html__( 'Twitter / X', 'suredonation' ),
94 'facebook' => esc_html__( 'Facebook', 'suredonation' ),
95 'linkedin' => esc_html__( 'LinkedIn', 'suredonation' ),
96 'pinterest' => esc_html__( 'Pinterest', 'suredonation' ),
97 'mastodon' => esc_html__( 'Mastodon', 'suredonation' ),
98 'threads' => esc_html__( 'Threads', 'suredonation' ),
99 'bluesky' => esc_html__( 'Bluesky', 'suredonation' ),
100 ],
101 'default' => self::DEFAULT_NETWORKS,
102 ];
103
104 // Inverted (default-off) control — see Base_Element::setting_bool():
105 // an untouched default-true checkbox would otherwise flip the block's
106 // Gutenberg default. Absent = links open in a new tab.
107 $this->controls['openInSameTab'] = [
108 'tab' => 'content',
109 'label' => esc_html__( 'Open Links In Same Tab', 'suredonation' ),
110 'type' => 'checkbox',
111 ];
112
113 $this->controls['contentAlign'] = [
114 'tab' => 'content',
115 'label' => esc_html__( 'Alignment', 'suredonation' ),
116 'type' => 'select',
117 'default' => 'left',
118 'options' => [
119 'left' => esc_html__( 'Left', 'suredonation' ),
120 'center' => esc_html__( 'Center', 'suredonation' ),
121 'right' => esc_html__( 'Right', 'suredonation' ),
122 ],
123 ];
124 }
125
126 /**
127 * {@inheritDoc}
128 */
129 protected function block_name() {
130 return 'suredonation/campaign-social-sharing';
131 }
132
133 /**
134 * Map the element settings to the block attributes.
135 *
136 * @since 1.2.0
137 * @param array<string, mixed> $settings Element settings.
138 * @return array<string, mixed>
139 */
140 protected function get_block_attrs( $settings ) {
141 // Allowlist at the element level too (the block sink re-validates) —
142 // consistent with the statistic/contentAlign handling.
143 $networks = isset( $settings['networks'] ) && is_array( $settings['networks'] )
144 ? array_values( array_intersect( array_map( 'strval', $settings['networks'] ), self::VALID_NETWORKS ) )
145 : self::DEFAULT_NETWORKS;
146
147 $align = $this->setting_string( $settings, 'contentAlign', 'left' );
148
149 return [
150 'headline' => $this->setting_string( $settings, 'headline', __( 'Share:', 'suredonation' ) ),
151 'networks' => $networks,
152 'openInNewTab' => ! $this->setting_bool( $settings, 'openInSameTab' ),
153 'contentAlign' => in_array( $align, [ 'left', 'center', 'right' ], true ) ? $align : 'left',
154 ];
155 }
156 }
157