PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.1.0
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.1.0
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 / fields / number-markup.php

number-markup.php in SureDonation – Donation Forms, Fundraising Campaigns & Donor Management 1.1.0, at inc/fields/number-markup.php

133 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * SureDonation Number Markup Class.
4 *
5 * @package SureDonation
6 * @since 0.0.1
7 */
8
9 namespace SureDonation\Inc\Fields;
10
11 use SureDonation\Inc\Helper;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 /**
18 * Number Markup Class.
19 *
20 * @since 0.0.1
21 */
22 class Number_Markup extends Base {
23 /**
24 * Minimum value allowed.
25 *
26 * @var int
27 * @since 0.0.1
28 */
29 protected $min_value;
30
31 /**
32 * Maximum value allowed (0 = no limit).
33 *
34 * @var int
35 * @since 0.0.1
36 */
37 protected $max_value;
38
39 /**
40 * Step value for number input.
41 *
42 * @var int|float
43 * @since 0.0.1
44 */
45 protected $step;
46
47 /**
48 * Whether to show currency symbol.
49 *
50 * @var bool
51 * @since 0.0.1
52 */
53 protected $show_currency;
54
55 /**
56 * Currency symbol.
57 *
58 * @var string
59 * @since 0.0.1
60 */
61 protected $currency_symbol;
62
63 /**
64 * Initialize the properties based on block attributes.
65 *
66 * @param array<string, mixed> $attributes Block attributes.
67 * @since 0.0.1
68 */
69 public function __construct( $attributes ) {
70 $this->slug = 'number';
71 $this->min_value = isset( $attributes['minValue'] ) ? absint( Helper::get_string_value( $attributes['minValue'] ) ) : 1;
72 $this->max_value = isset( $attributes['maxValue'] ) ? absint( Helper::get_string_value( $attributes['maxValue'] ) ) : 0;
73 $this->step = isset( $attributes['step'] ) ? (float) Helper::get_string_value( $attributes['step'] ) : 1;
74 $this->show_currency = ! empty( $attributes['showCurrency'] );
75
76 // Get currency symbol from settings.
77 $this->currency_symbol = Helper::get_string_value( Helper::get_suredonation_option( 'currency_symbol', '$' ) );
78
79 $this->set_properties( $attributes );
80 $this->set_unique_slug();
81 $this->set_markup_properties();
82 }
83
84 /**
85 * Render number markup
86 *
87 * @since 0.0.1
88 * @return string
89 */
90 public function markup() {
91 $classes = $this->get_field_classes( $this->show_currency ? [ 'sd-has-currency' ] : [] );
92 $aria_desc = $this->get_aria_describedby();
93
94 ob_start();
95 ?>
96 <div data-block-id="<?php echo esc_attr( $this->block_id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
97 <?php echo wp_kses_post( $this->label_markup ); ?>
98 <?php echo wp_kses_post( $this->help_markup ); ?>
99 <div class="sd-block-wrap sd-number-wrap">
100 <?php if ( $this->show_currency ) { ?>
101 <span class="sd-currency-symbol"><?php echo esc_html( $this->currency_symbol ); ?></span>
102 <?php } ?>
103 <input
104 class="sd-input-common sd-input-<?php echo esc_attr( $this->slug ); ?>"
105 type="number"
106 name="<?php echo esc_attr( $this->field_name ); ?>"
107 id="<?php echo esc_attr( $this->unique_slug ); ?>"
108 data-slug="<?php echo esc_attr( $this->block_slug ? $this->block_slug : $this->unique_slug ); ?>"
109 <?php if ( ! empty( $aria_desc ) ) { ?>
110 aria-describedby="<?php echo esc_attr( $aria_desc ); ?>"
111 <?php } ?>
112 data-required="<?php echo esc_attr( $this->data_require_attr ); ?>"
113 aria-required="<?php echo esc_attr( $this->data_require_attr ); ?>"
114 min="<?php echo esc_attr( (string) $this->min_value ); ?>"
115 <?php if ( $this->max_value > 0 ) { ?>
116 max="<?php echo esc_attr( (string) $this->max_value ); ?>"
117 <?php } ?>
118 step="<?php echo esc_attr( (string) $this->step ); ?>"
119 <?php if ( '' !== $this->default ) { ?>
120 value="<?php echo esc_attr( $this->default ); ?>"
121 <?php } ?>
122 <?php if ( '' !== $this->placeholder ) { ?>
123 placeholder="<?php echo esc_attr( $this->placeholder ); ?>"
124 <?php } ?>
125 />
126 </div>
127 <div class="sd-error-wrap"><?php echo wp_kses_post( $this->error_msg_markup ); ?></div>
128 </div>
129 <?php
130 return (string) ob_get_clean();
131 }
132 }
133