PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.2.1
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.2.1
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.1, at includes/Campaign/Elements/CampaignElements.php

635 lines 27.3 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' => 'Campaign Description',
66 'content' => "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).",
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' => 'Campaign Progress',
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 'defaultValue' => 'Campaign Progress',
179 ],
180 [
181 'key' => '_campaign_info',
182 'label' => __( 'Campaign Information', 'better-payment' ),
183 'type' => 'section_label',
184 ],
185 [
186 'key' => 'show_donated',
187 'label' => __( 'Show Donated', 'better-payment' ),
188 'type' => 'switch',
189 'defaultValue' => true,
190 ],
191 [
192 'key' => 'show_goal',
193 'label' => __( 'Show Goal', 'better-payment' ),
194 'type' => 'switch',
195 'defaultValue' => true,
196 ],
197 [
198 'key' => 'round_amounts',
199 'label' => __( 'Round Amounts', 'better-payment' ),
200 'type' => 'toggle',
201 'defaultValue' => false,
202 ],
203 [
204 'key' => 'donate_label',
205 'label' => __( 'Donate Label:', 'better-payment' ),
206 'type' => 'text',
207 'defaultValue' => 'Donated:',
208 ],
209 [
210 'key' => 'goal_label',
211 'label' => __( 'Goal Label:', 'better-payment' ),
212 'type' => 'text',
213 'defaultValue' => 'Goal:',
214 ],
215 [
216 'key' => 'width',
217 'label' => __( 'Width', 'better-payment' ),
218 'type' => 'range',
219 'min' => 10,
220 'max' => 100,
221 'step' => 1,
222 'unit' => '%',
223 'defaultValue' => 100,
224 'info' => __( 'Controls the width of the progress bar relative to its container.', 'better-payment' ),
225 ],
226 [
227 'key' => 'align',
228 'label' => __( 'Align', 'better-payment' ),
229 'type' => 'align',
230 'defaultValue' => 'left',
231 ],
232 ],
233 ] );
234
235 ElementRegistry::register( 'campaign_summary', [
236 'label' => __( 'Campaign Summary', 'better-payment' ),
237 'icon' => 'info',
238 'defaultSettings' => [
239 'headline' => 'Campaign Summary',
240 'show_raised' => true,
241 'show_donors' => true,
242 'show_percent' => true,
243 'show_days' => true,
244 'width' => 100,
245 'align' => 'left',
246 ],
247 'settingsSchema' => [
248 [
249 'key' => 'headline',
250 'label' => __( 'Headline', 'better-payment' ),
251 'type' => 'text',
252 'placeholder' => '',
253 'defaultValue' => 'Campaign Summary',
254 ],
255 [
256 'key' => 'choose_label',
257 'label' => __( 'Choose what information to show:', 'better-payment' ),
258 'type' => 'section_label',
259 ],
260 [
261 'key' => 'summary_note',
262 'label' => __( 'Note: All enabled items are always shown. Amount Donated and Number of Donors update as donations come in. Percent Raised shows 0% until a campaign goal is set, and Time Remaining shows 0 days left until an end date is set. Save and refresh the builder to see updated values.', 'better-payment' ),
263 'type' => 'note',
264 ],
265 [
266 'key' => 'show_raised',
267 'label' => __( 'Amount Donated', 'better-payment' ),
268 'type' => 'toggle',
269 ],
270 [
271 'key' => 'show_donors',
272 'label' => __( 'Number of Donors', 'better-payment' ),
273 'type' => 'toggle',
274 ],
275 [
276 'key' => 'show_percent',
277 'label' => __( 'Percent Raised', 'better-payment' ),
278 'type' => 'toggle',
279 ],
280 [
281 'key' => 'show_days',
282 'label' => __( 'Time Remaining', 'better-payment' ),
283 'type' => 'toggle',
284 ],
285 [
286 'key' => 'width',
287 'label' => __( 'Width', 'better-payment' ),
288 'type' => 'range',
289 'min' => 10,
290 'max' => 100,
291 'unit' => '%',
292 ],
293 [
294 'key' => 'align',
295 'label' => __( 'Align', 'better-payment' ),
296 'type' => 'align',
297 ],
298 ],
299 ] );
300
301 ElementRegistry::register( 'donation_form', [
302 'label' => __( 'Donate Button', 'better-payment' ),
303 'icon' => 'heart',
304 'defaultSettings' => [
305 'button_label' => 'Donate Now',
306 'button_color' => '',
307 'url' => '#',
308 'open_new_tab' => false,
309 'width' => 100,
310 'align' => 'center',
311 ],
312 'settingsSchema' => [
313 [
314 'key' => 'button_label',
315 'label' => __( 'Button Label', 'better-payment' ),
316 'type' => 'text',
317 'placeholder' => __( 'Donate Now', 'better-payment' ),
318 'defaultValue' => 'Donate Now',
319 ],
320 [
321 'key' => 'url',
322 'label' => __( 'Payment Form Page URL', 'better-payment' ),
323 'type' => 'url',
324 'placeholder' => 'https://',
325 'defaultValue' => '#',
326 'info' => __( 'Link to the page containing your donation form. Overrides the Donation Page set in General Settings.', 'better-payment' ),
327 ],
328 [
329 'key' => 'open_new_tab',
330 'label' => __( 'Open Links In New Tab', 'better-payment' ),
331 'type' => 'switch',
332 'defaultValue' => false,
333 ],
334 [
335 'key' => 'width',
336 'label' => __( 'Width', 'better-payment' ),
337 'type' => 'range',
338 'min' => 10,
339 'max' => 100,
340 'step' => 1,
341 'defaultValue' => 100,
342 ],
343 [
344 'key' => 'align',
345 'label' => __( 'Align', 'better-payment' ),
346 'type' => 'align',
347 'defaultValue' => 'center',
348 ],
349 ],
350 ] );
351
352 // Build WP users list for the Campaign Creator select.
353 $wp_users = get_users( [ 'fields' => [ 'ID', 'display_name', 'user_email' ] ] );
354 $creator_options = array_values( array_map( function ( $u ) {
355 return [
356 'value' => (int) $u->ID,
357 'label' => $u->display_name,
358 'avatar_url' => get_avatar_url( $u->user_email, [ 'size' => 48, 'default' => 'mysteryman' ] ),
359 ];
360 }, $wp_users ) );
361
362 ElementRegistry::register( 'organizer', [
363 'label' => __( 'Organizer', 'better-payment' ),
364 'icon' => 'admin-users',
365 'defaultSettings' => [
366 'creator_user_id' => get_current_user_id(),
367 'role_title' => 'Organizer',
368 'description' => '',
369 'width' => 100,
370 'align' => 'left',
371 ],
372 'settingsSchema' => [
373 [
374 'key' => 'role_title',
375 'label' => __( 'Role or Title', 'better-payment' ),
376 'type' => 'text',
377 'placeholder' => 'Organizer',
378 'defaultValue' => 'Organizer',
379 'info' => __( 'Shown beneath the creator\'s name (e.g. Organizer, Founder).', 'better-payment' ),
380 ],
381 [
382 'key' => 'creator_user_id',
383 'label' => __( 'Campaign Creator', 'better-payment' ),
384 'type' => 'select',
385 'options' => $creator_options,
386 ],
387 [
388 'key' => 'description',
389 'label' => __( 'Organizer Description', 'better-payment' ),
390 'type' => 'rich_text',
391 'info' => __( 'Brief bio or message shown beneath the creator\'s name.', 'better-payment' ),
392 ],
393 [
394 'key' => 'width',
395 'label' => __( 'Width', 'better-payment' ),
396 'type' => 'range',
397 'min' => 10,
398 'max' => 100,
399 'step' => 1,
400 'defaultValue' => 100,
401 'info' => __( 'Width of the organizer block as a percentage.', 'better-payment' ),
402 ],
403 [
404 'key' => 'align',
405 'label' => __( 'Align', 'better-payment' ),
406 'type' => 'align',
407 'defaultValue' => 'left',
408 ],
409 ],
410 ] );
411
412 ElementRegistry::register( 'donate_amount', [
413 'label' => __( 'Donate Amount', 'better-payment' ),
414 'icon' => 'money-alt',
415 'defaultSettings' => [
416 'headline' => 'Donate Amount',
417 ],
418 'settingsSchema' => [
419 [
420 'key' => 'headline',
421 'label' => __( 'Headline', 'better-payment' ),
422 'type' => 'text',
423 'placeholder' => __( 'Headline', 'better-payment' ),
424 'defaultValue' => 'Donate Amount',
425 'info' => __( 'Optional heading shown above the donation amounts.', 'better-payment' ),
426 ],
427 [
428 'key' => 'bpc_minimum_amount',
429 'label' => __( 'Minimum Donation Amount', 'better-payment' ),
430 'type' => 'currency',
431 'metaKey' => 'bpc_minimum_amount',
432 'info' => __( 'Leave empty to allow no restrictions on how small the donation can be.', 'better-payment' ),
433 ],
434 [
435 'key' => 'bpc_suggested_amounts',
436 'label' => __( 'Suggested Donation Amounts', 'better-payment' ),
437 'type' => 'suggested_amounts',
438 'metaKey' => 'bpc_suggested_amounts',
439 ],
440 [
441 'key' => 'bpc_allow_custom_amount',
442 'label' => __( 'Allow Custom Amount', 'better-payment' ),
443 'type' => 'switch',
444 'metaKey' => 'bpc_allow_custom_amount',
445 'defaultValue' => true,
446 ],
447 ],
448 ] );
449
450 ElementRegistry::register( 'social_sharing', [
451 'label' => __( 'Social Sharing', 'better-payment' ),
452 'icon' => 'share',
453 'defaultSettings' => [
454 'headline' => 'Share Now',
455 'twitter' => true,
456 'facebook' => true,
457 'linkedin' => true,
458 'pinterest' => true,
459 'mastodon' => true,
460 'threads' => true,
461 'bluesky' => true,
462 'open_new_tab' => true,
463 'align' => 'left',
464 ],
465 'settingsSchema' => [
466 [
467 'key' => 'headline',
468 'label' => __( 'Headline', 'better-payment' ),
469 'type' => 'text',
470 'placeholder' => __( 'Headline', 'better-payment' ),
471 'defaultValue' => 'Share Now',
472 ],
473 [
474 'key' => '_networks',
475 'label' => __( 'Choose your social network(s):', 'better-payment' ),
476 'type' => 'section_label',
477 ],
478 [
479 'key' => 'twitter',
480 'label' => __( 'Twitter / X', 'better-payment' ),
481 'type' => 'toggle',
482 'defaultValue' => true,
483 ],
484 [
485 'key' => 'facebook',
486 'label' => __( 'Facebook', 'better-payment' ),
487 'type' => 'toggle',
488 'defaultValue' => true,
489 ],
490 [
491 'key' => 'linkedin',
492 'label' => __( 'LinkedIn', 'better-payment' ),
493 'type' => 'toggle',
494 'defaultValue' => true,
495 ],
496 [
497 'key' => 'pinterest',
498 'label' => __( 'Pinterest', 'better-payment' ),
499 'type' => 'toggle',
500 'defaultValue' => true,
501 ],
502 [
503 'key' => 'mastodon',
504 'label' => __( 'Mastodon', 'better-payment' ),
505 'type' => 'toggle',
506 'defaultValue' => true,
507 ],
508 [
509 'key' => 'threads',
510 'label' => __( 'Threads', 'better-payment' ),
511 'type' => 'toggle',
512 'defaultValue' => true,
513 ],
514 [
515 'key' => 'bluesky',
516 'label' => __( 'Bluesky', 'better-payment' ),
517 'type' => 'toggle',
518 'defaultValue' => true,
519 ],
520 [
521 'key' => 'open_new_tab',
522 'label' => __( 'Open Links In New Tab', 'better-payment' ),
523 'type' => 'switch',
524 'defaultValue' => true,
525 ],
526 [
527 'key' => 'align',
528 'label' => __( 'Align', 'better-payment' ),
529 'type' => 'align',
530 ],
531 ],
532 ] );
533
534 ElementRegistry::register( 'social_links', [
535 'label' => __( 'Social Links', 'better-payment' ),
536 'icon' => 'admin-links',
537 'defaultSettings' => [
538 'headline' => 'Follow Now',
539 'twitter' => 'https://twitter.com/',
540 'facebook' => 'https://facebook.com/',
541 'linkedin' => 'https://linkedin.com/',
542 'instagram' => '',
543 'tiktok' => '',
544 'pinterest' => '',
545 'youtube' => '',
546 'threads' => '',
547 'bluesky' => '',
548 'mastodon' => '',
549 'open_new_tab' => true,
550 'align' => 'left',
551 ],
552 'settingsSchema' => [
553 [
554 'key' => 'headline',
555 'label' => __( 'Headline', 'better-payment' ),
556 'type' => 'text',
557 'placeholder' => __( 'Headline', 'better-payment' ),
558 'defaultValue' => 'Follow Now',
559 ],
560 [
561 'key' => 'twitter',
562 'label' => __( 'Twitter / X URL', 'better-payment' ),
563 'type' => 'url',
564 'placeholder' => 'https://',
565 ],
566 [
567 'key' => 'facebook',
568 'label' => __( 'Facebook URL', 'better-payment' ),
569 'type' => 'url',
570 'placeholder' => 'https://',
571 ],
572 [
573 'key' => 'linkedin',
574 'label' => __( 'LinkedIn URL', 'better-payment' ),
575 'type' => 'url',
576 'placeholder' => 'https://',
577 ],
578 [
579 'key' => 'instagram',
580 'label' => __( 'Instagram URL', 'better-payment' ),
581 'type' => 'url',
582 'placeholder' => 'https://',
583 ],
584 [
585 'key' => 'tiktok',
586 'label' => __( 'TikTok URL', 'better-payment' ),
587 'type' => 'url',
588 'placeholder' => 'https://',
589 ],
590 [
591 'key' => 'pinterest',
592 'label' => __( 'Pinterest URL', 'better-payment' ),
593 'type' => 'url',
594 'placeholder' => 'https://',
595 ],
596 [
597 'key' => 'youtube',
598 'label' => __( 'YouTube URL', 'better-payment' ),
599 'type' => 'url',
600 'placeholder' => 'https://',
601 ],
602 [
603 'key' => 'threads',
604 'label' => __( 'Threads URL', 'better-payment' ),
605 'type' => 'url',
606 'placeholder' => 'https://',
607 ],
608 [
609 'key' => 'bluesky',
610 'label' => __( 'Bluesky URL', 'better-payment' ),
611 'type' => 'url',
612 'placeholder' => 'https://',
613 ],
614 [
615 'key' => 'mastodon',
616 'label' => __( 'Mastodon URL', 'better-payment' ),
617 'type' => 'url',
618 'placeholder' => 'https://',
619 ],
620 [
621 'key' => 'open_new_tab',
622 'label' => __( 'Open Links In New Tab', 'better-payment' ),
623 'type' => 'switch',
624 'defaultValue' => true,
625 ],
626 [
627 'key' => 'align',
628 'label' => __( 'Align', 'better-payment' ),
629 'type' => 'align',
630 ],
631 ],
632 ] );
633 }
634 }
635