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