| 1 |
<?php |
| 2 |
/** |
| 3 |
* Give Meta Box Functions |
| 4 |
* |
| 5 |
* @package Give |
| 6 |
* @subpackage Functions |
| 7 |
* @copyright Copyright (c) 2016, GiveWP |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 1.8 |
| 10 |
*/ |
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
/** |
| 17 |
* Check if field callback exist or not. |
| 18 |
* |
| 19 |
* @since 1.8 |
| 20 |
* |
| 21 |
* @param $field |
| 22 |
* |
| 23 |
* @return bool|string |
| 24 |
*/ |
| 25 |
function give_is_field_callback_exist( $field ) { |
| 26 |
return ( give_get_field_callback( $field ) ? true : false ); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Get field callback. |
| 31 |
* |
| 32 |
* @since 1.8 |
| 33 |
* |
| 34 |
* @param $field |
| 35 |
* |
| 36 |
* @return bool|string |
| 37 |
*/ |
| 38 |
function give_get_field_callback( $field ) { |
| 39 |
$func_name_prefix = 'give'; |
| 40 |
$func_name = ''; |
| 41 |
|
| 42 |
// Set callback function on basis of cmb2 field name. |
| 43 |
switch ( $field['type'] ) { |
| 44 |
case 'radio_inline': |
| 45 |
$func_name = "{$func_name_prefix}_radio"; |
| 46 |
break; |
| 47 |
|
| 48 |
case 'text': |
| 49 |
case 'text-medium': |
| 50 |
case 'text_medium': |
| 51 |
case 'text-small': |
| 52 |
case 'text_small': |
| 53 |
case 'number': |
| 54 |
case 'email': |
| 55 |
$func_name = "{$func_name_prefix}_text_input"; |
| 56 |
break; |
| 57 |
|
| 58 |
case 'textarea': |
| 59 |
$func_name = "{$func_name_prefix}_textarea_input"; |
| 60 |
break; |
| 61 |
|
| 62 |
case 'colorpicker': |
| 63 |
$func_name = "{$func_name_prefix}_{$field['type']}"; |
| 64 |
break; |
| 65 |
|
| 66 |
case 'hidden': |
| 67 |
case 'levels_id': |
| 68 |
$func_name = "{$func_name_prefix}_hidden_input"; |
| 69 |
break; |
| 70 |
|
| 71 |
case 'group': |
| 72 |
$func_name = "_{$func_name_prefix}_metabox_form_data_repeater_fields"; |
| 73 |
break; |
| 74 |
|
| 75 |
case 'give_default_radio_inline': |
| 76 |
$func_name = "{$func_name_prefix}_radio"; |
| 77 |
break; |
| 78 |
|
| 79 |
case 'donation_limit': |
| 80 |
$func_name = "{$func_name_prefix}_donation_limit"; |
| 81 |
break; |
| 82 |
|
| 83 |
case 'chosen': |
| 84 |
$func_name = "{$func_name_prefix}_chosen_input"; |
| 85 |
break; |
| 86 |
|
| 87 |
case 'label': |
| 88 |
$func_name = "{$func_name_prefix}_label_field"; |
| 89 |
break; |
| 90 |
|
| 91 |
default: |
| 92 |
if ( |
| 93 |
array_key_exists( 'callback', $field ) |
| 94 |
&& ! empty( $field['callback'] ) |
| 95 |
) { |
| 96 |
$func_name = $field['callback']; |
| 97 |
} else { |
| 98 |
$func_name = "{$func_name_prefix}_{$field['type']}"; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Filter the metabox setting render function |
| 104 |
* |
| 105 |
* @since 1.8 |
| 106 |
*/ |
| 107 |
$func_name = apply_filters( 'give_get_field_callback', $func_name, $field ); |
| 108 |
|
| 109 |
// Exit if not any function exist. |
| 110 |
// Check if render callback exist or not. |
| 111 |
if ( empty( $func_name ) ) { |
| 112 |
return false; |
| 113 |
} elseif ( is_string( $func_name ) && ! function_exists( "$func_name" ) ) { |
| 114 |
return false; |
| 115 |
} elseif ( is_array( $func_name ) && ! method_exists( $func_name[0], "$func_name[1]" ) ) { |
| 116 |
return false; |
| 117 |
} |
| 118 |
|
| 119 |
return $func_name; |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* This function adds backward compatibility to render cmb2 type field type. |
| 124 |
* |
| 125 |
* @since 1.8 |
| 126 |
* |
| 127 |
* @param array $field Field argument array. |
| 128 |
* |
| 129 |
* @return bool |
| 130 |
*/ |
| 131 |
function give_render_field( $field ) { |
| 132 |
|
| 133 |
// Check if render callback exist or not. |
| 134 |
if ( ! ( $func_name = give_get_field_callback( $field ) ) ) { |
| 135 |
return false; |
| 136 |
} |
| 137 |
|
| 138 |
// CMB2 compatibility: Push all classes to attributes's class key |
| 139 |
if ( empty( $field['class'] ) ) { |
| 140 |
$field['class'] = ''; |
| 141 |
} |
| 142 |
|
| 143 |
if ( empty( $field['attributes']['class'] ) ) { |
| 144 |
$field['attributes']['class'] = ''; |
| 145 |
} |
| 146 |
|
| 147 |
$field['attributes']['class'] = trim( "give-field {$field['attributes']['class']} give-{$field['type']} {$field['class']}" ); |
| 148 |
unset( $field['class'] ); |
| 149 |
|
| 150 |
// CMB2 compatibility: Set wrapper class if any. |
| 151 |
if ( ! empty( $field['row_classes'] ) ) { |
| 152 |
$field['wrapper_class'] = $field['row_classes']; |
| 153 |
unset( $field['row_classes'] ); |
| 154 |
} |
| 155 |
|
| 156 |
// Set field params on basis of cmb2 field name. |
| 157 |
switch ( $field['type'] ) { |
| 158 |
case 'radio_inline': |
| 159 |
if ( empty( $field['wrapper_class'] ) ) { |
| 160 |
$field['wrapper_class'] = ''; |
| 161 |
} |
| 162 |
$field['wrapper_class'] .= ' give-inline-radio-fields'; |
| 163 |
|
| 164 |
break; |
| 165 |
|
| 166 |
case 'text': |
| 167 |
case 'text-medium': |
| 168 |
case 'text_medium': |
| 169 |
case 'text-small': |
| 170 |
case 'text_small': |
| 171 |
// CMB2 compatibility: Set field type to text. |
| 172 |
$field['type'] = isset( $field['attributes']['type'] ) ? $field['attributes']['type'] : 'text'; |
| 173 |
|
| 174 |
// CMB2 compatibility: Set data type to price. |
| 175 |
if ( |
| 176 |
empty( $field['data_type'] ) |
| 177 |
&& ! empty( $field['attributes']['class'] ) |
| 178 |
&& ( |
| 179 |
false !== strpos( $field['attributes']['class'], 'money' ) |
| 180 |
|| false !== strpos( $field['attributes']['class'], 'amount' ) |
| 181 |
) |
| 182 |
) { |
| 183 |
$field['data_type'] = 'decimal'; |
| 184 |
} |
| 185 |
break; |
| 186 |
|
| 187 |
case 'levels_id': |
| 188 |
$field['type'] = 'hidden'; |
| 189 |
break; |
| 190 |
|
| 191 |
case 'colorpicker': |
| 192 |
$field['type'] = 'text'; |
| 193 |
$field['class'] = 'give-colorpicker'; |
| 194 |
break; |
| 195 |
|
| 196 |
case 'give_default_radio_inline': |
| 197 |
$field['type'] = 'radio'; |
| 198 |
$field['options'] = [ |
| 199 |
'default' => __( 'Default', 'give' ), |
| 200 |
]; |
| 201 |
break; |
| 202 |
|
| 203 |
case 'donation_limit': |
| 204 |
$field['type'] = 'donation_limit'; |
| 205 |
break; |
| 206 |
} // End switch(). |
| 207 |
|
| 208 |
// CMB2 compatibility: Add support to define field description by desc & description param. |
| 209 |
// We encourage you to use description param. |
| 210 |
$field['description'] = ( ! empty( $field['description'] ) |
| 211 |
? $field['description'] |
| 212 |
: ( ! empty( $field['desc'] ) ? $field['desc'] : '' ) ); |
| 213 |
|
| 214 |
// Call render function. |
| 215 |
if ( is_array( $func_name ) ) { |
| 216 |
$func_name[0]->{$func_name[1]}( $field ); |
| 217 |
} else { |
| 218 |
$func_name( $field ); |
| 219 |
} |
| 220 |
|
| 221 |
return true; |
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
* Output a text input box. |
| 226 |
* |
| 227 |
* @since 1.8 |
| 228 |
* |
| 229 |
* @param array $field { |
| 230 |
* Optional. Array of text input field arguments. |
| 231 |
* |
| 232 |
* @type string $id Field ID. Default ''. |
| 233 |
* @type string $style CSS style for input field. Default ''. |
| 234 |
* @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 235 |
* @type string $value Value of input field. Default ''. |
| 236 |
* @type string $name Name of input field. Default ''. |
| 237 |
* @type string $type Type of input field. Default 'text'. |
| 238 |
* @type string $before_field Text/HTML to add before input field. Default ''. |
| 239 |
* @type string $after_field Text/HTML to add after input field. Default ''. |
| 240 |
* @type string $data_type Define data type for value of input to filter it properly. Default ''. |
| 241 |
* @type string $description Description of input field. Default ''. |
| 242 |
* @type array $attributes List of attributes of input field. Default array(). |
| 243 |
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 244 |
* => '****' ) |
| 245 |
* } |
| 246 |
* @return void |
| 247 |
*/ |
| 248 |
function give_text_input( $field ) { |
| 249 |
global $thepostid, $post; |
| 250 |
|
| 251 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 252 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 253 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 254 |
$field['value'] = give_get_field_value( $field, $thepostid ); |
| 255 |
$field['type'] = isset( $field['type'] ) ? $field['type'] : 'text'; |
| 256 |
$field['before_field'] = ''; |
| 257 |
$field['after_field'] = ''; |
| 258 |
$data_type = empty( $field['data_type'] ) ? '' : $field['data_type']; |
| 259 |
|
| 260 |
switch ( $data_type ) { |
| 261 |
case 'price': |
| 262 |
$field['value'] = ( ! empty( $field['value'] ) ? give_format_decimal( give_maybe_sanitize_amount( $field['value'] ), false, false ) : $field['value'] ); |
| 263 |
|
| 264 |
$field['before_field'] = ! empty( $field['before_field'] ) ? $field['before_field'] : ( give_get_option( 'currency_position', 'before' ) == 'before' ? '<span class="give-money-symbol give-money-symbol-before">' . give_currency_symbol() . '</span>' : '' ); |
| 265 |
$field['after_field'] = ! empty( $field['after_field'] ) ? $field['after_field'] : ( give_get_option( 'currency_position', 'before' ) == 'after' ? '<span class="give-money-symbol give-money-symbol-after">' . give_currency_symbol() . '</span>' : '' ); |
| 266 |
break; |
| 267 |
|
| 268 |
case 'decimal': |
| 269 |
$field['attributes']['class'] .= ' give_input_decimal'; |
| 270 |
$field['value'] = ( ! empty( $field['value'] ) ? give_format_decimal( give_maybe_sanitize_amount( $field['value'] ), false, false ) : $field['value'] ); |
| 271 |
break; |
| 272 |
|
| 273 |
default: |
| 274 |
break; |
| 275 |
} |
| 276 |
|
| 277 |
?> |
| 278 |
<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>"> |
| 279 |
<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label> |
| 280 |
<?php echo $field['before_field']; ?> |
| 281 |
<input |
| 282 |
type="<?php echo esc_attr( $field['type'] ); ?>" |
| 283 |
style="<?php echo esc_attr( $field['style'] ); ?>" |
| 284 |
name="<?php echo give_get_field_name( $field ); ?>" |
| 285 |
id="<?php echo esc_attr( $field['id'] ); ?>" |
| 286 |
value="<?php echo esc_attr( $field['value'] ); ?>" |
| 287 |
<?php echo give_get_attribute_str( $field ); ?> |
| 288 |
/> |
| 289 |
<?php echo $field['after_field']; ?> |
| 290 |
<?php |
| 291 |
echo give_get_field_description( $field ); |
| 292 |
echo '</p>'; |
| 293 |
} |
| 294 |
|
| 295 |
/** |
| 296 |
* Output a chosen input box. |
| 297 |
* Note: only for internal use. |
| 298 |
* |
| 299 |
* @param array $field { |
| 300 |
* Optional. Array of text input field arguments. |
| 301 |
* |
| 302 |
* @type string $id Field ID. Default ''. |
| 303 |
* @type string $style CSS style for input field. Default ''. |
| 304 |
* @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 305 |
* @type string $value Value of input field. Default ''. |
| 306 |
* @type string $name Name of input field. Default ''. |
| 307 |
* @type string $type Type of input field. Default 'text'. |
| 308 |
* @type string $before_field Text/HTML to add before input field. Default ''. |
| 309 |
* @type string $after_field Text/HTML to add after input field. Default ''. |
| 310 |
* @type string $data_type Define data type for value of input to filter it properly. Default ''. |
| 311 |
* @type string $description Description of input field. Default ''. |
| 312 |
* @type array $attributes List of attributes of input field. Default array(). |
| 313 |
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 314 |
* => '****' ) |
| 315 |
* } |
| 316 |
* |
| 317 |
* @since 2.1 |
| 318 |
* |
| 319 |
* @return void |
| 320 |
*/ |
| 321 |
function give_chosen_input( $field ) { |
| 322 |
global $thepostid, $post; |
| 323 |
|
| 324 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 325 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 326 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 327 |
$field['before_field'] = ''; |
| 328 |
$field['after_field'] = ''; |
| 329 |
$placeholder = isset( $field['placeholder'] ) ? 'data-placeholder="' . $field['placeholder'] . '"' : ''; |
| 330 |
$data_type = ! empty( $field['data_type'] ) ? $field['data_type'] : ''; |
| 331 |
$type = ''; |
| 332 |
$field['value'] = array_filter( (array) give_get_field_value( $field, $thepostid ) ); |
| 333 |
$choices = $field['options']; |
| 334 |
$fieldName = esc_attr( give_get_field_name( $field ) ); |
| 335 |
$allow_new_values = ! empty( $field['allow-custom-values'] ) && (bool) $field['allow-custom-values'] ? 'data-allows-new-values="true"' : ''; |
| 336 |
|
| 337 |
// Set attributes based on multiselect datatype. |
| 338 |
if ( 'multiselect' === $data_type ) { |
| 339 |
$type = 'multiple'; |
| 340 |
$field['value'] = empty( $field['value'] ) ? [] : $field['value']; |
| 341 |
$fieldName .= '[]'; |
| 342 |
} |
| 343 |
|
| 344 |
if ( $allow_new_values && $field['value'] ) { |
| 345 |
$choices = array_merge( array_combine( $field['value'], $field['value'] ), $choices ); |
| 346 |
} |
| 347 |
?> |
| 348 |
<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>"> |
| 349 |
<label for="<?php echo esc_attr( give_get_field_name( $field ) ); ?>"> |
| 350 |
<?php echo wp_kses_post( $field['name'] ); ?> |
| 351 |
</label> |
| 352 |
<?php echo esc_attr( $field['before_field'] ); ?> |
| 353 |
<select |
| 354 |
class="give-select-chosen give-chosen-settings" |
| 355 |
style="<?php echo esc_attr( $field['style'] ); ?>" |
| 356 |
name="<?php echo $fieldName; ?>" |
| 357 |
id="<?php echo esc_attr( $field['id'] ); ?>" |
| 358 |
<?php echo "{$type} {$allow_new_values} {$placeholder}"; ?> |
| 359 |
<?php echo give_get_attribute_str( $field ); ?> |
| 360 |
> |
| 361 |
<?php |
| 362 |
foreach ( $choices as $key => $name ) { |
| 363 |
echo sprintf( |
| 364 |
'<option %1$s value="%2$s">%3$s</option>', |
| 365 |
in_array( $key, $field['value'] ) ? 'selected="selected"' : '', |
| 366 |
esc_attr( $key ), |
| 367 |
$name |
| 368 |
); |
| 369 |
} |
| 370 |
?> |
| 371 |
</select> |
| 372 |
<?php echo esc_attr( $field['after_field'] ); ?> |
| 373 |
<?php echo give_get_field_description( $field ); ?> |
| 374 |
</p> |
| 375 |
<?php |
| 376 |
} |
| 377 |
|
| 378 |
/** |
| 379 |
* Output a label field |
| 380 |
* Note: only for internal use. |
| 381 |
* |
| 382 |
* @param array $field { |
| 383 |
* Optional. Array of text input field arguments. |
| 384 |
* |
| 385 |
* @type string $id Field ID. Default ''. |
| 386 |
* @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 387 |
* @type string $value Value of input field. Default ''. |
| 388 |
* @type string $title Text to display. HTML supported Default ''. |
| 389 |
* @type string $before_field Text/HTML to add before input field. Default ''. |
| 390 |
* @type string $after_field Text/HTML to add after input field. Default ''. |
| 391 |
* } |
| 392 |
* |
| 393 |
* @since 2.7.0 |
| 394 |
* |
| 395 |
* @return void |
| 396 |
*/ |
| 397 |
function give_label_field( $field ) { |
| 398 |
global $thepostid, $post; |
| 399 |
|
| 400 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 401 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 402 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 403 |
$field['before_field'] = ''; |
| 404 |
$field['after_field'] = ''; |
| 405 |
?> |
| 406 |
<p class=" <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>"> |
| 407 |
<?php echo esc_attr( $field['before_field'] ); ?> |
| 408 |
<?php echo $field['title']; ?> |
| 409 |
<?php echo esc_attr( $field['after_field'] ); ?> |
| 410 |
<?php echo give_get_field_description( $field ); ?> |
| 411 |
</p> |
| 412 |
<?php |
| 413 |
} |
| 414 |
|
| 415 |
/** |
| 416 |
* Give range slider field. |
| 417 |
* Note: only for internal logic |
| 418 |
* |
| 419 |
* @since 2.1 |
| 420 |
* |
| 421 |
* @param array $field { |
| 422 |
* Optional. Array of text input field arguments. |
| 423 |
* |
| 424 |
* @type string $id Field ID. Default ''. |
| 425 |
* @type string $style CSS style for input field. Default ''. |
| 426 |
* @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 427 |
* @type string $value Value of input field. Default ''. |
| 428 |
* @type string $name Name of input field. Default ''. |
| 429 |
* @type string $type Type of input field. Default 'text'. |
| 430 |
* @type string $before_field Text/HTML to add before input field. Default ''. |
| 431 |
* @type string $after_field Text/HTML to add after input field. Default ''. |
| 432 |
* @type string $data_type Define data type for value of input to filter it properly. Default ''. |
| 433 |
* @type string $description Description of input field. Default ''. |
| 434 |
* @type array $attributes List of attributes of input field. Default array(). |
| 435 |
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 436 |
* => '****' ) |
| 437 |
* } |
| 438 |
* |
| 439 |
* @return void |
| 440 |
*/ |
| 441 |
function give_donation_limit( $field ) { |
| 442 |
global $thepostid, $post; |
| 443 |
|
| 444 |
// Get Give donation form ID. |
| 445 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 446 |
|
| 447 |
// Default arguments. |
| 448 |
$default_options = [ |
| 449 |
'style' => '', |
| 450 |
'wrapper_class' => '', |
| 451 |
'value' => give_get_field_value( $field, $thepostid ), |
| 452 |
'data_type' => 'decimal', |
| 453 |
'before_field' => '', |
| 454 |
'after_field' => '', |
| 455 |
]; |
| 456 |
|
| 457 |
// Field options. |
| 458 |
$field['options'] = ! empty( $field['options'] ) ? $field['options'] : []; |
| 459 |
|
| 460 |
// Default field option arguments. |
| 461 |
$field['options'] = wp_parse_args( |
| 462 |
$field['options'], |
| 463 |
[ |
| 464 |
'display_label' => '', |
| 465 |
'minimum' => give_format_decimal( '1.00', false, false ), |
| 466 |
'maximum' => give_format_decimal( '999999.99', false, false ), |
| 467 |
] |
| 468 |
); |
| 469 |
|
| 470 |
// Set default field options. |
| 471 |
$field_options = wp_parse_args( $field, $default_options ); |
| 472 |
|
| 473 |
// Get default minimum value, if empty. |
| 474 |
$field_options['value']['minimum'] = ! empty( $field_options['value']['minimum'] ) |
| 475 |
? $field_options['value']['minimum'] |
| 476 |
: $field_options['options']['minimum']; |
| 477 |
|
| 478 |
// Get default maximum value, if empty. |
| 479 |
$field_options['value']['maximum'] = ! empty( $field_options['value']['maximum'] ) |
| 480 |
? $field_options['value']['maximum'] |
| 481 |
: $field_options['options']['maximum']; |
| 482 |
?> |
| 483 |
<p class="give-field-wrap <?php echo esc_attr( $field_options['id'] ); ?>_field <?php echo esc_attr( $field_options['wrapper_class'] ); ?>"> |
| 484 |
<label for="<?php echo give_get_field_name( $field_options ); ?>"><?php echo wp_kses_post( $field_options['name'] ); ?></label> |
| 485 |
<span class="give_donation_limit_display"> |
| 486 |
<?php |
| 487 |
foreach ( $field_options['value'] as $amount_range => $amount_value ) { |
| 488 |
|
| 489 |
switch ( $field_options['data_type'] ) { |
| 490 |
case 'price': |
| 491 |
$currency_position = give_get_option( 'currency_position', 'before' ); |
| 492 |
$price_field_labels = 'minimum' === $amount_range ? __( 'Minimum amount', 'give' ) : __( 'Maximum amount', 'give' ); |
| 493 |
|
| 494 |
$tooltip_html = [ |
| 495 |
'before' => Give()->tooltips->render_span( |
| 496 |
[ |
| 497 |
'label' => $price_field_labels, |
| 498 |
'tag_content' => sprintf( '<span class="give-money-symbol give-money-symbol-before">%s</span>', give_currency_symbol() ), |
| 499 |
] |
| 500 |
), |
| 501 |
'after' => Give()->tooltips->render_span( |
| 502 |
[ |
| 503 |
'label' => $price_field_labels, |
| 504 |
'tag_content' => sprintf( '<span class="give-money-symbol give-money-symbol-after">%s</span>', give_currency_symbol() ), |
| 505 |
] |
| 506 |
), |
| 507 |
]; |
| 508 |
|
| 509 |
$before_html = ! empty( $field_options['before_field'] ) |
| 510 |
? $field_options['before_field'] |
| 511 |
: ( 'before' === $currency_position ? $tooltip_html['before'] : '' ); |
| 512 |
|
| 513 |
$after_html = ! empty( $field_options['after_field'] ) |
| 514 |
? $field_options['after_field'] |
| 515 |
: ( 'after' === $currency_position ? $tooltip_html['after'] : '' ); |
| 516 |
|
| 517 |
$field_options['attributes']['class'] .= ' give-text_small'; |
| 518 |
$field_options['value'][ $amount_range ] = $amount_value; |
| 519 |
break; |
| 520 |
|
| 521 |
case 'decimal': |
| 522 |
$field_options['attributes']['class'] .= ' give_input_decimal give-text_small'; |
| 523 |
$field_options['value'][ $amount_range ] = $amount_value; |
| 524 |
break; |
| 525 |
} |
| 526 |
|
| 527 |
echo '<span class=give-minmax-wrap>'; |
| 528 |
printf( '<label for="%1$s_give_donation_limit_%2$s">%3$s</label>', esc_attr( $field_options['id'] ), esc_attr( $amount_range ), esc_html( $price_field_labels ) ); |
| 529 |
|
| 530 |
echo isset( $before_html ) ? $before_html : ''; |
| 531 |
?> |
| 532 |
<input |
| 533 |
name="<?php echo give_get_field_name( $field_options ); ?>[<?php echo esc_attr( $amount_range ); ?>]" |
| 534 |
type="text" |
| 535 |
id="<?php echo $field_options['id']; ?>_give_donation_limit_<?php echo $amount_range; ?>" |
| 536 |
data-range_type="<?php echo esc_attr( $amount_range ); ?>" |
| 537 |
value="<?php echo give_format_decimal( esc_attr( $field_options['value'][ $amount_range ] ) ); ?>" |
| 538 |
placeholder="<?php echo give_format_decimal( $field_options['options'][ $amount_range ] ); ?>" |
| 539 |
<?php echo give_get_attribute_str( $field_options ); ?> |
| 540 |
/> |
| 541 |
<?php |
| 542 |
echo isset( $after_html ) ? $after_html : ''; |
| 543 |
echo '</span>'; |
| 544 |
} |
| 545 |
?> |
| 546 |
</span> |
| 547 |
<?php echo give_get_field_description( $field_options ); ?> |
| 548 |
</p> |
| 549 |
<?php |
| 550 |
} |
| 551 |
|
| 552 |
/** |
| 553 |
* Output a hidden input box. |
| 554 |
* |
| 555 |
* @since 1.8 |
| 556 |
* |
| 557 |
* @param array $field { |
| 558 |
* Optional. Array of hidden text input field arguments. |
| 559 |
* |
| 560 |
* @type string $id Field ID. Default ''. |
| 561 |
* @type string $value Value of input field. Default ''. |
| 562 |
* @type string $name Name of input field. Default ''. |
| 563 |
* @type string $type Type of input field. Default 'text'. |
| 564 |
* @type array $attributes List of attributes of input field. Default array(). |
| 565 |
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 566 |
* => '****' ) |
| 567 |
* } |
| 568 |
* @return void |
| 569 |
*/ |
| 570 |
function give_hidden_input( $field ) { |
| 571 |
global $thepostid, $post; |
| 572 |
|
| 573 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 574 |
$field['value'] = give_get_field_value( $field, $thepostid ); |
| 575 |
|
| 576 |
// Custom attribute handling |
| 577 |
$custom_attributes = []; |
| 578 |
|
| 579 |
if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) { |
| 580 |
|
| 581 |
foreach ( $field['attributes'] as $attribute => $value ) { |
| 582 |
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; |
| 583 |
} |
| 584 |
} |
| 585 |
?> |
| 586 |
|
| 587 |
<input |
| 588 |
type="hidden" |
| 589 |
name="<?php echo give_get_field_name( $field ); ?>" |
| 590 |
id="<?php echo esc_attr( $field['id'] ); ?>" |
| 591 |
value="<?php echo esc_attr( $field['value'] ); ?>" |
| 592 |
<?php echo give_get_attribute_str( $field ); ?> |
| 593 |
/> |
| 594 |
<?php |
| 595 |
} |
| 596 |
|
| 597 |
/** |
| 598 |
* Output a textarea input box. |
| 599 |
* |
| 600 |
* @since 1.8 |
| 601 |
* @since 1.8 |
| 602 |
* |
| 603 |
* @param array $field { |
| 604 |
* Optional. Array of textarea input field arguments. |
| 605 |
* |
| 606 |
* @type string $id Field ID. Default ''. |
| 607 |
* @type string $style CSS style for input field. Default ''. |
| 608 |
* @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 609 |
* @type string $value Value of input field. Default ''. |
| 610 |
* @type string $name Name of input field. Default ''. |
| 611 |
* @type string $description Description of input field. Default ''. |
| 612 |
* @type array $attributes List of attributes of input field. Default array(). |
| 613 |
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 614 |
* => '****' ) |
| 615 |
* } |
| 616 |
* @return void |
| 617 |
*/ |
| 618 |
function give_textarea_input( $field ) { |
| 619 |
global $thepostid, $post; |
| 620 |
|
| 621 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 622 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 623 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 624 |
$field['value'] = give_get_field_value( $field, $thepostid ); |
| 625 |
$default_attributes = [ |
| 626 |
'cols' => 20, |
| 627 |
'rows' => 10, |
| 628 |
]; |
| 629 |
?> |
| 630 |
<div class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>"> |
| 631 |
<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label> |
| 632 |
<textarea |
| 633 |
style="<?php echo esc_attr( $field['style'] ); ?>" |
| 634 |
name="<?php echo give_get_field_name( $field ); ?>" |
| 635 |
id="<?php echo esc_attr( $field['id'] ); ?>" |
| 636 |
<?php echo give_get_attribute_str( $field, $default_attributes ); ?> |
| 637 |
><?php echo esc_textarea( $field['value'] ); ?></textarea> |
| 638 |
<?php |
| 639 |
echo give_get_field_description( $field ); |
| 640 |
echo '</div>'; |
| 641 |
} |
| 642 |
|
| 643 |
/** |
| 644 |
* Output a wysiwyg. |
| 645 |
* |
| 646 |
* @since 1.8 |
| 647 |
* |
| 648 |
* @param array $field { |
| 649 |
* Optional. Array of WordPress editor field arguments. |
| 650 |
* |
| 651 |
* @type string $id Field ID. Default ''. |
| 652 |
* @type string $style CSS style for input field. Default ''. |
| 653 |
* @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 654 |
* @type string $value Value of input field. Default ''. |
| 655 |
* @type string $name Name of input field. Default ''. |
| 656 |
* @type string $description Description of input field. Default ''. |
| 657 |
* @type array $attributes List of attributes of input field. Default array(). |
| 658 |
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 659 |
* => '****' ) |
| 660 |
* } |
| 661 |
* @return void |
| 662 |
*/ |
| 663 |
function give_wysiwyg( $field ) { |
| 664 |
global $thepostid, $post; |
| 665 |
|
| 666 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 667 |
$field['value'] = give_get_field_value( $field, $thepostid ); |
| 668 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 669 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 670 |
|
| 671 |
// Since WP 3.9.0 WP does not allow square brackets in field id. |
| 672 |
// If we pass square brackets in field id then code will work as expected but you will get PHP warnings. |
| 673 |
// wp-includes/class-wp-editor.php::parse_settings::106 |
| 674 |
$field['unique_field_id'] = str_replace( [ '[', ']' ], [ '_', '' ], give_get_field_name( $field ) ); |
| 675 |
|
| 676 |
$editor_attributes = [ |
| 677 |
'textarea_name' => isset( $field['repeatable_field_id'] ) ? $field['repeatable_field_id'] : $field['id'], |
| 678 |
'textarea_rows' => '10', |
| 679 |
'editor_css' => esc_attr( $field['style'] ), |
| 680 |
'editor_class' => $field['attributes']['class'], |
| 681 |
]; |
| 682 |
$data_wp_editor = ' data-wp-editor="' . base64_encode( |
| 683 |
json_encode( |
| 684 |
[ |
| 685 |
$field['value'], |
| 686 |
$field['unique_field_id'], |
| 687 |
$editor_attributes, |
| 688 |
] |
| 689 |
) |
| 690 |
) . '"'; |
| 691 |
$data_wp_editor = isset( $field['repeatable_field_id'] ) ? $data_wp_editor : ''; |
| 692 |
|
| 693 |
echo '<div class="give-field-wrap ' . $field['unique_field_id'] . '_field ' . esc_attr( $field['wrapper_class'] ) . '"' . $data_wp_editor . '><label for="' . $field['unique_field_id'] . '">' . wp_kses_post( $field['name'] ) . '</label>'; |
| 694 |
|
| 695 |
wp_editor( |
| 696 |
$field['value'], |
| 697 |
$field['unique_field_id'], |
| 698 |
$editor_attributes |
| 699 |
); |
| 700 |
|
| 701 |
echo give_get_field_description( $field ); |
| 702 |
echo '</div>'; |
| 703 |
} |
| 704 |
|
| 705 |
/** |
| 706 |
* Output a checkbox input box. |
| 707 |
* |
| 708 |
* @since 1.8 |
| 709 |
* |
| 710 |
* @param array $field { |
| 711 |
* Optional. Array of checkbox field arguments. |
| 712 |
* |
| 713 |
* @type string $id Field ID. Default ''. |
| 714 |
* @type string $style CSS style for input field. Default ''. |
| 715 |
* @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 716 |
* @type string $value Value of input field. Default ''. |
| 717 |
* @type string $cbvalue Checkbox value. Default 'on'. |
| 718 |
* @type string $name Name of input field. Default ''. |
| 719 |
* @type string $description Description of input field. Default ''. |
| 720 |
* @type array $attributes List of attributes of input field. Default array(). |
| 721 |
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 722 |
* => '****' ) |
| 723 |
* } |
| 724 |
* @return void |
| 725 |
*/ |
| 726 |
function give_checkbox( $field ) { |
| 727 |
global $thepostid, $post; |
| 728 |
|
| 729 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 730 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 731 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 732 |
$field['value'] = give_get_field_value( $field, $thepostid ); |
| 733 |
$field['cbvalue'] = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'on'; |
| 734 |
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 735 |
?> |
| 736 |
<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>"> |
| 737 |
<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label> |
| 738 |
<input |
| 739 |
type="checkbox" |
| 740 |
style="<?php echo esc_attr( $field['style'] ); ?>" |
| 741 |
name="<?php echo give_get_field_name( $field ); ?>" |
| 742 |
id="<?php echo esc_attr( $field['id'] ); ?>" |
| 743 |
value="<?php echo esc_attr( $field['cbvalue'] ); ?>" |
| 744 |
<?php echo checked( $field['value'], $field['cbvalue'], false ); ?> |
| 745 |
<?php echo give_get_attribute_str( $field ); ?> |
| 746 |
/> |
| 747 |
<?php |
| 748 |
echo give_get_field_description( $field ); |
| 749 |
echo '</p>'; |
| 750 |
} |
| 751 |
|
| 752 |
/** |
| 753 |
* Output multi checkbox input box. |
| 754 |
* |
| 755 |
* @since 2.9.0 |
| 756 |
* |
| 757 |
* @param array $field { |
| 758 |
* Optional. Array of checkbox field arguments. |
| 759 |
* |
| 760 |
* @type string $id Field ID. Default ''. |
| 761 |
* @type string $style CSS style for input field. Default ''. |
| 762 |
* @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 763 |
* @type string $value Value of input field. Default ''. |
| 764 |
* @type string $name Name of input field. Default ''. |
| 765 |
* @type string $description Description of input field. Default ''. |
| 766 |
* @type array $attributes List of attributes of input field. Default array(). |
| 767 |
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 768 |
* => '****' ) |
| 769 |
* @type array $options List of options. Default array(). |
| 770 |
* for example: 'options' => array( 'option1' => 'Option 1', 'option2' => |
| 771 |
* 'Option 2' ) |
| 772 |
* } |
| 773 |
* @return void |
| 774 |
*/ |
| 775 |
function give_multicheck( $field ) { |
| 776 |
global $thepostid, $post; |
| 777 |
|
| 778 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 779 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 780 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 781 |
$field['value'] = give_get_field_value( $field, $thepostid ); |
| 782 |
$field['value'] = is_array( $field['value'] ) ? $field['value'] : []; |
| 783 |
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 784 |
|
| 785 |
?> |
| 786 |
<fieldset class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>"> |
| 787 |
<span class="give-field-label"><?php echo wp_kses_post( $field['name'] ); ?></span> |
| 788 |
<legend class="screen-reader-text"><?php echo wp_kses_post( $field['name'] ); ?></legend> |
| 789 |
|
| 790 |
<ul> |
| 791 |
<?php foreach ( $field['options'] as $key => $value ) : ?> |
| 792 |
<li> |
| 793 |
<label> |
| 794 |
<input |
| 795 |
type="checkbox" |
| 796 |
name="<?php echo give_get_field_name( $field ); ?>[]" |
| 797 |
value="<?php echo esc_attr( $key ); ?>" |
| 798 |
style="<?php echo esc_attr( $field['style'] ); ?>" |
| 799 |
<?php echo give_get_attribute_str( $field ); ?> |
| 800 |
<?php |
| 801 |
if ( in_array( $key, $field['value'] ) ) { |
| 802 |
echo 'checked="checked"';} |
| 803 |
?> |
| 804 |
/> <?php echo esc_html( $value ); ?> |
| 805 |
</label> |
| 806 |
</li> |
| 807 |
<?php endforeach; ?> |
| 808 |
</ul> |
| 809 |
<?php echo give_get_field_description( $field ); ?> |
| 810 |
</fieldset> |
| 811 |
<?php |
| 812 |
} |
| 813 |
|
| 814 |
/** |
| 815 |
* Output a select input box. |
| 816 |
* |
| 817 |
* @since 1.8 |
| 818 |
* |
| 819 |
* @param array $field { |
| 820 |
* Optional. Array of select field arguments. |
| 821 |
* |
| 822 |
* @type string $id Field ID. Default ''. |
| 823 |
* @type string $style CSS style for input field. Default ''. |
| 824 |
* @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 825 |
* @type string $value Value of input field. Default ''. |
| 826 |
* @type string $name Name of input field. Default ''. |
| 827 |
* @type string $description Description of input field. Default ''. |
| 828 |
* @type array $attributes List of attributes of input field. Default array(). |
| 829 |
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 830 |
* => '****' ) |
| 831 |
* @type array $options List of options. Default array(). |
| 832 |
* for example: 'options' => array( '' => 'None', 'yes' => 'Yes' ) |
| 833 |
* } |
| 834 |
* @return void |
| 835 |
*/ |
| 836 |
function give_select( $field ) { |
| 837 |
global $thepostid, $post; |
| 838 |
|
| 839 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 840 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 841 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 842 |
$field['value'] = give_get_field_value( $field, $thepostid ); |
| 843 |
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 844 |
?> |
| 845 |
<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>"> |
| 846 |
<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label> |
| 847 |
<select |
| 848 |
id="<?php echo esc_attr( $field['id'] ); ?>" |
| 849 |
name="<?php echo give_get_field_name( $field ); ?>" |
| 850 |
style="<?php echo esc_attr( $field['style'] ); ?>" |
| 851 |
<?php echo give_get_attribute_str( $field ); ?> |
| 852 |
> |
| 853 |
<?php |
| 854 |
foreach ( $field['options'] as $key => $value ) { |
| 855 |
echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>'; |
| 856 |
} |
| 857 |
echo '</select>'; |
| 858 |
echo give_get_field_description( $field ); |
| 859 |
echo '</p>'; |
| 860 |
} |
| 861 |
|
| 862 |
/** |
| 863 |
* Output a radio input box. |
| 864 |
* |
| 865 |
* @since 1.8 |
| 866 |
* |
| 867 |
* @param array $field { |
| 868 |
* Optional. Array of radio field arguments. |
| 869 |
* |
| 870 |
* @type string $id Field ID. Default ''. |
| 871 |
* @type string $style CSS style for input field. Default ''. |
| 872 |
* @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 873 |
* @type string $value Value of input field. Default ''. |
| 874 |
* @type string $name Name of input field. Default ''. |
| 875 |
* @type string $description Description of input field. Default ''. |
| 876 |
* @type array $attributes List of attributes of input field. Default array(). |
| 877 |
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 878 |
* => '****' ) |
| 879 |
* @type array $options List of options. Default array(). |
| 880 |
* for example: 'options' => array( 'enable' => 'Enable', 'disable' => |
| 881 |
* 'Disable' ) |
| 882 |
* } |
| 883 |
* @return void |
| 884 |
*/ |
| 885 |
function give_radio( $field ) { |
| 886 |
global $thepostid, $post; |
| 887 |
|
| 888 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 889 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 890 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 891 |
$field['value'] = give_get_field_value( $field, $thepostid ); |
| 892 |
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 893 |
|
| 894 |
echo '<fieldset class="give-field-wrap ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><span class="give-field-label">' . wp_kses_post( $field['name'] ) . '</span><legend class="screen-reader-text">' . wp_kses_post( $field['name'] ) . '</legend><ul class="give-radios">'; |
| 895 |
|
| 896 |
foreach ( $field['options'] as $key => $value ) { |
| 897 |
|
| 898 |
echo '<li><label><input |
| 899 |
name="' . give_get_field_name( $field ) . '" |
| 900 |
value="' . esc_attr( $key ) . '" |
| 901 |
type="radio" |
| 902 |
style="' . esc_attr( $field['style'] ) . '" |
| 903 |
' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . ' ' |
| 904 |
. give_get_attribute_str( $field ) . ' |
| 905 |
/> ' . esc_html( $value ) . '</label> |
| 906 |
</li>'; |
| 907 |
} |
| 908 |
echo '</ul>'; |
| 909 |
|
| 910 |
echo give_get_field_description( $field ); |
| 911 |
echo '</fieldset>'; |
| 912 |
} |
| 913 |
|
| 914 |
/** |
| 915 |
* Output a multi-line radio input box. |
| 916 |
* |
| 917 |
* @since 2.9.0 |
| 918 |
* |
| 919 |
* @param array $field { |
| 920 |
* Optional. Array of radio field arguments. |
| 921 |
* |
| 922 |
* @type string $id Field ID. Default ''. |
| 923 |
* @type string $style CSS style for input field. Default ''. |
| 924 |
* @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 925 |
* @type string $value Value of input field. Default ''. |
| 926 |
* @type string $name Name of input field. Default ''. |
| 927 |
* @type string $description Description of input field. Default ''. |
| 928 |
* @type array $attributes List of attributes of input field. Default array(). |
| 929 |
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 930 |
* => '****' ) |
| 931 |
* @type array $options List of options. Default array(). |
| 932 |
* for example: 'options' => array( 'enable' => [ 'label' => 'Enable', 'description' => 'Description' ] ) |
| 933 |
* } |
| 934 |
* @return void |
| 935 |
*/ |
| 936 |
function give_multiradio( $field ) { |
| 937 |
global $thepostid, $post; |
| 938 |
|
| 939 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 940 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 941 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 942 |
$field['value'] = give_get_field_value( $field, $thepostid ); |
| 943 |
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 944 |
?> |
| 945 |
|
| 946 |
<fieldset class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>"> |
| 947 |
<span class="give-field-label"><?php echo wp_kses_post( $field['name'] ); ?></span> |
| 948 |
<legend class="screen-reader-text"><?php echo wp_kses_post( $field['name'] ); ?></legend> |
| 949 |
|
| 950 |
|
| 951 |
<ul class="give-radios"> |
| 952 |
<?php foreach ( $field['options'] as $key => $data ) : ?> |
| 953 |
<li> |
| 954 |
<label> |
| 955 |
<input |
| 956 |
type="radio" |
| 957 |
name="<?php echo give_get_field_name( $field ); ?>" |
| 958 |
value="<?php echo esc_attr( $key ); ?>" |
| 959 |
style="<?php echo esc_attr( $field['style'] ); ?>" |
| 960 |
<?php echo checked( esc_attr( $field['value'] ), esc_attr( $key ), false ); ?> |
| 961 |
<?php echo give_get_attribute_str( $field ); ?> |
| 962 |
/> <?php echo esc_html( $data['label'] ); ?> |
| 963 |
</label> |
| 964 |
<?php if ( isset( $data['description'] ) ) : ?> |
| 965 |
<span class="give-field-description"> |
| 966 |
<?php echo wp_kses_post( $data['description'] ); ?> |
| 967 |
</span> |
| 968 |
<?php endif; ?> |
| 969 |
</li> |
| 970 |
<?php endforeach; ?> |
| 971 |
</ul> |
| 972 |
<?php echo give_get_field_description( $field ); ?> |
| 973 |
</fieldset> |
| 974 |
<?php |
| 975 |
} |
| 976 |
|
| 977 |
/** |
| 978 |
* Output a colorpicker. |
| 979 |
* |
| 980 |
* @since 1.8 |
| 981 |
* |
| 982 |
* @param array $field { |
| 983 |
* Optional. Array of colorpicker field arguments. |
| 984 |
* |
| 985 |
* @type string $id Field ID. Default ''. |
| 986 |
* @type string $style CSS style for input field. Default ''. |
| 987 |
* @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 988 |
* @type string $value Value of input field. Default ''. |
| 989 |
* @type string $name Name of input field. Default ''. |
| 990 |
* @type string $description Description of input field. Default ''. |
| 991 |
* @type array $attributes List of attributes of input field. Default array(). |
| 992 |
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 993 |
* => '****' ) |
| 994 |
* } |
| 995 |
* @return void |
| 996 |
*/ |
| 997 |
function give_colorpicker( $field ) { |
| 998 |
global $thepostid, $post; |
| 999 |
|
| 1000 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 1001 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 1002 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 1003 |
$field['value'] = give_get_field_value( $field, $thepostid ); |
| 1004 |
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 1005 |
$field['type'] = 'text'; |
| 1006 |
?> |
| 1007 |
<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>"> |
| 1008 |
<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label> |
| 1009 |
<input |
| 1010 |
type="<?php echo esc_attr( $field['type'] ); ?>" |
| 1011 |
style="<?php echo esc_attr( $field['style'] ); ?>" |
| 1012 |
name="<?php echo give_get_field_name( $field ); ?>" |
| 1013 |
id="<?php echo esc_attr( $field['id'] ); ?>" |
| 1014 |
value="<?php echo esc_attr( $field['value'] ); ?>" |
| 1015 |
<?php echo give_get_attribute_str( $field ); ?> |
| 1016 |
/> |
| 1017 |
<?php |
| 1018 |
echo give_get_field_description( $field ); |
| 1019 |
echo '</p>'; |
| 1020 |
} |
| 1021 |
|
| 1022 |
/** |
| 1023 |
* Output a file upload field. |
| 1024 |
* |
| 1025 |
* @since 1.8.9 |
| 1026 |
* |
| 1027 |
* @param array $field |
| 1028 |
*/ |
| 1029 |
function give_file( $field ) { |
| 1030 |
give_media( $field ); |
| 1031 |
} |
| 1032 |
|
| 1033 |
|
| 1034 |
/** |
| 1035 |
* Output a media upload field. |
| 1036 |
* |
| 1037 |
* @since 1.8 |
| 1038 |
* |
| 1039 |
* @param array $field |
| 1040 |
*/ |
| 1041 |
function give_media( $field ) { |
| 1042 |
global $thepostid, $post; |
| 1043 |
|
| 1044 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 1045 |
$button_label = sprintf( __( 'Add or Upload %s', 'give' ), ( 'file' === $field['type'] ? __( 'File', 'give' ) : __( 'Image', 'give' ) ) ); |
| 1046 |
|
| 1047 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 1048 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 1049 |
$field['value'] = give_get_field_value( $field, $thepostid ); |
| 1050 |
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 1051 |
$field['attributes']['class'] = "{$field['attributes']['class']} give-text-medium"; |
| 1052 |
|
| 1053 |
// Allow developer to save attachment ID or attachment url as metadata. |
| 1054 |
$field['fvalue'] = isset( $field['fvalue'] ) ? $field['fvalue'] : 'url'; |
| 1055 |
|
| 1056 |
$allow_media_preview_tags = [ 'jpg', 'jpeg', 'png', 'gif', 'ico' ]; |
| 1057 |
$preview_image_src = $field['value'] ? ( 'id' === $field['fvalue'] ? wp_get_attachment_url( $field['value'] ) : $field['value'] ) : '#'; |
| 1058 |
$preview_image_extension = $preview_image_src ? pathinfo( $preview_image_src, PATHINFO_EXTENSION ) : ''; |
| 1059 |
$is_show_preview = in_array( $preview_image_extension, $allow_media_preview_tags ); |
| 1060 |
?> |
| 1061 |
<fieldset class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>"> |
| 1062 |
<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label> |
| 1063 |
<input |
| 1064 |
name="<?php echo give_get_field_name( $field ); ?>" |
| 1065 |
id="<?php echo esc_attr( $field['id'] ); ?>" |
| 1066 |
type="text" |
| 1067 |
value="<?php echo $field['value']; ?>" |
| 1068 |
style="<?php echo esc_attr( $field['style'] ); ?>" |
| 1069 |
<?php echo give_get_attribute_str( $field ); ?> |
| 1070 |
/> <input class="give-upload-button button" type="button" value="<?php echo $button_label; ?>" data-fvalue="<?php echo $field['fvalue']; ?>" data-field-type="<?php echo $field['type']; ?>"> |
| 1071 |
<?php echo give_get_field_description( $field ); ?> |
| 1072 |
<div class="give-image-thumb<?php echo ! $field['value'] || ! $is_show_preview ? ' give-hidden' : ''; ?>"> |
| 1073 |
<span class="give-delete-image-thumb dashicons dashicons-no-alt"></span> |
| 1074 |
<img src="<?php echo $preview_image_src; ?>" alt=""> |
| 1075 |
</div> |
| 1076 |
</fieldset> |
| 1077 |
<?php |
| 1078 |
} |
| 1079 |
|
| 1080 |
/** |
| 1081 |
* Output a select field with payment options list. |
| 1082 |
* |
| 1083 |
* @since 1.8 |
| 1084 |
* |
| 1085 |
* @param array $field |
| 1086 |
* |
| 1087 |
* @return void |
| 1088 |
*/ |
| 1089 |
function give_default_gateway( $field ) { |
| 1090 |
global $thepostid, $post; |
| 1091 |
|
| 1092 |
// get all active payment gateways. |
| 1093 |
$gateways = give_get_enabled_payment_gateways( $thepostid ); |
| 1094 |
$field['options'] = []; |
| 1095 |
|
| 1096 |
// Set field option value. |
| 1097 |
if ( ! empty( $gateways ) ) { |
| 1098 |
foreach ( $gateways as $key => $option ) { |
| 1099 |
$field['options'][ $key ] = $option['admin_label']; |
| 1100 |
} |
| 1101 |
} |
| 1102 |
|
| 1103 |
// Add a field to the Give Form admin single post view of this field |
| 1104 |
if ( is_object( $post ) && 'give_forms' === $post->post_type ) { |
| 1105 |
$field['options'] = array_merge( [ 'global' => esc_html__( 'Global Default', 'give' ) ], $field['options'] ); |
| 1106 |
} |
| 1107 |
|
| 1108 |
// Render select field. |
| 1109 |
give_select( $field ); |
| 1110 |
} |
| 1111 |
|
| 1112 |
/** |
| 1113 |
* Output the documentation link. |
| 1114 |
* |
| 1115 |
* @since 1.8 |
| 1116 |
* |
| 1117 |
* @param array $field { |
| 1118 |
* Optional. Array of customizable link attributes. |
| 1119 |
* |
| 1120 |
* @type string $name Name of input field. Default ''. |
| 1121 |
* @type string $type Type of input field. Default 'text'. |
| 1122 |
* @type string $url Value to be passed as a link. Default 'https://givewp.com/documentation'. |
| 1123 |
* @type string $title Value to be passed as text of link. Default 'Documentation'. |
| 1124 |
* @type array $attributes List of attributes of input field. Default array(). |
| 1125 |
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 1126 |
* => '****' ) |
| 1127 |
* } |
| 1128 |
* @return void |
| 1129 |
*/ |
| 1130 |
|
| 1131 |
function give_docs_link( $field ) { |
| 1132 |
$field['url'] = isset( $field['url'] ) ? $field['url'] : 'https://givewp.com/documentation'; |
| 1133 |
$field['title'] = isset( $field['title'] ) ? $field['title'] : 'Documentation'; |
| 1134 |
|
| 1135 |
echo '<p class="give-docs-link"><a href="' . esc_url( $field['url'] ) |
| 1136 |
. '" target="_blank">' |
| 1137 |
. sprintf( esc_html__( 'Need Help? See docs on "%s"', 'give' ), $field['title'] ) |
| 1138 |
. '<span class="dashicons dashicons-editor-help"></span></a></p>'; |
| 1139 |
} |
| 1140 |
|
| 1141 |
|
| 1142 |
/** |
| 1143 |
* Output preview buttons. |
| 1144 |
* |
| 1145 |
* @since 2.0 |
| 1146 |
* |
| 1147 |
* @param $field |
| 1148 |
*/ |
| 1149 |
function give_email_preview_buttons( $field ) { |
| 1150 |
/* @var WP_Post $post */ |
| 1151 |
global $post; |
| 1152 |
|
| 1153 |
$field_id = str_replace( [ '_give_', '_preview_buttons' ], '', $field['id'] ); |
| 1154 |
|
| 1155 |
ob_start(); |
| 1156 |
|
| 1157 |
echo '<p class="give-field-wrap ' . esc_attr( $field['id'] ) . '_field"><label for="' . give_get_field_name( $field ) . '">' . wp_kses_post( $field['name'] ) . '</label>'; |
| 1158 |
|
| 1159 |
echo sprintf( |
| 1160 |
'<a href="%1$s" class="button-secondary" target="_blank">%2$s</a>', |
| 1161 |
esc_url( |
| 1162 |
wp_nonce_url( |
| 1163 |
add_query_arg( |
| 1164 |
[ |
| 1165 |
'give_action' => 'preview_email', |
| 1166 |
'email_type' => $field_id, |
| 1167 |
'form_id' => $post->ID, |
| 1168 |
], |
| 1169 |
home_url() |
| 1170 |
), |
| 1171 |
'give-preview-email' |
| 1172 |
) |
| 1173 |
), |
| 1174 |
$field['name'] |
| 1175 |
); |
| 1176 |
|
| 1177 |
echo sprintf( |
| 1178 |
' <a href="%1$s" aria-label="%2$s" class="button-secondary">%3$s</a>', |
| 1179 |
esc_url( |
| 1180 |
wp_nonce_url( |
| 1181 |
add_query_arg( |
| 1182 |
[ |
| 1183 |
'give_action' => 'send_preview_email', |
| 1184 |
'email_type' => $field_id, |
| 1185 |
'give-messages[]' => 'sent-test-email', |
| 1186 |
'form_id' => $post->ID, |
| 1187 |
] |
| 1188 |
), |
| 1189 |
'give-send-preview-email' |
| 1190 |
) |
| 1191 |
), |
| 1192 |
esc_attr__( 'Send Test Email.', 'give' ), |
| 1193 |
esc_html__( 'Send Test Email', 'give' ) |
| 1194 |
); |
| 1195 |
|
| 1196 |
if ( ! empty( $field['description'] ) ) { |
| 1197 |
echo '<span class="give-field-description">' . wp_kses_post( $field['desc'] ) . '</span>'; |
| 1198 |
} |
| 1199 |
|
| 1200 |
echo '</p>'; |
| 1201 |
|
| 1202 |
echo ob_get_clean(); |
| 1203 |
} |
| 1204 |
|
| 1205 |
/** |
| 1206 |
* Get setting field value. |
| 1207 |
* |
| 1208 |
* Note: Use only for single post, page or custom post type. |
| 1209 |
* |
| 1210 |
* @since 1.8 |
| 1211 |
* @since 2.1 Added support for donation_limit. |
| 1212 |
* |
| 1213 |
* @param array $field |
| 1214 |
* @param int $postid |
| 1215 |
* |
| 1216 |
* @return mixed |
| 1217 |
*/ |
| 1218 |
function give_get_field_value( $field, $postid ) { |
| 1219 |
if ( isset( $field['attributes']['value'] ) ) { |
| 1220 |
return $field['attributes']['value']; |
| 1221 |
} |
| 1222 |
|
| 1223 |
// If field is range slider. |
| 1224 |
if ( 'donation_limit' === $field['type'] ) { |
| 1225 |
|
| 1226 |
// Get minimum value. |
| 1227 |
$minimum = give_get_meta( $postid, $field['id'] . '_minimum', true ); |
| 1228 |
|
| 1229 |
// Give < 2.1 |
| 1230 |
if ( '_give_custom_amount_range' === $field['id'] && empty( $minimum ) ) { |
| 1231 |
$minimum = give_get_meta( $postid, '_give_custom_amount_minimum', true ); |
| 1232 |
} |
| 1233 |
|
| 1234 |
$field_value = [ |
| 1235 |
'minimum' => $minimum, |
| 1236 |
'maximum' => give_get_meta( $postid, $field['id'] . '_maximum', true ), |
| 1237 |
]; |
| 1238 |
} else { |
| 1239 |
// Get value from db. |
| 1240 |
$field_value = give_get_meta( $postid, $field['id'], true ); |
| 1241 |
} |
| 1242 |
|
| 1243 |
/** |
| 1244 |
* Filter the field value before apply default value. |
| 1245 |
* |
| 1246 |
* @since 1.8 |
| 1247 |
* |
| 1248 |
* @param mixed $field_value Field value. |
| 1249 |
*/ |
| 1250 |
$field_value = apply_filters( "{$field['id']}_field_value", $field_value, $field, $postid ); |
| 1251 |
|
| 1252 |
// Set default value if no any data saved to db. |
| 1253 |
if ( ! $field_value && isset( $field['default'] ) ) { |
| 1254 |
$field_value = $field['default']; |
| 1255 |
} |
| 1256 |
|
| 1257 |
return $field_value; |
| 1258 |
} |
| 1259 |
|
| 1260 |
|
| 1261 |
/** |
| 1262 |
* Get field description html. |
| 1263 |
* |
| 1264 |
* @since 1.8 |
| 1265 |
* |
| 1266 |
* @param $field |
| 1267 |
* |
| 1268 |
* @return string |
| 1269 |
*/ |
| 1270 |
function give_get_field_description( $field ) { |
| 1271 |
$field_desc_html = ''; |
| 1272 |
$description = ''; |
| 1273 |
|
| 1274 |
// Check for both `description` and `desc`. |
| 1275 |
if ( isset( $field['description'] ) ) { |
| 1276 |
$description = $field['description']; |
| 1277 |
} elseif ( isset( $field['desc'] ) ) { |
| 1278 |
$description = $field['desc']; |
| 1279 |
} |
| 1280 |
|
| 1281 |
// Set if there is a description. |
| 1282 |
if ( ! empty( $description ) ) { |
| 1283 |
$field_desc_html = '<span class="give-field-description">' . wp_kses_post( $description ) . '</span>'; |
| 1284 |
} |
| 1285 |
|
| 1286 |
return $field_desc_html; |
| 1287 |
} |
| 1288 |
|
| 1289 |
|
| 1290 |
/** |
| 1291 |
* Get repeater field value. |
| 1292 |
* |
| 1293 |
* Note: Use only for single post, page or custom post type. |
| 1294 |
* |
| 1295 |
* @since 1.8 |
| 1296 |
* |
| 1297 |
* @param array $field |
| 1298 |
* @param array $field_group |
| 1299 |
* @param array $fields |
| 1300 |
* |
| 1301 |
* @return string |
| 1302 |
*/ |
| 1303 |
function give_get_repeater_field_value( $field, $field_group, $fields ) { |
| 1304 |
$field_value = ( isset( $field_group[ $field['id'] ] ) ? $field_group[ $field['id'] ] : '' ); |
| 1305 |
|
| 1306 |
/** |
| 1307 |
* Filter the specific repeater field value |
| 1308 |
* |
| 1309 |
* @since 1.8 |
| 1310 |
* |
| 1311 |
* @param string $field_id |
| 1312 |
*/ |
| 1313 |
$field_value = apply_filters( "give_get_repeater_field_{$field['id']}_value", $field_value, $field, $field_group, $fields ); |
| 1314 |
|
| 1315 |
/** |
| 1316 |
* Filter the repeater field value |
| 1317 |
* |
| 1318 |
* @since 1.8 |
| 1319 |
* |
| 1320 |
* @param string $field_id |
| 1321 |
*/ |
| 1322 |
$field_value = apply_filters( 'give_get_repeater_field_value', $field_value, $field, $field_group, $fields ); |
| 1323 |
|
| 1324 |
return $field_value; |
| 1325 |
} |
| 1326 |
|
| 1327 |
/** |
| 1328 |
* Get repeater field id. |
| 1329 |
* |
| 1330 |
* Note: Use only for single post, page or custom post type. |
| 1331 |
* |
| 1332 |
* @since 1.8 |
| 1333 |
* |
| 1334 |
* @param array $field |
| 1335 |
* @param array $fields |
| 1336 |
* @param int|bool $default |
| 1337 |
* |
| 1338 |
* @return string |
| 1339 |
*/ |
| 1340 |
function give_get_repeater_field_id( $field, $fields, $default = false ) { |
| 1341 |
$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}'; |
| 1342 |
|
| 1343 |
// Get field id. |
| 1344 |
$field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}]"; |
| 1345 |
|
| 1346 |
/** |
| 1347 |
* Filter the specific repeater field id |
| 1348 |
* |
| 1349 |
* @since 1.8 |
| 1350 |
* |
| 1351 |
* @param string $field_id |
| 1352 |
*/ |
| 1353 |
$field_id = apply_filters( "give_get_repeater_field_{$field['id']}_id", $field_id, $field, $fields, $default ); |
| 1354 |
|
| 1355 |
/** |
| 1356 |
* Filter the repeater field id |
| 1357 |
* |
| 1358 |
* @since 1.8 |
| 1359 |
* |
| 1360 |
* @param string $field_id |
| 1361 |
*/ |
| 1362 |
$field_id = apply_filters( 'give_get_repeater_field_id', $field_id, $field, $fields, $default ); |
| 1363 |
|
| 1364 |
return $field_id; |
| 1365 |
} |
| 1366 |
|
| 1367 |
|
| 1368 |
/** |
| 1369 |
* Get field name. |
| 1370 |
* |
| 1371 |
* @since 1.8 |
| 1372 |
* |
| 1373 |
* @param array $field |
| 1374 |
* |
| 1375 |
* @return string |
| 1376 |
*/ |
| 1377 |
function give_get_field_name( $field ) { |
| 1378 |
$field_name = esc_attr( empty( $field['repeat'] ) ? $field['id'] : $field['repeatable_field_id'] ); |
| 1379 |
|
| 1380 |
/** |
| 1381 |
* Filter the field name. |
| 1382 |
* |
| 1383 |
* @since 1.8 |
| 1384 |
* |
| 1385 |
* @param string $field_name |
| 1386 |
*/ |
| 1387 |
$field_name = apply_filters( 'give_get_field_name', $field_name, $field ); |
| 1388 |
|
| 1389 |
return $field_name; |
| 1390 |
} |
| 1391 |
|
| 1392 |
/** |
| 1393 |
* Output repeater field or multi donation type form on donation from edit screen. |
| 1394 |
* Note: internal use only. |
| 1395 |
* |
| 1396 |
* @TODO : Add support for wysiwyg type field. |
| 1397 |
* |
| 1398 |
* @since 1.8 |
| 1399 |
* |
| 1400 |
* @param array $fields |
| 1401 |
* |
| 1402 |
* @return void |
| 1403 |
*/ |
| 1404 |
function _give_metabox_form_data_repeater_fields( $fields ) { |
| 1405 |
global $thepostid, $post; |
| 1406 |
|
| 1407 |
// Bailout. |
| 1408 |
if ( ! isset( $fields['fields'] ) || empty( $fields['fields'] ) ) { |
| 1409 |
return; |
| 1410 |
} |
| 1411 |
|
| 1412 |
$group_numbering = isset( $fields['options']['group_numbering'] ) ? (int) $fields['options']['group_numbering'] : 0; |
| 1413 |
$close_tabs = isset( $fields['options']['close_tabs'] ) ? (int) $fields['options']['close_tabs'] : 0; |
| 1414 |
$wrapper_class = isset( $fields['wrapper_class'] ) ? $fields['wrapper_class'] : ''; |
| 1415 |
?> |
| 1416 |
<div class="give-repeatable-field-section <?php echo esc_attr( $wrapper_class ); ?>" id="<?php echo "{$fields['id']}_field"; ?>" |
| 1417 |
data-group-numbering="<?php echo $group_numbering; ?>" data-close-tabs="<?php echo $close_tabs; ?>"> |
| 1418 |
<?php if ( ! empty( $fields['name'] ) ) : ?> |
| 1419 |
<p class="give-repeater-field-name"><?php echo $fields['name']; ?></p> |
| 1420 |
<?php endif; ?> |
| 1421 |
|
| 1422 |
<?php if ( ! empty( $fields['description'] ) ) : ?> |
| 1423 |
<p class="give-repeater-field-description"><?php echo $fields['description']; ?></p> |
| 1424 |
<?php endif; ?> |
| 1425 |
|
| 1426 |
<table class="give-repeatable-fields-section-wrapper" cellspacing="0"> |
| 1427 |
<?php |
| 1428 |
// Get value. |
| 1429 |
$repeater_field_values = ! empty( $fields['attributes']['value'] ) |
| 1430 |
? $fields['attributes']['value'] |
| 1431 |
: give_get_meta( $thepostid, $fields['id'], true ); |
| 1432 |
|
| 1433 |
// Setup default value. |
| 1434 |
if ( empty( $repeater_field_values ) && ! empty( $fields['default'] ) ) { |
| 1435 |
$repeater_field_values = $fields['default']; |
| 1436 |
} |
| 1437 |
|
| 1438 |
$header_title = isset( $fields['options']['header_title'] ) |
| 1439 |
? $fields['options']['header_title'] |
| 1440 |
: esc_attr__( 'Group', 'give' ); |
| 1441 |
|
| 1442 |
$add_default_donation_field = false; |
| 1443 |
|
| 1444 |
// Check if level is not created or we have to add default level. |
| 1445 |
if ( is_array( $repeater_field_values ) && ( $fields_count = count( $repeater_field_values ) ) ) { |
| 1446 |
$repeater_field_values = array_values( $repeater_field_values ); |
| 1447 |
} else { |
| 1448 |
$fields_count = 1; |
| 1449 |
$add_default_donation_field = true; |
| 1450 |
} |
| 1451 |
?> |
| 1452 |
<tbody class="container"<?php echo " data-rf-row-count=\"{$fields_count}\""; ?>> |
| 1453 |
<!--Repeater field group template--> |
| 1454 |
<tr class="give-template give-row"> |
| 1455 |
<td class="give-repeater-field-wrap give-column" colspan="2"> |
| 1456 |
<div class="give-row-head give-move"> |
| 1457 |
<button type="button" class="give-handlediv button-link"><span class="toggle-indicator"></span> |
| 1458 |
</button> |
| 1459 |
<span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-</span> |
| 1460 |
<h2> |
| 1461 |
<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span> |
| 1462 |
</h2> |
| 1463 |
</div> |
| 1464 |
<div class="give-row-body"> |
| 1465 |
<?php foreach ( $fields['fields'] as $field ) : ?> |
| 1466 |
<?php |
| 1467 |
if ( ! give_is_field_callback_exist( $field ) ) { |
| 1468 |
continue; |
| 1469 |
} |
| 1470 |
?> |
| 1471 |
<?php |
| 1472 |
$field['repeat'] = true; |
| 1473 |
$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields ); |
| 1474 |
$field['id'] = str_replace( |
| 1475 |
[ '[', ']' ], |
| 1476 |
[ '_', '' ], |
| 1477 |
$field['repeatable_field_id'] |
| 1478 |
); |
| 1479 |
?> |
| 1480 |
<?php give_render_field( $field ); ?> |
| 1481 |
<?php endforeach; ?> |
| 1482 |
</div> |
| 1483 |
</td> |
| 1484 |
</tr> |
| 1485 |
|
| 1486 |
<?php if ( ! empty( $repeater_field_values ) ) : ?> |
| 1487 |
<!--Stored repeater field group--> |
| 1488 |
<?php foreach ( $repeater_field_values as $index => $field_group ) : ?> |
| 1489 |
<tr class="give-row"> |
| 1490 |
<td class="give-repeater-field-wrap give-column" colspan="2"> |
| 1491 |
<div class="give-row-head give-move"> |
| 1492 |
<button type="button" class="give-handlediv button-link"> |
| 1493 |
<span class="toggle-indicator"></span></button> |
| 1494 |
<span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">- |
| 1495 |
</span> |
| 1496 |
<h2> |
| 1497 |
<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span> |
| 1498 |
</h2> |
| 1499 |
</div> |
| 1500 |
<div class="give-row-body"> |
| 1501 |
<?php foreach ( $fields['fields'] as $field ) : ?> |
| 1502 |
<?php |
| 1503 |
if ( ! give_is_field_callback_exist( $field ) ) { |
| 1504 |
continue; |
| 1505 |
} |
| 1506 |
?> |
| 1507 |
<?php |
| 1508 |
$field['repeat'] = true; |
| 1509 |
$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, $index ); |
| 1510 |
$field['attributes']['value'] = give_get_repeater_field_value( $field, $field_group, $fields ); |
| 1511 |
$field['id'] = str_replace( |
| 1512 |
[ '[', ']' ], |
| 1513 |
[ '_', '' ], |
| 1514 |
$field['repeatable_field_id'] |
| 1515 |
); |
| 1516 |
?> |
| 1517 |
<?php give_render_field( $field ); ?> |
| 1518 |
<?php endforeach; ?> |
| 1519 |
</div> |
| 1520 |
</td> |
| 1521 |
</tr> |
| 1522 |
<?php |
| 1523 |
endforeach; |
| 1524 |
?> |
| 1525 |
|
| 1526 |
<?php elseif ( $add_default_donation_field ) : ?> |
| 1527 |
<!--Default repeater field group--> |
| 1528 |
<tr class="give-row"> |
| 1529 |
<td class="give-repeater-field-wrap give-column" colspan="2"> |
| 1530 |
<div class="give-row-head give-move"> |
| 1531 |
<button type="button" class="give-handlediv button-link"> |
| 1532 |
<span class="toggle-indicator"></span></button> |
| 1533 |
<span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">- |
| 1534 |
</span> |
| 1535 |
<h2> |
| 1536 |
<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span> |
| 1537 |
</h2> |
| 1538 |
</div> |
| 1539 |
<div class="give-row-body"> |
| 1540 |
<?php |
| 1541 |
foreach ( $fields['fields'] as $field ) : |
| 1542 |
if ( ! give_is_field_callback_exist( $field ) ) { |
| 1543 |
continue; |
| 1544 |
} |
| 1545 |
|
| 1546 |
$field['repeat'] = true; |
| 1547 |
$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, 0 ); |
| 1548 |
$field['attributes']['value'] = apply_filters( |
| 1549 |
"give_default_field_group_field_{$field['id']}_value", |
| 1550 |
( ! empty( $field['default'] ) ? $field['default'] : '' ), |
| 1551 |
$field, |
| 1552 |
$fields |
| 1553 |
); |
| 1554 |
$field['id'] = str_replace( |
| 1555 |
[ '[', ']' ], |
| 1556 |
[ '_', '' ], |
| 1557 |
$field['repeatable_field_id'] |
| 1558 |
); |
| 1559 |
give_render_field( $field ); |
| 1560 |
|
| 1561 |
endforeach; |
| 1562 |
?> |
| 1563 |
</div> |
| 1564 |
</td> |
| 1565 |
</tr> |
| 1566 |
<?php endif; ?> |
| 1567 |
</tbody> |
| 1568 |
<tfoot> |
| 1569 |
<tr> |
| 1570 |
<?php |
| 1571 |
$add_row_btn_title = isset( $fields['options']['add_button'] ) |
| 1572 |
? $add_row_btn_title = $fields['options']['add_button'] |
| 1573 |
: esc_html__( 'Add Row', 'give' ); |
| 1574 |
?> |
| 1575 |
<td colspan="2" class="give-add-repeater-field-section-row-wrap"> |
| 1576 |
<span class="button button-primary give-add-repeater-field-section-row"><?php echo $add_row_btn_title; ?></span> |
| 1577 |
</td> |
| 1578 |
</tr> |
| 1579 |
</tfoot> |
| 1580 |
</table> |
| 1581 |
</div> |
| 1582 |
<?php |
| 1583 |
} |
| 1584 |
|
| 1585 |
|
| 1586 |
/** |
| 1587 |
* Set repeater field id for multi donation form. |
| 1588 |
* |
| 1589 |
* @since 1.8 |
| 1590 |
* |
| 1591 |
* @param int $field_id |
| 1592 |
* @param array $field |
| 1593 |
* @param array $fields |
| 1594 |
* @param bool $default |
| 1595 |
* |
| 1596 |
* @return mixed |
| 1597 |
*/ |
| 1598 |
function _give_set_multi_level_repeater_field_id( $field_id, $field, $fields, $default ) { |
| 1599 |
$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}'; |
| 1600 |
$field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}][level_id]"; |
| 1601 |
|
| 1602 |
return $field_id; |
| 1603 |
} |
| 1604 |
|
| 1605 |
add_filter( 'give_get_repeater_field__give_id_id', '_give_set_multi_level_repeater_field_id', 10, 4 ); |
| 1606 |
|
| 1607 |
/** |
| 1608 |
* Set repeater field value for multi donation form. |
| 1609 |
* |
| 1610 |
* @since 1.8 |
| 1611 |
* |
| 1612 |
* @param string $field_value |
| 1613 |
* @param array $field |
| 1614 |
* @param array $field_group |
| 1615 |
* @param array $fields |
| 1616 |
* |
| 1617 |
* @return mixed |
| 1618 |
*/ |
| 1619 |
function _give_set_multi_level_repeater_field_value( $field_value, $field, $field_group, $fields ) { |
| 1620 |
$field_value = $field_group[ $field['id'] ]['level_id']; |
| 1621 |
|
| 1622 |
return $field_value; |
| 1623 |
} |
| 1624 |
|
| 1625 |
add_filter( 'give_get_repeater_field__give_id_value', '_give_set_multi_level_repeater_field_value', 10, 4 ); |
| 1626 |
|
| 1627 |
/** |
| 1628 |
* Set default value for _give_id field. |
| 1629 |
* |
| 1630 |
* @since 1.8 |
| 1631 |
* |
| 1632 |
* @param $field |
| 1633 |
* |
| 1634 |
* @return string |
| 1635 |
*/ |
| 1636 |
function _give_set_field_give_id_default_value( $field ) { |
| 1637 |
return 0; |
| 1638 |
} |
| 1639 |
|
| 1640 |
add_filter( 'give_default_field_group_field__give_id_value', '_give_set_field_give_id_default_value' ); |
| 1641 |
|
| 1642 |
/** |
| 1643 |
* Set default value for _give_default field. |
| 1644 |
* |
| 1645 |
* @since 1.8 |
| 1646 |
* |
| 1647 |
* @param $field |
| 1648 |
* |
| 1649 |
* @return string |
| 1650 |
*/ |
| 1651 |
function _give_set_field_give_default_default_value( $field ) { |
| 1652 |
return 'default'; |
| 1653 |
} |
| 1654 |
|
| 1655 |
add_filter( 'give_default_field_group_field__give_default_value', '_give_set_field_give_default_default_value' ); |
| 1656 |
|
| 1657 |
/** |
| 1658 |
* Set repeater field editor id for field type wysiwyg. |
| 1659 |
* |
| 1660 |
* @since 1.8 |
| 1661 |
* |
| 1662 |
* @param $field_name |
| 1663 |
* @param $field |
| 1664 |
* |
| 1665 |
* @return string |
| 1666 |
*/ |
| 1667 |
function give_repeater_field_set_editor_id( $field_name, $field ) { |
| 1668 |
if ( isset( $field['repeatable_field_id'] ) && 'wysiwyg' == $field['type'] ) { |
| 1669 |
$field_name = '_give_repeater_' . uniqid() . '_wysiwyg'; |
| 1670 |
} |
| 1671 |
|
| 1672 |
return $field_name; |
| 1673 |
} |
| 1674 |
|
| 1675 |
add_filter( 'give_get_field_name', 'give_repeater_field_set_editor_id', 10, 2 ); |
| 1676 |
|
| 1677 |
/** |
| 1678 |
* Output Donation form radio input box. |
| 1679 |
* |
| 1680 |
* @since 2.1.3 |
| 1681 |
* |
| 1682 |
* @param array $field { |
| 1683 |
* Optional. Array of radio field arguments. |
| 1684 |
* |
| 1685 |
* @type string $id Field ID. Default ''. |
| 1686 |
* @type string $style CSS style for input field. Default ''. |
| 1687 |
* @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 1688 |
* @type string $value Value of input field. Default ''. |
| 1689 |
* @type string $name Name of input field. Default ''. |
| 1690 |
* @type string $description Description of input field. Default ''. |
| 1691 |
* @type array $attributes List of attributes of input field. Default array(). |
| 1692 |
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 1693 |
* => '****' ) |
| 1694 |
* @type array $options List of options. Default array(). |
| 1695 |
* for example: 'options' => array( 'enable' => 'Enable', 'disable' => |
| 1696 |
* 'Disable' ) |
| 1697 |
* } |
| 1698 |
* @return void |
| 1699 |
*/ |
| 1700 |
function give_donation_form_goal( $field ) { |
| 1701 |
global $thepostid, $post; |
| 1702 |
|
| 1703 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 1704 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 1705 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 1706 |
$field['value'] = give_get_field_value( $field, $thepostid ); |
| 1707 |
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 1708 |
|
| 1709 |
printf( |
| 1710 |
'<fieldset class="give-field-wrap %s_field %s">', |
| 1711 |
esc_attr( $field['id'] ), |
| 1712 |
esc_attr( $field['wrapper_class'] ) |
| 1713 |
); |
| 1714 |
|
| 1715 |
printf( |
| 1716 |
'<span class="give-field-label">%s</span>', |
| 1717 |
esc_html( $field['name'] ) |
| 1718 |
); |
| 1719 |
|
| 1720 |
printf( |
| 1721 |
'<legend class="screen-reader-text">%s</legend>', |
| 1722 |
esc_html( $field['name'] ) |
| 1723 |
); |
| 1724 |
?> |
| 1725 |
|
| 1726 |
<ul class="give-radios"> |
| 1727 |
<?php |
| 1728 |
foreach ( $field['options'] as $key => $value ) { |
| 1729 |
$attributes = empty( $field['attributes'] ) ? '' : give_get_attribute_str( $field['attributes'] ); |
| 1730 |
printf( |
| 1731 |
'<li><label><input name="%s" value="%s" type="radio" style="%s" %s %s /> %s </label></li>', |
| 1732 |
give_get_field_name( $field ), |
| 1733 |
esc_attr( $key ), |
| 1734 |
esc_attr( $field['style'] ), |
| 1735 |
checked( esc_attr( $field['value'] ), esc_attr( $key ), false ), |
| 1736 |
$attributes, |
| 1737 |
esc_html( $value ) |
| 1738 |
); |
| 1739 |
} |
| 1740 |
?> |
| 1741 |
</ul> |
| 1742 |
|
| 1743 |
<?php |
| 1744 |
/** |
| 1745 |
* Action to add HTML after donation form radio button is display and before description. |
| 1746 |
* |
| 1747 |
* @since 2.1.3 |
| 1748 |
* |
| 1749 |
* @param array $field Array of radio field arguments. |
| 1750 |
*/ |
| 1751 |
do_action( 'give_donation_form_goal_before_description', $field ); |
| 1752 |
|
| 1753 |
echo give_get_field_description( $field ); |
| 1754 |
|
| 1755 |
echo '</fieldset>'; |
| 1756 |
} |
| 1757 |
|