| 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 |
/** |
| 39 |
* Curated web-safe font-family options shared by typography-enabled elements. |
| 40 |
* Value is the full CSS font stack; empty value inherits the theme font. |
| 41 |
* |
| 42 |
* @return array<int, array{value: string, label: string}> |
| 43 |
*/ |
| 44 |
public static function font_family_options(): array { |
| 45 |
$families = [ |
| 46 |
'' => __( 'Default', 'better-payment' ), |
| 47 |
'Arial, Helvetica, sans-serif' => 'Arial', |
| 48 |
"'Arial Black', Gadget, sans-serif" => 'Arial Black', |
| 49 |
"'Comic Sans MS', cursive, sans-serif" => 'Comic Sans MS', |
| 50 |
"'Courier New', Courier, monospace" => 'Courier New', |
| 51 |
'Georgia, serif' => 'Georgia', |
| 52 |
"'Helvetica Neue', Helvetica, Arial, sans-serif" => 'Helvetica', |
| 53 |
'Impact, Charcoal, sans-serif' => 'Impact', |
| 54 |
"'Lucida Sans Unicode', 'Lucida Grande', sans-serif" => 'Lucida Sans', |
| 55 |
"'Palatino Linotype', 'Book Antiqua', Palatino, serif" => 'Palatino', |
| 56 |
'Tahoma, Geneva, sans-serif' => 'Tahoma', |
| 57 |
"'Times New Roman', Times, serif" => 'Times New Roman', |
| 58 |
"'Trebuchet MS', Helvetica, sans-serif" => 'Trebuchet MS', |
| 59 |
'Verdana, Geneva, sans-serif' => 'Verdana', |
| 60 |
]; |
| 61 |
|
| 62 |
$options = []; |
| 63 |
foreach ( $families as $value => $label ) { |
| 64 |
$options[] = [ 'value' => $value, 'label' => $label ]; |
| 65 |
} |
| 66 |
|
| 67 |
return $options; |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Font-style options shared by typography-enabled elements. |
| 72 |
* |
| 73 |
* @return array<int, array{value: string, label: string}> |
| 74 |
*/ |
| 75 |
public static function font_style_options(): array { |
| 76 |
return [ |
| 77 |
[ 'value' => '', 'label' => __( 'Default', 'better-payment' ) ], |
| 78 |
[ 'value' => 'normal', 'label' => __( 'Normal', 'better-payment' ) ], |
| 79 |
[ 'value' => 'italic', 'label' => __( 'Italic', 'better-payment' ) ], |
| 80 |
[ 'value' => 'oblique', 'label' => __( 'Oblique', 'better-payment' ) ], |
| 81 |
]; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Font-weight options shared by typography-enabled elements. |
| 86 |
* |
| 87 |
* @return array<int, array{value: string, label: string}> |
| 88 |
*/ |
| 89 |
public static function font_weight_options(): array { |
| 90 |
return [ |
| 91 |
[ 'value' => '', 'label' => __( 'Default', 'better-payment' ) ], |
| 92 |
[ 'value' => '100', 'label' => __( '100 (Thin)', 'better-payment' ) ], |
| 93 |
[ 'value' => '200', 'label' => __( '200 (Extra Light)', 'better-payment' ) ], |
| 94 |
[ 'value' => '300', 'label' => __( '300 (Light)', 'better-payment' ) ], |
| 95 |
[ 'value' => '400', 'label' => __( '400 (Normal)', 'better-payment' ) ], |
| 96 |
[ 'value' => '500', 'label' => __( '500 (Medium)', 'better-payment' ) ], |
| 97 |
[ 'value' => '600', 'label' => __( '600 (Semi Bold)', 'better-payment' ) ], |
| 98 |
[ 'value' => '700', 'label' => __( '700 (Bold)', 'better-payment' ) ], |
| 99 |
[ 'value' => '800', 'label' => __( '800 (Extra Bold)', 'better-payment' ) ], |
| 100 |
[ 'value' => '900', 'label' => __( '900 (Black)', 'better-payment' ) ], |
| 101 |
]; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Text-transform options shared by typography-enabled elements. |
| 106 |
* |
| 107 |
* @return array<int, array{value: string, label: string}> |
| 108 |
*/ |
| 109 |
public static function text_transform_options(): array { |
| 110 |
return [ |
| 111 |
[ 'value' => '', 'label' => __( 'Default', 'better-payment' ) ], |
| 112 |
[ 'value' => 'uppercase', 'label' => __( 'Uppercase', 'better-payment' ) ], |
| 113 |
[ 'value' => 'lowercase', 'label' => __( 'Lowercase', 'better-payment' ) ], |
| 114 |
[ 'value' => 'capitalize', 'label' => __( 'Capitalize', 'better-payment' ) ], |
| 115 |
[ 'value' => 'none', 'label' => __( 'Normal', 'better-payment' ) ], |
| 116 |
]; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Text-decoration options shared by typography-enabled elements. |
| 121 |
* |
| 122 |
* @return array<int, array{value: string, label: string}> |
| 123 |
*/ |
| 124 |
public static function text_decoration_options(): array { |
| 125 |
return [ |
| 126 |
[ 'value' => '', 'label' => __( 'Default', 'better-payment' ) ], |
| 127 |
[ 'value' => 'underline', 'label' => __( 'Underline', 'better-payment' ) ], |
| 128 |
[ 'value' => 'overline', 'label' => __( 'Overline', 'better-payment' ) ], |
| 129 |
[ 'value' => 'line-through', 'label' => __( 'Line Through', 'better-payment' ) ], |
| 130 |
[ 'value' => 'none', 'label' => __( 'None', 'better-payment' ) ], |
| 131 |
]; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Full typography control group shared by typography-enabled elements, |
| 136 |
* wrapped in a single collapsible "Typography" section. Mirrors Elementor's |
| 137 |
* Typography group (Family, Size, Weight, Transform, Style, Decoration, Line |
| 138 |
* Height, Letter Spacing, Word Spacing, Color). |
| 139 |
* |
| 140 |
* @param array $overrides Per-control overrides keyed by control key |
| 141 |
* (e.g. [ 'font_size' => [ 'defaultValue' => 32 ] ]). |
| 142 |
* Values are merged into that control descriptor. |
| 143 |
* @return array<int, array<string, mixed>> A single-element array holding the |
| 144 |
* collapsible section (type 'section') whose `children` |
| 145 |
* are the individual typography controls. |
| 146 |
*/ |
| 147 |
private static function typography_schema( array $overrides = [], string $prefix = '', string $section_label = '', string $section_key = '_typography' ): array { |
| 148 |
if ( '' === $section_label ) { |
| 149 |
$section_label = __( 'Typography', 'better-payment' ); |
| 150 |
} |
| 151 |
$children = [ |
| 152 |
[ |
| 153 |
'key' => 'font_family', |
| 154 |
'label' => __( 'Font Family', 'better-payment' ), |
| 155 |
'type' => 'select', |
| 156 |
'defaultValue' => '', |
| 157 |
'options' => self::font_family_options(), |
| 158 |
], |
| 159 |
[ |
| 160 |
'key' => 'font_size', |
| 161 |
'label' => __( 'Font Size (px)', 'better-payment' ), |
| 162 |
'type' => 'number', |
| 163 |
'min' => 8, |
| 164 |
'max' => 200, |
| 165 |
], |
| 166 |
[ |
| 167 |
'key' => 'font_weight', |
| 168 |
'label' => __( 'Font Weight', 'better-payment' ), |
| 169 |
'type' => 'select', |
| 170 |
'defaultValue' => '', |
| 171 |
'options' => self::font_weight_options(), |
| 172 |
], |
| 173 |
[ |
| 174 |
'key' => 'text_transform', |
| 175 |
'label' => __( 'Text Transform', 'better-payment' ), |
| 176 |
'type' => 'select', |
| 177 |
'defaultValue' => '', |
| 178 |
'options' => self::text_transform_options(), |
| 179 |
], |
| 180 |
[ |
| 181 |
'key' => 'font_style', |
| 182 |
'label' => __( 'Font Style', 'better-payment' ), |
| 183 |
'type' => 'select', |
| 184 |
'defaultValue' => '', |
| 185 |
'options' => self::font_style_options(), |
| 186 |
], |
| 187 |
[ |
| 188 |
'key' => 'text_decoration', |
| 189 |
'label' => __( 'Text Decoration', 'better-payment' ), |
| 190 |
'type' => 'select', |
| 191 |
'defaultValue' => '', |
| 192 |
'options' => self::text_decoration_options(), |
| 193 |
], |
| 194 |
[ |
| 195 |
'key' => 'line_height', |
| 196 |
'label' => __( 'Line Height (px)', 'better-payment' ), |
| 197 |
'type' => 'number', |
| 198 |
'min' => 0, |
| 199 |
'max' => 400, |
| 200 |
], |
| 201 |
[ |
| 202 |
'key' => 'letter_spacing', |
| 203 |
'label' => __( 'Letter Spacing (px)', 'better-payment' ), |
| 204 |
'type' => 'number', |
| 205 |
'min' => -20, |
| 206 |
'max' => 100, |
| 207 |
], |
| 208 |
[ |
| 209 |
'key' => 'word_spacing', |
| 210 |
'label' => __( 'Word Spacing (px)', 'better-payment' ), |
| 211 |
'type' => 'number', |
| 212 |
'min' => -20, |
| 213 |
'max' => 100, |
| 214 |
], |
| 215 |
[ |
| 216 |
'key' => 'color', |
| 217 |
'label' => __( 'Text Color', 'better-payment' ), |
| 218 |
'type' => 'color', |
| 219 |
], |
| 220 |
]; |
| 221 |
|
| 222 |
// Overrides are keyed by the BASE control key (e.g. 'font_size'), applied |
| 223 |
// before the prefix so callers don't need to know the prefix. |
| 224 |
if ( ! empty( $overrides ) ) { |
| 225 |
foreach ( $children as $i => $control ) { |
| 226 |
if ( isset( $overrides[ $control['key'] ] ) ) { |
| 227 |
$children[ $i ] = array_merge( $control, $overrides[ $control['key'] ] ); |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
// Prefix the control keys so a single element can carry more than one |
| 233 |
// independent typography set. The Description widget uses this to style |
| 234 |
// its title and body separately ('title_font_family' vs 'font_family'); |
| 235 |
// the renderer strips the prefix before applying the CSS. |
| 236 |
if ( '' !== $prefix ) { |
| 237 |
foreach ( $children as $i => $control ) { |
| 238 |
$children[ $i ]['key'] = $prefix . $control['key']; |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
// Return the controls wrapped in a single collapsible section (type => |
| 243 |
// 'section' with children) instead of a flat section_label + siblings. |
| 244 |
// The builder renders this as one expandable accordion (see |
| 245 |
// RightSidebar.js CollapsibleSection). |
| 246 |
return [ |
| 247 |
[ |
| 248 |
'key' => $section_key, |
| 249 |
'label' => $section_label, |
| 250 |
'type' => 'section', |
| 251 |
'collapsible' => true, |
| 252 |
'collapsed' => true, |
| 253 |
'children' => $children, |
| 254 |
], |
| 255 |
]; |
| 256 |
} |
| 257 |
|
| 258 |
public static function register_all(): void { |
| 259 |
|
| 260 |
ElementRegistry::register( 'campaign_title', [ |
| 261 |
'label' => __( 'Campaign Title', 'better-payment' ), |
| 262 |
'icon' => 'heading', |
| 263 |
// Typography keys are intentionally NOT seeded here — their absence is |
| 264 |
// how the renderer distinguishes a user override (emitted with |
| 265 |
// !important to beat template styles) from the template default. |
| 266 |
'defaultSettings' => [ |
| 267 |
'align' => 'left', |
| 268 |
], |
| 269 |
'settingsSchema' => array_merge( |
| 270 |
[ |
| 271 |
[ |
| 272 |
'key' => 'title', |
| 273 |
'label' => __( 'Campaign Title', 'better-payment' ), |
| 274 |
'type' => 'text', |
| 275 |
'placeholder' => __( 'Campaign name', 'better-payment' ), |
| 276 |
], |
| 277 |
], |
| 278 |
self::typography_schema( [ |
| 279 |
'font_size' => [ 'defaultValue' => 32 ], |
| 280 |
'color' => [ 'defaultValue' => '#1a1a2e' ], |
| 281 |
] ), |
| 282 |
[ |
| 283 |
[ |
| 284 |
'key' => 'align', |
| 285 |
'label' => __( 'Align', 'better-payment' ), |
| 286 |
'type' => 'align', |
| 287 |
], |
| 288 |
] |
| 289 |
), |
| 290 |
] ); |
| 291 |
|
| 292 |
ElementRegistry::register( 'campaign_description', [ |
| 293 |
'label' => __( 'Campaign Description', 'better-payment' ), |
| 294 |
'icon' => 'editor-paragraph', |
| 295 |
// Typography keys are intentionally NOT seeded — their absence marks a |
| 296 |
// user override, which the renderer emits with !important so it wins |
| 297 |
// over template styles. |
| 298 |
'defaultSettings' => [ |
| 299 |
'headline' => 'Campaign Description', |
| 300 |
'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).", |
| 301 |
'width' => 100, |
| 302 |
'align' => 'left', |
| 303 |
], |
| 304 |
'settingsSchema' => array_merge( |
| 305 |
[ |
| 306 |
[ |
| 307 |
'key' => 'headline', |
| 308 |
'label' => __( 'Headline', 'better-payment' ), |
| 309 |
'type' => 'text', |
| 310 |
'placeholder' => __( 'Headline', 'better-payment' ), |
| 311 |
], |
| 312 |
], |
| 313 |
// Title Typography — styles the headline (h3) only. Uses `title_` |
| 314 |
// prefixed keys so it stays independent of the body typography. |
| 315 |
self::typography_schema( |
| 316 |
[ |
| 317 |
'font_size' => [ |
| 318 |
'info' => __( 'Leave empty to use the heading default size.', 'better-payment' ), |
| 319 |
], |
| 320 |
], |
| 321 |
'title_', |
| 322 |
__( 'Title Typography', 'better-payment' ), |
| 323 |
'_title_typography' |
| 324 |
), |
| 325 |
[ |
| 326 |
[ |
| 327 |
'key' => 'content', |
| 328 |
'label' => __( 'Campaign Description', 'better-payment' ), |
| 329 |
'type' => 'rich_text', |
| 330 |
'info' => __( 'Supports bold, italic, underline, links, and lists.', 'better-payment' ), |
| 331 |
], |
| 332 |
], |
| 333 |
// Description Typography — styles the body content. Keeps the base |
| 334 |
// (unprefixed) keys so previously-saved description typography |
| 335 |
// continues to apply to the content. |
| 336 |
self::typography_schema( |
| 337 |
[ |
| 338 |
'font_size' => [ |
| 339 |
'placeholder' => '16', |
| 340 |
'info' => __( 'Leave empty to use the template default size.', 'better-payment' ), |
| 341 |
], |
| 342 |
], |
| 343 |
'', |
| 344 |
__( 'Description Typography', 'better-payment' ), |
| 345 |
'_content_typography' |
| 346 |
), |
| 347 |
[ |
| 348 |
[ |
| 349 |
'key' => 'width', |
| 350 |
'label' => __( 'Width', 'better-payment' ), |
| 351 |
'type' => 'range', |
| 352 |
'min' => 10, |
| 353 |
'max' => 100, |
| 354 |
'step' => 1, |
| 355 |
'unit' => '%', |
| 356 |
'defaultValue' => 100, |
| 357 |
'info' => __( 'Content width as a percentage of its container.', 'better-payment' ), |
| 358 |
], |
| 359 |
[ |
| 360 |
'key' => 'align', |
| 361 |
'label' => __( 'Align', 'better-payment' ), |
| 362 |
'type' => 'align', |
| 363 |
], |
| 364 |
] |
| 365 |
), |
| 366 |
] ); |
| 367 |
|
| 368 |
ElementRegistry::register( 'photo', [ |
| 369 |
'label' => __( 'Photo', 'better-payment' ), |
| 370 |
'icon' => 'format-image', |
| 371 |
'defaultSettings' => [ |
| 372 |
'src' => '', |
| 373 |
'src_id' => 0, |
| 374 |
'src_sizes' => [], |
| 375 |
'alt' => '', |
| 376 |
'size' => 'full', |
| 377 |
'width' => 100, |
| 378 |
'align' => 'center', |
| 379 |
], |
| 380 |
'settingsSchema' => [ |
| 381 |
[ |
| 382 |
'key' => 'src', |
| 383 |
'label' => __( 'Choose Image', 'better-payment' ), |
| 384 |
'type' => 'image_upload', |
| 385 |
'info' => __( 'Paste an external image URL or select from the media library.', 'better-payment' ), |
| 386 |
], |
| 387 |
[ |
| 388 |
'key' => 'alt', |
| 389 |
'label' => __( 'ALT Text', 'better-payment' ), |
| 390 |
'type' => 'text', |
| 391 |
'placeholder' => __( 'Describe the image…', 'better-payment' ), |
| 392 |
'info' => __( 'Describes the image for screen readers and when the image fails to load.', 'better-payment' ), |
| 393 |
], |
| 394 |
[ |
| 395 |
'key' => 'size', |
| 396 |
'label' => __( 'Image Resolution', 'better-payment' ), |
| 397 |
'type' => 'select', |
| 398 |
'defaultValue' => 'full', |
| 399 |
'options' => [ |
| 400 |
[ 'value' => 'thumbnail', 'label' => __( 'Thumbnail (150×150)', 'better-payment' ) ], |
| 401 |
[ 'value' => 'medium', 'label' => __( 'Medium (300×300)', 'better-payment' ) ], |
| 402 |
[ 'value' => 'medium_large', 'label' => __( 'Medium Large (768×auto)', 'better-payment' ) ], |
| 403 |
[ 'value' => 'large', 'label' => __( 'Large (1024×1024)', 'better-payment' ) ], |
| 404 |
[ 'value' => 'full', 'label' => __( 'Full (Original)', 'better-payment' ) ], |
| 405 |
], |
| 406 |
], |
| 407 |
[ |
| 408 |
'key' => 'width', |
| 409 |
'label' => __( 'Width', 'better-payment' ), |
| 410 |
'type' => 'range', |
| 411 |
'min' => 10, |
| 412 |
'max' => 100, |
| 413 |
'step' => 1, |
| 414 |
'unit' => '%', |
| 415 |
'defaultValue' => 100, |
| 416 |
'info' => __( 'Image width as a percentage of its container.', 'better-payment' ), |
| 417 |
], |
| 418 |
[ |
| 419 |
'key' => 'align', |
| 420 |
'label' => __( 'Align', 'better-payment' ), |
| 421 |
'type' => 'align', |
| 422 |
], |
| 423 |
], |
| 424 |
] ); |
| 425 |
|
| 426 |
ElementRegistry::register( 'progress_bar', [ |
| 427 |
'label' => __( 'Progress Bar', 'better-payment' ), |
| 428 |
'icon' => 'chart-bar', |
| 429 |
'defaultSettings' => [ |
| 430 |
'headline' => 'Campaign Progress', |
| 431 |
'show_donated' => true, |
| 432 |
'show_goal' => true, |
| 433 |
'round_amounts' => false, |
| 434 |
'donate_label' => 'Donated:', |
| 435 |
'goal_label' => 'Goal:', |
| 436 |
'width' => 100, |
| 437 |
'align' => 'left', |
| 438 |
], |
| 439 |
'settingsSchema' => [ |
| 440 |
[ |
| 441 |
'key' => 'headline', |
| 442 |
'label' => __( 'Headline', 'better-payment' ), |
| 443 |
'type' => 'text', |
| 444 |
'defaultValue' => 'Campaign Progress', |
| 445 |
], |
| 446 |
[ |
| 447 |
'key' => '_campaign_info', |
| 448 |
'label' => __( 'Campaign Information', 'better-payment' ), |
| 449 |
'type' => 'section_label', |
| 450 |
], |
| 451 |
[ |
| 452 |
'key' => 'show_donated', |
| 453 |
'label' => __( 'Show Donated', 'better-payment' ), |
| 454 |
'type' => 'switch', |
| 455 |
'defaultValue' => true, |
| 456 |
], |
| 457 |
[ |
| 458 |
'key' => 'show_goal', |
| 459 |
'label' => __( 'Show Goal', 'better-payment' ), |
| 460 |
'type' => 'switch', |
| 461 |
'defaultValue' => true, |
| 462 |
], |
| 463 |
[ |
| 464 |
'key' => 'round_amounts', |
| 465 |
'label' => __( 'Round Amounts', 'better-payment' ), |
| 466 |
'type' => 'toggle', |
| 467 |
'defaultValue' => false, |
| 468 |
], |
| 469 |
[ |
| 470 |
'key' => 'donate_label', |
| 471 |
'label' => __( 'Donate Label:', 'better-payment' ), |
| 472 |
'type' => 'text', |
| 473 |
'defaultValue' => 'Donated:', |
| 474 |
], |
| 475 |
[ |
| 476 |
'key' => 'goal_label', |
| 477 |
'label' => __( 'Goal Label:', 'better-payment' ), |
| 478 |
'type' => 'text', |
| 479 |
'defaultValue' => 'Goal:', |
| 480 |
], |
| 481 |
[ |
| 482 |
'key' => 'width', |
| 483 |
'label' => __( 'Width', 'better-payment' ), |
| 484 |
'type' => 'range', |
| 485 |
'min' => 10, |
| 486 |
'max' => 100, |
| 487 |
'step' => 1, |
| 488 |
'unit' => '%', |
| 489 |
'defaultValue' => 100, |
| 490 |
'info' => __( 'Controls the width of the progress bar relative to its container.', 'better-payment' ), |
| 491 |
], |
| 492 |
[ |
| 493 |
'key' => 'align', |
| 494 |
'label' => __( 'Align', 'better-payment' ), |
| 495 |
'type' => 'align', |
| 496 |
'defaultValue' => 'left', |
| 497 |
], |
| 498 |
], |
| 499 |
] ); |
| 500 |
|
| 501 |
ElementRegistry::register( 'campaign_summary', [ |
| 502 |
'label' => __( 'Campaign Summary', 'better-payment' ), |
| 503 |
'icon' => 'info', |
| 504 |
'defaultSettings' => [ |
| 505 |
'headline' => 'Campaign Summary', |
| 506 |
'show_raised' => true, |
| 507 |
'show_donors' => true, |
| 508 |
'show_percent' => true, |
| 509 |
'show_days' => true, |
| 510 |
'width' => 100, |
| 511 |
'align' => 'left', |
| 512 |
], |
| 513 |
'settingsSchema' => [ |
| 514 |
[ |
| 515 |
'key' => 'headline', |
| 516 |
'label' => __( 'Headline', 'better-payment' ), |
| 517 |
'type' => 'text', |
| 518 |
'placeholder' => '', |
| 519 |
'defaultValue' => 'Campaign Summary', |
| 520 |
], |
| 521 |
[ |
| 522 |
'key' => 'choose_label', |
| 523 |
'label' => __( 'Choose what information to show:', 'better-payment' ), |
| 524 |
'type' => 'section_label', |
| 525 |
], |
| 526 |
[ |
| 527 |
'key' => 'summary_note', |
| 528 |
'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' ), |
| 529 |
'type' => 'note', |
| 530 |
], |
| 531 |
[ |
| 532 |
'key' => 'show_raised', |
| 533 |
'label' => __( 'Amount Donated', 'better-payment' ), |
| 534 |
'type' => 'toggle', |
| 535 |
], |
| 536 |
[ |
| 537 |
'key' => 'show_donors', |
| 538 |
'label' => __( 'Number of Donors', 'better-payment' ), |
| 539 |
'type' => 'toggle', |
| 540 |
], |
| 541 |
[ |
| 542 |
'key' => 'show_percent', |
| 543 |
'label' => __( 'Percent Raised', 'better-payment' ), |
| 544 |
'type' => 'toggle', |
| 545 |
], |
| 546 |
[ |
| 547 |
'key' => 'show_days', |
| 548 |
'label' => __( 'Time Remaining', 'better-payment' ), |
| 549 |
'type' => 'toggle', |
| 550 |
], |
| 551 |
[ |
| 552 |
'key' => 'width', |
| 553 |
'label' => __( 'Width', 'better-payment' ), |
| 554 |
'type' => 'range', |
| 555 |
'min' => 10, |
| 556 |
'max' => 100, |
| 557 |
'unit' => '%', |
| 558 |
], |
| 559 |
[ |
| 560 |
'key' => 'align', |
| 561 |
'label' => __( 'Align', 'better-payment' ), |
| 562 |
'type' => 'align', |
| 563 |
], |
| 564 |
], |
| 565 |
] ); |
| 566 |
|
| 567 |
ElementRegistry::register( 'donation_form', [ |
| 568 |
'label' => __( 'Donate Button', 'better-payment' ), |
| 569 |
'icon' => 'heart', |
| 570 |
'defaultSettings' => [ |
| 571 |
'button_label' => 'Donate Now', |
| 572 |
'button_color' => '', |
| 573 |
'url' => '#', |
| 574 |
'open_new_tab' => false, |
| 575 |
'width' => 100, |
| 576 |
'align' => 'center', |
| 577 |
], |
| 578 |
'settingsSchema' => [ |
| 579 |
[ |
| 580 |
'key' => 'button_label', |
| 581 |
'label' => __( 'Button Label', 'better-payment' ), |
| 582 |
'type' => 'text', |
| 583 |
'placeholder' => __( 'Donate Now', 'better-payment' ), |
| 584 |
'defaultValue' => 'Donate Now', |
| 585 |
], |
| 586 |
[ |
| 587 |
'key' => 'button_color', |
| 588 |
'label' => __( 'Button Color', 'better-payment' ), |
| 589 |
'type' => 'color', |
| 590 |
'info' => __( 'Leave empty to use the campaign primary color.', 'better-payment' ), |
| 591 |
], |
| 592 |
[ |
| 593 |
'key' => 'url', |
| 594 |
'label' => __( 'Payment Form Page URL', 'better-payment' ), |
| 595 |
'type' => 'url', |
| 596 |
'placeholder' => 'https://', |
| 597 |
'defaultValue' => '#', |
| 598 |
'info' => __( 'Link to the page containing your donation form. Overrides the Donation Page set in General Settings.', 'better-payment' ), |
| 599 |
], |
| 600 |
[ |
| 601 |
'key' => 'open_new_tab', |
| 602 |
'label' => __( 'Open Links In New Tab', 'better-payment' ), |
| 603 |
'type' => 'switch', |
| 604 |
'defaultValue' => false, |
| 605 |
], |
| 606 |
[ |
| 607 |
'key' => 'width', |
| 608 |
'label' => __( 'Width', 'better-payment' ), |
| 609 |
'type' => 'range', |
| 610 |
'min' => 10, |
| 611 |
'max' => 100, |
| 612 |
'step' => 1, |
| 613 |
'defaultValue' => 100, |
| 614 |
], |
| 615 |
[ |
| 616 |
'key' => 'align', |
| 617 |
'label' => __( 'Align', 'better-payment' ), |
| 618 |
'type' => 'align', |
| 619 |
'defaultValue' => 'center', |
| 620 |
], |
| 621 |
], |
| 622 |
] ); |
| 623 |
|
| 624 |
// Build WP users list for the Campaign Creator select. |
| 625 |
$wp_users = get_users( [ 'fields' => [ 'ID', 'display_name', 'user_email' ] ] ); |
| 626 |
$creator_options = array_values( array_map( function ( $u ) { |
| 627 |
return [ |
| 628 |
'value' => (int) $u->ID, |
| 629 |
'label' => $u->display_name, |
| 630 |
'avatar_url' => get_avatar_url( $u->user_email, [ 'size' => 48, 'default' => 'mysteryman' ] ), |
| 631 |
]; |
| 632 |
}, $wp_users ) ); |
| 633 |
|
| 634 |
ElementRegistry::register( 'organizer', [ |
| 635 |
'label' => __( 'Organizer', 'better-payment' ), |
| 636 |
'icon' => 'admin-users', |
| 637 |
'defaultSettings' => [ |
| 638 |
'creator_user_id' => get_current_user_id(), |
| 639 |
'role_title' => 'Organizer', |
| 640 |
'description' => '', |
| 641 |
'width' => 100, |
| 642 |
'align' => 'left', |
| 643 |
], |
| 644 |
'settingsSchema' => [ |
| 645 |
[ |
| 646 |
'key' => 'role_title', |
| 647 |
'label' => __( 'Role or Title', 'better-payment' ), |
| 648 |
'type' => 'text', |
| 649 |
'placeholder' => 'Organizer', |
| 650 |
'defaultValue' => 'Organizer', |
| 651 |
'info' => __( 'Shown beneath the creator\'s name (e.g. Organizer, Founder).', 'better-payment' ), |
| 652 |
], |
| 653 |
[ |
| 654 |
'key' => 'creator_user_id', |
| 655 |
'label' => __( 'Campaign Creator', 'better-payment' ), |
| 656 |
'type' => 'select', |
| 657 |
'options' => $creator_options, |
| 658 |
], |
| 659 |
[ |
| 660 |
'key' => 'description', |
| 661 |
'label' => __( 'Organizer Description', 'better-payment' ), |
| 662 |
'type' => 'rich_text', |
| 663 |
'info' => __( 'Brief bio or message shown beneath the creator\'s name.', 'better-payment' ), |
| 664 |
], |
| 665 |
[ |
| 666 |
'key' => 'width', |
| 667 |
'label' => __( 'Width', 'better-payment' ), |
| 668 |
'type' => 'range', |
| 669 |
'min' => 10, |
| 670 |
'max' => 100, |
| 671 |
'step' => 1, |
| 672 |
'defaultValue' => 100, |
| 673 |
'info' => __( 'Width of the organizer block as a percentage.', 'better-payment' ), |
| 674 |
], |
| 675 |
[ |
| 676 |
'key' => 'align', |
| 677 |
'label' => __( 'Align', 'better-payment' ), |
| 678 |
'type' => 'align', |
| 679 |
'defaultValue' => 'left', |
| 680 |
], |
| 681 |
], |
| 682 |
] ); |
| 683 |
|
| 684 |
ElementRegistry::register( 'donate_amount', [ |
| 685 |
'label' => __( 'Donate Amount', 'better-payment' ), |
| 686 |
'icon' => 'money-alt', |
| 687 |
'defaultSettings' => [ |
| 688 |
'headline' => 'Donate Amount', |
| 689 |
], |
| 690 |
'settingsSchema' => [ |
| 691 |
[ |
| 692 |
'key' => 'headline', |
| 693 |
'label' => __( 'Headline', 'better-payment' ), |
| 694 |
'type' => 'text', |
| 695 |
'placeholder' => __( 'Headline', 'better-payment' ), |
| 696 |
'defaultValue' => 'Donate Amount', |
| 697 |
'info' => __( 'Optional heading shown above the donation amounts.', 'better-payment' ), |
| 698 |
], |
| 699 |
[ |
| 700 |
'key' => 'bpc_minimum_amount', |
| 701 |
'label' => __( 'Minimum Donation Amount', 'better-payment' ), |
| 702 |
'type' => 'currency', |
| 703 |
'metaKey' => 'bpc_minimum_amount', |
| 704 |
'info' => __( 'Leave empty to allow no restrictions on how small the donation can be.', 'better-payment' ), |
| 705 |
], |
| 706 |
[ |
| 707 |
'key' => 'bpc_suggested_amounts', |
| 708 |
'label' => __( 'Suggested Donation Amounts', 'better-payment' ), |
| 709 |
'type' => 'suggested_amounts', |
| 710 |
'metaKey' => 'bpc_suggested_amounts', |
| 711 |
], |
| 712 |
[ |
| 713 |
'key' => 'bpc_allow_custom_amount', |
| 714 |
'label' => __( 'Allow Custom Amount', 'better-payment' ), |
| 715 |
'type' => 'switch', |
| 716 |
'metaKey' => 'bpc_allow_custom_amount', |
| 717 |
'defaultValue' => true, |
| 718 |
], |
| 719 |
], |
| 720 |
] ); |
| 721 |
|
| 722 |
ElementRegistry::register( 'social_sharing', [ |
| 723 |
'label' => __( 'Social Sharing', 'better-payment' ), |
| 724 |
'icon' => 'share', |
| 725 |
'defaultSettings' => [ |
| 726 |
'headline' => 'Share Now', |
| 727 |
'twitter' => true, |
| 728 |
'facebook' => true, |
| 729 |
'linkedin' => true, |
| 730 |
'pinterest' => true, |
| 731 |
'mastodon' => true, |
| 732 |
'threads' => true, |
| 733 |
'bluesky' => true, |
| 734 |
'open_new_tab' => true, |
| 735 |
'align' => 'left', |
| 736 |
], |
| 737 |
'settingsSchema' => [ |
| 738 |
[ |
| 739 |
'key' => 'headline', |
| 740 |
'label' => __( 'Headline', 'better-payment' ), |
| 741 |
'type' => 'text', |
| 742 |
'placeholder' => __( 'Headline', 'better-payment' ), |
| 743 |
'defaultValue' => 'Share Now', |
| 744 |
], |
| 745 |
[ |
| 746 |
'key' => '_networks', |
| 747 |
'label' => __( 'Choose your social network(s):', 'better-payment' ), |
| 748 |
'type' => 'section_label', |
| 749 |
], |
| 750 |
[ |
| 751 |
'key' => 'twitter', |
| 752 |
'label' => __( 'Twitter / X', 'better-payment' ), |
| 753 |
'type' => 'toggle', |
| 754 |
'defaultValue' => true, |
| 755 |
], |
| 756 |
[ |
| 757 |
'key' => 'facebook', |
| 758 |
'label' => __( 'Facebook', 'better-payment' ), |
| 759 |
'type' => 'toggle', |
| 760 |
'defaultValue' => true, |
| 761 |
], |
| 762 |
[ |
| 763 |
'key' => 'linkedin', |
| 764 |
'label' => __( 'LinkedIn', 'better-payment' ), |
| 765 |
'type' => 'toggle', |
| 766 |
'defaultValue' => true, |
| 767 |
], |
| 768 |
[ |
| 769 |
'key' => 'pinterest', |
| 770 |
'label' => __( 'Pinterest', 'better-payment' ), |
| 771 |
'type' => 'toggle', |
| 772 |
'defaultValue' => true, |
| 773 |
], |
| 774 |
[ |
| 775 |
'key' => 'mastodon', |
| 776 |
'label' => __( 'Mastodon', 'better-payment' ), |
| 777 |
'type' => 'toggle', |
| 778 |
'defaultValue' => true, |
| 779 |
], |
| 780 |
[ |
| 781 |
'key' => 'threads', |
| 782 |
'label' => __( 'Threads', 'better-payment' ), |
| 783 |
'type' => 'toggle', |
| 784 |
'defaultValue' => true, |
| 785 |
], |
| 786 |
[ |
| 787 |
'key' => 'bluesky', |
| 788 |
'label' => __( 'Bluesky', 'better-payment' ), |
| 789 |
'type' => 'toggle', |
| 790 |
'defaultValue' => true, |
| 791 |
], |
| 792 |
[ |
| 793 |
'key' => 'open_new_tab', |
| 794 |
'label' => __( 'Open Links In New Tab', 'better-payment' ), |
| 795 |
'type' => 'switch', |
| 796 |
'defaultValue' => true, |
| 797 |
], |
| 798 |
[ |
| 799 |
'key' => 'align', |
| 800 |
'label' => __( 'Align', 'better-payment' ), |
| 801 |
'type' => 'align', |
| 802 |
], |
| 803 |
], |
| 804 |
] ); |
| 805 |
|
| 806 |
ElementRegistry::register( 'social_links', [ |
| 807 |
'label' => __( 'Social Links', 'better-payment' ), |
| 808 |
'icon' => 'admin-links', |
| 809 |
'defaultSettings' => [ |
| 810 |
'headline' => 'Follow Now', |
| 811 |
'twitter' => 'https://twitter.com/', |
| 812 |
'facebook' => 'https://facebook.com/', |
| 813 |
'linkedin' => 'https://linkedin.com/', |
| 814 |
'instagram' => '', |
| 815 |
'tiktok' => '', |
| 816 |
'pinterest' => '', |
| 817 |
'youtube' => '', |
| 818 |
'threads' => '', |
| 819 |
'bluesky' => '', |
| 820 |
'mastodon' => '', |
| 821 |
'open_new_tab' => true, |
| 822 |
'align' => 'left', |
| 823 |
], |
| 824 |
'settingsSchema' => [ |
| 825 |
[ |
| 826 |
'key' => 'headline', |
| 827 |
'label' => __( 'Headline', 'better-payment' ), |
| 828 |
'type' => 'text', |
| 829 |
'placeholder' => __( 'Headline', 'better-payment' ), |
| 830 |
'defaultValue' => 'Follow Now', |
| 831 |
], |
| 832 |
[ |
| 833 |
'key' => 'twitter', |
| 834 |
'label' => __( 'Twitter / X URL', 'better-payment' ), |
| 835 |
'type' => 'url', |
| 836 |
'placeholder' => 'https://', |
| 837 |
], |
| 838 |
[ |
| 839 |
'key' => 'facebook', |
| 840 |
'label' => __( 'Facebook URL', 'better-payment' ), |
| 841 |
'type' => 'url', |
| 842 |
'placeholder' => 'https://', |
| 843 |
], |
| 844 |
[ |
| 845 |
'key' => 'linkedin', |
| 846 |
'label' => __( 'LinkedIn URL', 'better-payment' ), |
| 847 |
'type' => 'url', |
| 848 |
'placeholder' => 'https://', |
| 849 |
], |
| 850 |
[ |
| 851 |
'key' => 'instagram', |
| 852 |
'label' => __( 'Instagram URL', 'better-payment' ), |
| 853 |
'type' => 'url', |
| 854 |
'placeholder' => 'https://', |
| 855 |
], |
| 856 |
[ |
| 857 |
'key' => 'tiktok', |
| 858 |
'label' => __( 'TikTok URL', 'better-payment' ), |
| 859 |
'type' => 'url', |
| 860 |
'placeholder' => 'https://', |
| 861 |
], |
| 862 |
[ |
| 863 |
'key' => 'pinterest', |
| 864 |
'label' => __( 'Pinterest URL', 'better-payment' ), |
| 865 |
'type' => 'url', |
| 866 |
'placeholder' => 'https://', |
| 867 |
], |
| 868 |
[ |
| 869 |
'key' => 'youtube', |
| 870 |
'label' => __( 'YouTube URL', 'better-payment' ), |
| 871 |
'type' => 'url', |
| 872 |
'placeholder' => 'https://', |
| 873 |
], |
| 874 |
[ |
| 875 |
'key' => 'threads', |
| 876 |
'label' => __( 'Threads URL', 'better-payment' ), |
| 877 |
'type' => 'url', |
| 878 |
'placeholder' => 'https://', |
| 879 |
], |
| 880 |
[ |
| 881 |
'key' => 'bluesky', |
| 882 |
'label' => __( 'Bluesky URL', 'better-payment' ), |
| 883 |
'type' => 'url', |
| 884 |
'placeholder' => 'https://', |
| 885 |
], |
| 886 |
[ |
| 887 |
'key' => 'mastodon', |
| 888 |
'label' => __( 'Mastodon URL', 'better-payment' ), |
| 889 |
'type' => 'url', |
| 890 |
'placeholder' => 'https://', |
| 891 |
], |
| 892 |
[ |
| 893 |
'key' => 'open_new_tab', |
| 894 |
'label' => __( 'Open Links In New Tab', 'better-payment' ), |
| 895 |
'type' => 'switch', |
| 896 |
'defaultValue' => true, |
| 897 |
], |
| 898 |
[ |
| 899 |
'key' => 'align', |
| 900 |
'label' => __( 'Align', 'better-payment' ), |
| 901 |
'type' => 'align', |
| 902 |
], |
| 903 |
], |
| 904 |
] ); |
| 905 |
} |
| 906 |
} |
| 907 |
|