PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.2.0
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.2.0
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 All 66 releases
better-payment / includes / Campaign / Elements / CampaignElements.php

CampaignElements.php in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 2.2.0, at includes/Campaign/Elements/CampaignElements.php

624 lines 25.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Better_Payment\Lite\Campaign\Elements;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Registers all built-in campaign element types into the ElementRegistry.
11 *
12 * Mirrors Fluent Forms' DefaultElements.php pattern: a structured PHP
13 * definition drives both the PHP renderer and the JS builder's settings panel.
14 *
15 * Each element schema shape:
16 * [
17 * 'type' => string, // unique key
18 * 'label' => string, // display name in builder
19 * 'icon' => string, // dashicons suffix (without 'dashicons-')
20 * 'defaultSettings' => array, // settings applied when element is dropped
21 * 'settingsSchema' => array, // controls shown in the right panel
22 * ]
23 *
24 * settingsSchema control shape:
25 * [
26 * 'key' => string, // settings key
27 * 'label' => string, // control label
28 * 'type' => string, // text | number | color | toggle | select | textarea
29 * 'placeholder' => string, // optional
30 * 'min' => int, // for number type
31 * 'max' => int, // for number type
32 * 'rows' => int, // for textarea type
33 * 'options' => array, // for select type: [['value'=>..., 'label'=>...], ...]
34 * ]
35 */
36 class CampaignElements {
37
38 public static function register_all(): void {
39
40 ElementRegistry::register( 'campaign_title', [
41 'label' => __( 'Campaign Title', 'better-payment' ),
42 'icon' => 'heading',
43 'defaultSettings' => [
44 'align' => 'left',
45 ],
46 'settingsSchema' => [
47 [
48 'key' => 'title',
49 'label' => __( 'Campaign Title', 'better-payment' ),
50 'type' => 'text',
51 'placeholder' => __( 'Campaign name', 'better-payment' ),
52 ],
53 [
54 'key' => 'align',
55 'label' => __( 'Align', 'better-payment' ),
56 'type' => 'align',
57 ],
58 ],
59 ] );
60
61 ElementRegistry::register( 'campaign_description', [
62 'label' => __( 'Campaign Description', 'better-payment' ),
63 'icon' => 'editor-paragraph',
64 'defaultSettings' => [
65 'headline' => '',
66 'content' => '',
67 'width' => 100,
68 'align' => 'left',
69 ],
70 'settingsSchema' => [
71 [
72 'key' => 'headline',
73 'label' => __( 'Headline', 'better-payment' ),
74 'type' => 'text',
75 'placeholder' => __( 'Headline', 'better-payment' ),
76 ],
77 [
78 'key' => 'content',
79 'label' => __( 'Campaign Description', 'better-payment' ),
80 'type' => 'rich_text',
81 'info' => __( 'Supports bold, italic, underline, links, and lists.', 'better-payment' ),
82 ],
83 [
84 'key' => 'width',
85 'label' => __( 'Width', 'better-payment' ),
86 'type' => 'range',
87 'min' => 10,
88 'max' => 100,
89 'step' => 1,
90 'unit' => '%',
91 'defaultValue' => 100,
92 'info' => __( 'Content width as a percentage of its container.', 'better-payment' ),
93 ],
94 [
95 'key' => 'align',
96 'label' => __( 'Align', 'better-payment' ),
97 'type' => 'align',
98 ],
99 ],
100 ] );
101
102 ElementRegistry::register( 'photo', [
103 'label' => __( 'Photo', 'better-payment' ),
104 'icon' => 'format-image',
105 'defaultSettings' => [
106 'src' => '',
107 'src_id' => 0,
108 'src_sizes' => [],
109 'alt' => '',
110 'size' => 'full',
111 'width' => 100,
112 'align' => 'center',
113 ],
114 'settingsSchema' => [
115 [
116 'key' => 'src',
117 'label' => __( 'Choose Image', 'better-payment' ),
118 'type' => 'image_upload',
119 'info' => __( 'Paste an external image URL or select from the media library.', 'better-payment' ),
120 ],
121 [
122 'key' => 'alt',
123 'label' => __( 'ALT Text', 'better-payment' ),
124 'type' => 'text',
125 'placeholder' => __( 'Describe the image…', 'better-payment' ),
126 'info' => __( 'Describes the image for screen readers and when the image fails to load.', 'better-payment' ),
127 ],
128 [
129 'key' => 'size',
130 'label' => __( 'Image Resolution', 'better-payment' ),
131 'type' => 'select',
132 'defaultValue' => 'full',
133 'options' => [
134 [ 'value' => 'thumbnail', 'label' => __( 'Thumbnail (150×150)', 'better-payment' ) ],
135 [ 'value' => 'medium', 'label' => __( 'Medium (300×300)', 'better-payment' ) ],
136 [ 'value' => 'medium_large', 'label' => __( 'Medium Large (768×auto)', 'better-payment' ) ],
137 [ 'value' => 'large', 'label' => __( 'Large (1024×1024)', 'better-payment' ) ],
138 [ 'value' => 'full', 'label' => __( 'Full (Original)', 'better-payment' ) ],
139 ],
140 ],
141 [
142 'key' => 'width',
143 'label' => __( 'Width', 'better-payment' ),
144 'type' => 'range',
145 'min' => 10,
146 'max' => 100,
147 'step' => 1,
148 'unit' => '%',
149 'defaultValue' => 100,
150 'info' => __( 'Image width as a percentage of its container.', 'better-payment' ),
151 ],
152 [
153 'key' => 'align',
154 'label' => __( 'Align', 'better-payment' ),
155 'type' => 'align',
156 ],
157 ],
158 ] );
159
160 ElementRegistry::register( 'progress_bar', [
161 'label' => __( 'Progress Bar', 'better-payment' ),
162 'icon' => 'chart-bar',
163 'defaultSettings' => [
164 'headline' => '',
165 'show_donated' => true,
166 'show_goal' => true,
167 'round_amounts' => false,
168 'donate_label' => 'Donated:',
169 'goal_label' => 'Goal:',
170 'width' => 100,
171 'align' => 'left',
172 ],
173 'settingsSchema' => [
174 [
175 'key' => 'headline',
176 'label' => __( 'Headline', 'better-payment' ),
177 'type' => 'text',
178 ],
179 [
180 'key' => '_campaign_info',
181 'label' => __( 'Campaign Information', 'better-payment' ),
182 'type' => 'section_label',
183 ],
184 [
185 'key' => 'show_donated',
186 'label' => __( 'Show Donated', 'better-payment' ),
187 'type' => 'switch',
188 'defaultValue' => true,
189 ],
190 [
191 'key' => 'show_goal',
192 'label' => __( 'Show Goal', 'better-payment' ),
193 'type' => 'switch',
194 'defaultValue' => true,
195 ],
196 [
197 'key' => 'round_amounts',
198 'label' => __( 'Round Amounts', 'better-payment' ),
199 'type' => 'toggle',
200 'defaultValue' => false,
201 ],
202 [
203 'key' => 'donate_label',
204 'label' => __( 'Donate Label:', 'better-payment' ),
205 'type' => 'text',
206 'defaultValue' => 'Donated:',
207 ],
208 [
209 'key' => 'goal_label',
210 'label' => __( 'Goal Label:', 'better-payment' ),
211 'type' => 'text',
212 'defaultValue' => 'Goal:',
213 ],
214 [
215 'key' => 'width',
216 'label' => __( 'Width', 'better-payment' ),
217 'type' => 'range',
218 'min' => 10,
219 'max' => 100,
220 'step' => 1,
221 'unit' => '%',
222 'defaultValue' => 100,
223 'info' => __( 'Controls the width of the progress bar relative to its container.', 'better-payment' ),
224 ],
225 [
226 'key' => 'align',
227 'label' => __( 'Align', 'better-payment' ),
228 'type' => 'align',
229 'defaultValue' => 'left',
230 ],
231 ],
232 ] );
233
234 ElementRegistry::register( 'campaign_summary', [
235 'label' => __( 'Campaign Summary', 'better-payment' ),
236 'icon' => 'info',
237 'defaultSettings' => [
238 'headline' => '',
239 'show_raised' => true,
240 'show_donors' => true,
241 'show_percent' => true,
242 'show_days' => true,
243 'width' => 100,
244 'align' => 'left',
245 ],
246 'settingsSchema' => [
247 [
248 'key' => 'headline',
249 'label' => __( 'Headline', 'better-payment' ),
250 'type' => 'text',
251 'placeholder' => '',
252 ],
253 [
254 'key' => 'choose_label',
255 'label' => __( 'Choose what information to show:', 'better-payment' ),
256 'type' => 'section_label',
257 ],
258 [
259 'key' => 'summary_note',
260 'label' => __( 'Note: Some items might not be visible or enabled depending on campaign goal and date settings. Save and refresh the builder to see updated values.', 'better-payment' ),
261 'type' => 'note',
262 ],
263 [
264 'key' => 'show_raised',
265 'label' => __( 'Amount Donated', 'better-payment' ),
266 'type' => 'toggle',
267 ],
268 [
269 'key' => 'show_donors',
270 'label' => __( 'Number of Donors', 'better-payment' ),
271 'type' => 'toggle',
272 ],
273 [
274 'key' => 'show_percent',
275 'label' => __( 'Percent Raised', 'better-payment' ),
276 'type' => 'toggle',
277 ],
278 [
279 'key' => 'show_days',
280 'label' => __( 'Time Remaining', 'better-payment' ),
281 'type' => 'toggle',
282 ],
283 [
284 'key' => 'width',
285 'label' => __( 'Width', 'better-payment' ),
286 'type' => 'range',
287 'min' => 10,
288 'max' => 100,
289 'unit' => '%',
290 ],
291 [
292 'key' => 'align',
293 'label' => __( 'Align', 'better-payment' ),
294 'type' => 'align',
295 ],
296 ],
297 ] );
298
299 ElementRegistry::register( 'donation_form', [
300 'label' => __( 'Donate Button', 'better-payment' ),
301 'icon' => 'heart',
302 'defaultSettings' => [
303 'button_label' => 'Donate Now',
304 'button_color' => '',
305 'url' => '',
306 'open_new_tab' => false,
307 'width' => 100,
308 'align' => 'center',
309 ],
310 'settingsSchema' => [
311 [
312 'key' => 'button_label',
313 'label' => __( 'Button Label', 'better-payment' ),
314 'type' => 'text',
315 'placeholder' => __( 'Donate Now', 'better-payment' ),
316 'defaultValue' => 'Donate Now',
317 ],
318 [
319 'key' => 'url',
320 'label' => __( 'Payment Form Page URL', 'better-payment' ),
321 'type' => 'url',
322 'placeholder' => 'https://',
323 'info' => __( 'Link to the page containing your donation form. Overrides the Donation Page set in General Settings.', 'better-payment' ),
324 ],
325 [
326 'key' => 'open_new_tab',
327 'label' => __( 'Open Links In New Tab', 'better-payment' ),
328 'type' => 'switch',
329 'defaultValue' => false,
330 ],
331 [
332 'key' => 'width',
333 'label' => __( 'Width', 'better-payment' ),
334 'type' => 'range',
335 'min' => 10,
336 'max' => 100,
337 'step' => 1,
338 'defaultValue' => 100,
339 ],
340 [
341 'key' => 'align',
342 'label' => __( 'Align', 'better-payment' ),
343 'type' => 'align',
344 'defaultValue' => 'center',
345 ],
346 ],
347 ] );
348
349 // Build WP users list for the Campaign Creator select.
350 $wp_users = get_users( [ 'fields' => [ 'ID', 'display_name', 'user_email' ] ] );
351 $creator_options = array_values( array_map( function ( $u ) {
352 return [
353 'value' => (int) $u->ID,
354 'label' => $u->display_name,
355 'avatar_url' => get_avatar_url( $u->user_email, [ 'size' => 48, 'default' => 'mysteryman' ] ),
356 ];
357 }, $wp_users ) );
358
359 ElementRegistry::register( 'organizer', [
360 'label' => __( 'Organizer', 'better-payment' ),
361 'icon' => 'admin-users',
362 'defaultSettings' => [
363 'creator_user_id' => get_current_user_id(),
364 'role_title' => 'Organizer',
365 'description' => '',
366 'width' => 100,
367 'align' => 'left',
368 ],
369 'settingsSchema' => [
370 [
371 'key' => 'role_title',
372 'label' => __( 'Role or Title', 'better-payment' ),
373 'type' => 'text',
374 'placeholder' => 'Organizer',
375 'defaultValue' => 'Organizer',
376 'info' => __( 'Shown beneath the creator\'s name (e.g. Organizer, Founder).', 'better-payment' ),
377 ],
378 [
379 'key' => 'creator_user_id',
380 'label' => __( 'Campaign Creator', 'better-payment' ),
381 'type' => 'select',
382 'options' => $creator_options,
383 ],
384 [
385 'key' => 'description',
386 'label' => __( 'Organizer Description', 'better-payment' ),
387 'type' => 'rich_text',
388 'info' => __( 'Brief bio or message shown beneath the creator\'s name.', 'better-payment' ),
389 ],
390 [
391 'key' => 'width',
392 'label' => __( 'Width', 'better-payment' ),
393 'type' => 'range',
394 'min' => 10,
395 'max' => 100,
396 'step' => 1,
397 'defaultValue' => 100,
398 'info' => __( 'Width of the organizer block as a percentage.', 'better-payment' ),
399 ],
400 [
401 'key' => 'align',
402 'label' => __( 'Align', 'better-payment' ),
403 'type' => 'align',
404 'defaultValue' => 'left',
405 ],
406 ],
407 ] );
408
409 ElementRegistry::register( 'donate_amount', [
410 'label' => __( 'Donate Amount', 'better-payment' ),
411 'icon' => 'money-alt',
412 'defaultSettings' => [
413 'headline' => '',
414 ],
415 'settingsSchema' => [
416 [
417 'key' => 'headline',
418 'label' => __( 'Headline', 'better-payment' ),
419 'type' => 'text',
420 'placeholder' => __( 'Headline', 'better-payment' ),
421 'info' => __( 'Optional heading shown above the donation amounts.', 'better-payment' ),
422 ],
423 [
424 'key' => 'bpc_suggested_amounts',
425 'label' => __( 'Suggested Donation Amounts', 'better-payment' ),
426 'type' => 'suggested_amounts',
427 'metaKey' => 'bpc_suggested_amounts',
428 ],
429 [
430 'key' => 'bpc_allow_custom_amount',
431 'label' => __( 'Allow Custom Donations', 'better-payment' ),
432 'type' => 'switch',
433 'metaKey' => 'bpc_allow_custom_amount',
434 'defaultValue' => true,
435 ],
436 ],
437 ] );
438
439 ElementRegistry::register( 'social_sharing', [
440 'label' => __( 'Social Sharing', 'better-payment' ),
441 'icon' => 'share',
442 'defaultSettings' => [
443 'headline' => 'Share Now',
444 'twitter' => true,
445 'facebook' => true,
446 'linkedin' => true,
447 'pinterest' => true,
448 'mastodon' => true,
449 'threads' => true,
450 'bluesky' => true,
451 'open_new_tab' => true,
452 'align' => 'left',
453 ],
454 'settingsSchema' => [
455 [
456 'key' => 'headline',
457 'label' => __( 'Headline', 'better-payment' ),
458 'type' => 'text',
459 'placeholder' => __( 'Headline', 'better-payment' ),
460 'defaultValue' => 'Share Now',
461 ],
462 [
463 'key' => '_networks',
464 'label' => __( 'Choose your social network(s):', 'better-payment' ),
465 'type' => 'section_label',
466 ],
467 [
468 'key' => 'twitter',
469 'label' => __( 'Twitter / X', 'better-payment' ),
470 'type' => 'toggle',
471 'defaultValue' => true,
472 ],
473 [
474 'key' => 'facebook',
475 'label' => __( 'Facebook', 'better-payment' ),
476 'type' => 'toggle',
477 'defaultValue' => true,
478 ],
479 [
480 'key' => 'linkedin',
481 'label' => __( 'LinkedIn', 'better-payment' ),
482 'type' => 'toggle',
483 'defaultValue' => true,
484 ],
485 [
486 'key' => 'pinterest',
487 'label' => __( 'Pinterest', 'better-payment' ),
488 'type' => 'toggle',
489 'defaultValue' => true,
490 ],
491 [
492 'key' => 'mastodon',
493 'label' => __( 'Mastodon', 'better-payment' ),
494 'type' => 'toggle',
495 'defaultValue' => true,
496 ],
497 [
498 'key' => 'threads',
499 'label' => __( 'Threads', 'better-payment' ),
500 'type' => 'toggle',
501 'defaultValue' => true,
502 ],
503 [
504 'key' => 'bluesky',
505 'label' => __( 'Bluesky', 'better-payment' ),
506 'type' => 'toggle',
507 'defaultValue' => true,
508 ],
509 [
510 'key' => 'open_new_tab',
511 'label' => __( 'Open Links In New Tab', 'better-payment' ),
512 'type' => 'switch',
513 'defaultValue' => true,
514 ],
515 [
516 'key' => 'align',
517 'label' => __( 'Align', 'better-payment' ),
518 'type' => 'align',
519 ],
520 ],
521 ] );
522
523 ElementRegistry::register( 'social_links', [
524 'label' => __( 'Social Links', 'better-payment' ),
525 'icon' => 'admin-links',
526 'defaultSettings' => [
527 'headline' => 'Follow Now',
528 'twitter' => 'https://twitter.com/',
529 'facebook' => 'https://facebook.com/',
530 'linkedin' => 'https://linkedin.com/',
531 'instagram' => '',
532 'tiktok' => '',
533 'pinterest' => '',
534 'youtube' => '',
535 'threads' => '',
536 'bluesky' => '',
537 'mastodon' => '',
538 'open_new_tab' => true,
539 'align' => 'left',
540 ],
541 'settingsSchema' => [
542 [
543 'key' => 'headline',
544 'label' => __( 'Headline', 'better-payment' ),
545 'type' => 'text',
546 'placeholder' => __( 'Headline', 'better-payment' ),
547 'defaultValue' => 'Follow Now',
548 ],
549 [
550 'key' => 'twitter',
551 'label' => __( 'Twitter / X URL', 'better-payment' ),
552 'type' => 'url',
553 'placeholder' => 'https://',
554 ],
555 [
556 'key' => 'facebook',
557 'label' => __( 'Facebook URL', 'better-payment' ),
558 'type' => 'url',
559 'placeholder' => 'https://',
560 ],
561 [
562 'key' => 'linkedin',
563 'label' => __( 'LinkedIn URL', 'better-payment' ),
564 'type' => 'url',
565 'placeholder' => 'https://',
566 ],
567 [
568 'key' => 'instagram',
569 'label' => __( 'Instagram URL', 'better-payment' ),
570 'type' => 'url',
571 'placeholder' => 'https://',
572 ],
573 [
574 'key' => 'tiktok',
575 'label' => __( 'TikTok URL', 'better-payment' ),
576 'type' => 'url',
577 'placeholder' => 'https://',
578 ],
579 [
580 'key' => 'pinterest',
581 'label' => __( 'Pinterest URL', 'better-payment' ),
582 'type' => 'url',
583 'placeholder' => 'https://',
584 ],
585 [
586 'key' => 'youtube',
587 'label' => __( 'YouTube URL', 'better-payment' ),
588 'type' => 'url',
589 'placeholder' => 'https://',
590 ],
591 [
592 'key' => 'threads',
593 'label' => __( 'Threads URL', 'better-payment' ),
594 'type' => 'url',
595 'placeholder' => 'https://',
596 ],
597 [
598 'key' => 'bluesky',
599 'label' => __( 'Bluesky URL', 'better-payment' ),
600 'type' => 'url',
601 'placeholder' => 'https://',
602 ],
603 [
604 'key' => 'mastodon',
605 'label' => __( 'Mastodon URL', 'better-payment' ),
606 'type' => 'url',
607 'placeholder' => 'https://',
608 ],
609 [
610 'key' => 'open_new_tab',
611 'label' => __( 'Open Links In New Tab', 'better-payment' ),
612 'type' => 'switch',
613 'defaultValue' => true,
614 ],
615 [
616 'key' => 'align',
617 'label' => __( 'Align', 'better-payment' ),
618 'type' => 'align',
619 ],
620 ],
621 ] );
622 }
623 }
624