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
give-metabox-functions.php
1628 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 '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'] = array( |
| 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 | $allow_new_values = ''; |
| 333 | $field['value'] = give_get_field_value( $field, $thepostid ); |
| 334 | $field['value'] = is_array( $field['value'] ) ? |
| 335 | array_fill_keys( array_filter( $field['value'] ), 'selected' ) : |
| 336 | $field['value']; |
| 337 | $title_prefixes_value = ( is_array( $field['value'] ) && count( $field['value'] ) > 0 ) ? |
| 338 | array_merge( $field['options'], $field['value'] ) : |
| 339 | $field['options']; |
| 340 | |
| 341 | // Set attributes based on multiselect datatype. |
| 342 | if ( 'multiselect' === $data_type ) { |
| 343 | $type = 'multiple'; |
| 344 | $allow_new_values = 'data-allows-new-values="true"'; |
| 345 | } |
| 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 esc_attr( give_get_field_name( $field ) ); ?>[]" |
| 357 | id="<?php echo esc_attr( $field['id'] ); ?>" |
| 358 | <?php echo "{$type} {$allow_new_values} {$placeholder}"; ?> |
| 359 | > |
| 360 | <?php |
| 361 | if ( is_array( $title_prefixes_value ) && count( $title_prefixes_value ) > 0 ) { |
| 362 | foreach ( $title_prefixes_value as $key => $value ) { |
| 363 | echo sprintf( |
| 364 | '<option %1$s value="%2$s">%2$s</option>', |
| 365 | ( 'selected' === $value ) ? 'selected="selected"' : '', |
| 366 | esc_attr( $key ) |
| 367 | ); |
| 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 = array( |
| 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'] : array(); |
| 459 | |
| 460 | // Default field option arguments. |
| 461 | $field['options'] = wp_parse_args( |
| 462 | $field['options'], |
| 463 | array( |
| 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 = array( |
| 495 | 'before' => Give()->tooltips->render_span( |
| 496 | array( |
| 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 | array( |
| 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 = array(); |
| 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 = array( |
| 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 a select input box. |
| 754 | * |
| 755 | * @since 1.8 |
| 756 | * |
| 757 | * @param array $field { |
| 758 | * Optional. Array of select 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( '' => 'None', 'yes' => 'Yes' ) |
| 771 | * } |
| 772 | * @return void |
| 773 | */ |
| 774 | function give_select( $field ) { |
| 775 | global $thepostid, $post; |
| 776 | |
| 777 | $thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 778 | $field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 779 | $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 780 | $field['value'] = give_get_field_value( $field, $thepostid ); |
| 781 | $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 782 | ?> |
| 783 | <p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>"> |
| 784 | <label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label> |
| 785 | <select |
| 786 | id="<?php echo esc_attr( $field['id'] ); ?>" |
| 787 | name="<?php echo give_get_field_name( $field ); ?>" |
| 788 | style="<?php echo esc_attr( $field['style'] ); ?>" |
| 789 | <?php echo give_get_attribute_str( $field ); ?> |
| 790 | > |
| 791 | <?php |
| 792 | foreach ( $field['options'] as $key => $value ) { |
| 793 | echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>'; |
| 794 | } |
| 795 | echo '</select>'; |
| 796 | echo give_get_field_description( $field ); |
| 797 | echo '</p>'; |
| 798 | } |
| 799 | |
| 800 | /** |
| 801 | * Output a radio input box. |
| 802 | * |
| 803 | * @since 1.8 |
| 804 | * |
| 805 | * @param array $field { |
| 806 | * Optional. Array of radio field arguments. |
| 807 | * |
| 808 | * @type string $id Field ID. Default ''. |
| 809 | * @type string $style CSS style for input field. Default ''. |
| 810 | * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 811 | * @type string $value Value of input field. Default ''. |
| 812 | * @type string $name Name of input field. Default ''. |
| 813 | * @type string $description Description of input field. Default ''. |
| 814 | * @type array $attributes List of attributes of input field. Default array(). |
| 815 | * for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 816 | * => '****' ) |
| 817 | * @type array $options List of options. Default array(). |
| 818 | * for example: 'options' => array( 'enable' => 'Enable', 'disable' => |
| 819 | * 'Disable' ) |
| 820 | * } |
| 821 | * @return void |
| 822 | */ |
| 823 | function give_radio( $field ) { |
| 824 | global $thepostid, $post; |
| 825 | |
| 826 | $thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 827 | $field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 828 | $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 829 | $field['value'] = give_get_field_value( $field, $thepostid ); |
| 830 | $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 831 | |
| 832 | 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">'; |
| 833 | |
| 834 | foreach ( $field['options'] as $key => $value ) { |
| 835 | |
| 836 | echo '<li><label><input |
| 837 | name="' . give_get_field_name( $field ) . '" |
| 838 | value="' . esc_attr( $key ) . '" |
| 839 | type="radio" |
| 840 | style="' . esc_attr( $field['style'] ) . '" |
| 841 | ' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . ' ' |
| 842 | . give_get_attribute_str( $field ) . ' |
| 843 | /> ' . esc_html( $value ) . '</label> |
| 844 | </li>'; |
| 845 | } |
| 846 | echo '</ul>'; |
| 847 | |
| 848 | echo give_get_field_description( $field ); |
| 849 | echo '</fieldset>'; |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * Output a colorpicker. |
| 854 | * |
| 855 | * @since 1.8 |
| 856 | * |
| 857 | * @param array $field { |
| 858 | * Optional. Array of colorpicker field arguments. |
| 859 | * |
| 860 | * @type string $id Field ID. Default ''. |
| 861 | * @type string $style CSS style for input field. Default ''. |
| 862 | * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 863 | * @type string $value Value of input field. Default ''. |
| 864 | * @type string $name Name of input field. Default ''. |
| 865 | * @type string $description Description of input field. Default ''. |
| 866 | * @type array $attributes List of attributes of input field. Default array(). |
| 867 | * for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 868 | * => '****' ) |
| 869 | * } |
| 870 | * @return void |
| 871 | */ |
| 872 | function give_colorpicker( $field ) { |
| 873 | global $thepostid, $post; |
| 874 | |
| 875 | $thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 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['type'] = 'text'; |
| 881 | ?> |
| 882 | <p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>"> |
| 883 | <label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label> |
| 884 | <input |
| 885 | type="<?php echo esc_attr( $field['type'] ); ?>" |
| 886 | style="<?php echo esc_attr( $field['style'] ); ?>" |
| 887 | name="<?php echo give_get_field_name( $field ); ?>" |
| 888 | id="<?php echo esc_attr( $field['id'] ); ?>" |
| 889 | value="<?php echo esc_attr( $field['value'] ); ?>" |
| 890 | <?php echo give_get_attribute_str( $field ); ?> |
| 891 | /> |
| 892 | <?php |
| 893 | echo give_get_field_description( $field ); |
| 894 | echo '</p>'; |
| 895 | } |
| 896 | |
| 897 | /** |
| 898 | * Output a file upload field. |
| 899 | * |
| 900 | * @since 1.8.9 |
| 901 | * |
| 902 | * @param array $field |
| 903 | */ |
| 904 | function give_file( $field ) { |
| 905 | give_media( $field ); |
| 906 | } |
| 907 | |
| 908 | |
| 909 | /** |
| 910 | * Output a media upload field. |
| 911 | * |
| 912 | * @since 1.8 |
| 913 | * |
| 914 | * @param array $field |
| 915 | */ |
| 916 | function give_media( $field ) { |
| 917 | global $thepostid, $post; |
| 918 | |
| 919 | $thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 920 | $button_label = sprintf( __( 'Add or Upload %s', 'give' ), ( 'file' === $field['type'] ? __( 'File', 'give' ) : __( 'Image', 'give' ) ) ); |
| 921 | |
| 922 | $field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 923 | $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 924 | $field['value'] = give_get_field_value( $field, $thepostid ); |
| 925 | $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 926 | $field['attributes']['class'] = "{$field['attributes']['class']} give-text-medium"; |
| 927 | |
| 928 | // Allow developer to save attachment ID or attachment url as metadata. |
| 929 | $field['fvalue'] = isset( $field['fvalue'] ) ? $field['fvalue'] : 'url'; |
| 930 | |
| 931 | $allow_media_preview_tags = array( 'jpg', 'jpeg', 'png', 'gif', 'ico' ); |
| 932 | $preview_image_src = $field['value'] ? ( 'id' === $field['fvalue'] ? wp_get_attachment_url( $field['value'] ) : $field['value'] ) : '#'; |
| 933 | $preview_image_extension = $preview_image_src ? pathinfo( $preview_image_src, PATHINFO_EXTENSION ) : ''; |
| 934 | $is_show_preview = in_array( $preview_image_extension, $allow_media_preview_tags ); |
| 935 | ?> |
| 936 | <fieldset class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>"> |
| 937 | <label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label> |
| 938 | <input |
| 939 | name="<?php echo give_get_field_name( $field ); ?>" |
| 940 | id="<?php echo esc_attr( $field['id'] ); ?>" |
| 941 | type="text" |
| 942 | value="<?php echo $field['value']; ?>" |
| 943 | style="<?php echo esc_attr( $field['style'] ); ?>" |
| 944 | <?php echo give_get_attribute_str( $field ); ?> |
| 945 | /> <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']; ?>"> |
| 946 | <?php echo give_get_field_description( $field ); ?> |
| 947 | <div class="give-image-thumb<?php echo ! $field['value'] || ! $is_show_preview ? ' give-hidden' : ''; ?>"> |
| 948 | <span class="give-delete-image-thumb dashicons dashicons-no-alt"></span> |
| 949 | <img src="<?php echo $preview_image_src; ?>" alt=""> |
| 950 | </div> |
| 951 | </fieldset> |
| 952 | <?php |
| 953 | } |
| 954 | |
| 955 | /** |
| 956 | * Output a select field with payment options list. |
| 957 | * |
| 958 | * @since 1.8 |
| 959 | * |
| 960 | * @param array $field |
| 961 | * |
| 962 | * @return void |
| 963 | */ |
| 964 | function give_default_gateway( $field ) { |
| 965 | global $thepostid, $post; |
| 966 | |
| 967 | // get all active payment gateways. |
| 968 | $gateways = give_get_enabled_payment_gateways( $thepostid ); |
| 969 | $field['options'] = array(); |
| 970 | |
| 971 | // Set field option value. |
| 972 | if ( ! empty( $gateways ) ) { |
| 973 | foreach ( $gateways as $key => $option ) { |
| 974 | $field['options'][ $key ] = $option['admin_label']; |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | // Add a field to the Give Form admin single post view of this field |
| 979 | if ( is_object( $post ) && 'give_forms' === $post->post_type ) { |
| 980 | $field['options'] = array_merge( array( 'global' => esc_html__( 'Global Default', 'give' ) ), $field['options'] ); |
| 981 | } |
| 982 | |
| 983 | // Render select field. |
| 984 | give_select( $field ); |
| 985 | } |
| 986 | |
| 987 | /** |
| 988 | * Output the documentation link. |
| 989 | * |
| 990 | * @since 1.8 |
| 991 | * |
| 992 | * @param array $field { |
| 993 | * Optional. Array of customizable link attributes. |
| 994 | * |
| 995 | * @type string $name Name of input field. Default ''. |
| 996 | * @type string $type Type of input field. Default 'text'. |
| 997 | * @type string $url Value to be passed as a link. Default 'https://givewp.com/documentation'. |
| 998 | * @type string $title Value to be passed as text of link. Default 'Documentation'. |
| 999 | * @type array $attributes List of attributes of input field. Default array(). |
| 1000 | * for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 1001 | * => '****' ) |
| 1002 | * } |
| 1003 | * @return void |
| 1004 | */ |
| 1005 | |
| 1006 | function give_docs_link( $field ) { |
| 1007 | $field['url'] = isset( $field['url'] ) ? $field['url'] : 'https://givewp.com/documentation'; |
| 1008 | $field['title'] = isset( $field['title'] ) ? $field['title'] : 'Documentation'; |
| 1009 | |
| 1010 | echo '<p class="give-docs-link"><a href="' . esc_url( $field['url'] ) |
| 1011 | . '" target="_blank">' |
| 1012 | . sprintf( esc_html__( 'Need Help? See docs on "%s"', 'give' ), $field['title'] ) |
| 1013 | . '<span class="dashicons dashicons-editor-help"></span></a></p>'; |
| 1014 | } |
| 1015 | |
| 1016 | |
| 1017 | /** |
| 1018 | * Output preview buttons. |
| 1019 | * |
| 1020 | * @since 2.0 |
| 1021 | * |
| 1022 | * @param $field |
| 1023 | */ |
| 1024 | function give_email_preview_buttons( $field ) { |
| 1025 | /* @var WP_Post $post */ |
| 1026 | global $post; |
| 1027 | |
| 1028 | $field_id = str_replace( array( '_give_', '_preview_buttons' ), '', $field['id'] ); |
| 1029 | |
| 1030 | ob_start(); |
| 1031 | |
| 1032 | echo '<p class="give-field-wrap ' . esc_attr( $field['id'] ) . '_field"><label for="' . give_get_field_name( $field ) . '">' . wp_kses_post( $field['name'] ) . '</label>'; |
| 1033 | |
| 1034 | echo sprintf( |
| 1035 | '<a href="%1$s" class="button-secondary" target="_blank">%2$s</a>', |
| 1036 | wp_nonce_url( |
| 1037 | add_query_arg( |
| 1038 | array( |
| 1039 | 'give_action' => 'preview_email', |
| 1040 | 'email_type' => $field_id, |
| 1041 | 'form_id' => $post->ID, |
| 1042 | ), |
| 1043 | home_url() |
| 1044 | ), |
| 1045 | 'give-preview-email' |
| 1046 | ), |
| 1047 | $field['name'] |
| 1048 | ); |
| 1049 | |
| 1050 | echo sprintf( |
| 1051 | ' <a href="%1$s" aria-label="%2$s" class="button-secondary">%3$s</a>', |
| 1052 | wp_nonce_url( |
| 1053 | add_query_arg( |
| 1054 | array( |
| 1055 | 'give_action' => 'send_preview_email', |
| 1056 | 'email_type' => $field_id, |
| 1057 | 'give-messages[]' => 'sent-test-email', |
| 1058 | 'form_id' => $post->ID, |
| 1059 | ) |
| 1060 | ), |
| 1061 | 'give-send-preview-email' |
| 1062 | ), |
| 1063 | esc_attr__( 'Send Test Email.', 'give' ), |
| 1064 | esc_html__( 'Send Test Email', 'give' ) |
| 1065 | ); |
| 1066 | |
| 1067 | if ( ! empty( $field['description'] ) ) { |
| 1068 | echo '<span class="give-field-description">' . wp_kses_post( $field['desc'] ) . '</span>'; |
| 1069 | } |
| 1070 | |
| 1071 | echo '</p>'; |
| 1072 | |
| 1073 | echo ob_get_clean(); |
| 1074 | } |
| 1075 | |
| 1076 | /** |
| 1077 | * Get setting field value. |
| 1078 | * |
| 1079 | * Note: Use only for single post, page or custom post type. |
| 1080 | * |
| 1081 | * @since 1.8 |
| 1082 | * @since 2.1 Added support for donation_limit. |
| 1083 | * |
| 1084 | * @param array $field |
| 1085 | * @param int $postid |
| 1086 | * |
| 1087 | * @return mixed |
| 1088 | */ |
| 1089 | function give_get_field_value( $field, $postid ) { |
| 1090 | if ( isset( $field['attributes']['value'] ) ) { |
| 1091 | return $field['attributes']['value']; |
| 1092 | } |
| 1093 | |
| 1094 | // If field is range slider. |
| 1095 | if ( 'donation_limit' === $field['type'] ) { |
| 1096 | |
| 1097 | // Get minimum value. |
| 1098 | $minimum = give_get_meta( $postid, $field['id'] . '_minimum', true ); |
| 1099 | |
| 1100 | // Give < 2.1 |
| 1101 | if ( '_give_custom_amount_range' === $field['id'] && empty( $minimum ) ) { |
| 1102 | $minimum = give_get_meta( $postid, '_give_custom_amount_minimum', true ); |
| 1103 | } |
| 1104 | |
| 1105 | $field_value = array( |
| 1106 | 'minimum' => $minimum, |
| 1107 | 'maximum' => give_get_meta( $postid, $field['id'] . '_maximum', true ), |
| 1108 | ); |
| 1109 | } else { |
| 1110 | // Get value from db. |
| 1111 | $field_value = give_get_meta( $postid, $field['id'], true ); |
| 1112 | } |
| 1113 | |
| 1114 | /** |
| 1115 | * Filter the field value before apply default value. |
| 1116 | * |
| 1117 | * @since 1.8 |
| 1118 | * |
| 1119 | * @param mixed $field_value Field value. |
| 1120 | */ |
| 1121 | $field_value = apply_filters( "{$field['id']}_field_value", $field_value, $field, $postid ); |
| 1122 | |
| 1123 | // Set default value if no any data saved to db. |
| 1124 | if ( ! $field_value && isset( $field['default'] ) ) { |
| 1125 | $field_value = $field['default']; |
| 1126 | } |
| 1127 | |
| 1128 | return $field_value; |
| 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | /** |
| 1133 | * Get field description html. |
| 1134 | * |
| 1135 | * @since 1.8 |
| 1136 | * |
| 1137 | * @param $field |
| 1138 | * |
| 1139 | * @return string |
| 1140 | */ |
| 1141 | function give_get_field_description( $field ) { |
| 1142 | $field_desc_html = ''; |
| 1143 | $description = ''; |
| 1144 | |
| 1145 | // Check for both `description` and `desc`. |
| 1146 | if ( isset( $field['description'] ) ) { |
| 1147 | $description = $field['description']; |
| 1148 | } elseif ( isset( $field['desc'] ) ) { |
| 1149 | $description = $field['desc']; |
| 1150 | } |
| 1151 | |
| 1152 | // Set if there is a description. |
| 1153 | if ( ! empty( $description ) ) { |
| 1154 | $field_desc_html = '<span class="give-field-description">' . wp_kses_post( $description ) . '</span>'; |
| 1155 | } |
| 1156 | |
| 1157 | return $field_desc_html; |
| 1158 | } |
| 1159 | |
| 1160 | |
| 1161 | /** |
| 1162 | * Get repeater field value. |
| 1163 | * |
| 1164 | * Note: Use only for single post, page or custom post type. |
| 1165 | * |
| 1166 | * @since 1.8 |
| 1167 | * |
| 1168 | * @param array $field |
| 1169 | * @param array $field_group |
| 1170 | * @param array $fields |
| 1171 | * |
| 1172 | * @return string |
| 1173 | */ |
| 1174 | function give_get_repeater_field_value( $field, $field_group, $fields ) { |
| 1175 | $field_value = ( isset( $field_group[ $field['id'] ] ) ? $field_group[ $field['id'] ] : '' ); |
| 1176 | |
| 1177 | /** |
| 1178 | * Filter the specific repeater field value |
| 1179 | * |
| 1180 | * @since 1.8 |
| 1181 | * |
| 1182 | * @param string $field_id |
| 1183 | */ |
| 1184 | $field_value = apply_filters( "give_get_repeater_field_{$field['id']}_value", $field_value, $field, $field_group, $fields ); |
| 1185 | |
| 1186 | /** |
| 1187 | * Filter the repeater field value |
| 1188 | * |
| 1189 | * @since 1.8 |
| 1190 | * |
| 1191 | * @param string $field_id |
| 1192 | */ |
| 1193 | $field_value = apply_filters( 'give_get_repeater_field_value', $field_value, $field, $field_group, $fields ); |
| 1194 | |
| 1195 | return $field_value; |
| 1196 | } |
| 1197 | |
| 1198 | /** |
| 1199 | * Get repeater field id. |
| 1200 | * |
| 1201 | * Note: Use only for single post, page or custom post type. |
| 1202 | * |
| 1203 | * @since 1.8 |
| 1204 | * |
| 1205 | * @param array $field |
| 1206 | * @param array $fields |
| 1207 | * @param int|bool $default |
| 1208 | * |
| 1209 | * @return string |
| 1210 | */ |
| 1211 | function give_get_repeater_field_id( $field, $fields, $default = false ) { |
| 1212 | $row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}'; |
| 1213 | |
| 1214 | // Get field id. |
| 1215 | $field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}]"; |
| 1216 | |
| 1217 | /** |
| 1218 | * Filter the specific repeater field id |
| 1219 | * |
| 1220 | * @since 1.8 |
| 1221 | * |
| 1222 | * @param string $field_id |
| 1223 | */ |
| 1224 | $field_id = apply_filters( "give_get_repeater_field_{$field['id']}_id", $field_id, $field, $fields, $default ); |
| 1225 | |
| 1226 | /** |
| 1227 | * Filter the repeater field id |
| 1228 | * |
| 1229 | * @since 1.8 |
| 1230 | * |
| 1231 | * @param string $field_id |
| 1232 | */ |
| 1233 | $field_id = apply_filters( 'give_get_repeater_field_id', $field_id, $field, $fields, $default ); |
| 1234 | |
| 1235 | return $field_id; |
| 1236 | } |
| 1237 | |
| 1238 | |
| 1239 | /** |
| 1240 | * Get field name. |
| 1241 | * |
| 1242 | * @since 1.8 |
| 1243 | * |
| 1244 | * @param array $field |
| 1245 | * |
| 1246 | * @return string |
| 1247 | */ |
| 1248 | function give_get_field_name( $field ) { |
| 1249 | $field_name = esc_attr( empty( $field['repeat'] ) ? $field['id'] : $field['repeatable_field_id'] ); |
| 1250 | |
| 1251 | /** |
| 1252 | * Filter the field name. |
| 1253 | * |
| 1254 | * @since 1.8 |
| 1255 | * |
| 1256 | * @param string $field_name |
| 1257 | */ |
| 1258 | $field_name = apply_filters( 'give_get_field_name', $field_name, $field ); |
| 1259 | |
| 1260 | return $field_name; |
| 1261 | } |
| 1262 | |
| 1263 | /** |
| 1264 | * Output repeater field or multi donation type form on donation from edit screen. |
| 1265 | * Note: internal use only. |
| 1266 | * |
| 1267 | * @TODO : Add support for wysiwyg type field. |
| 1268 | * |
| 1269 | * @since 1.8 |
| 1270 | * |
| 1271 | * @param array $fields |
| 1272 | * |
| 1273 | * @return void |
| 1274 | */ |
| 1275 | function _give_metabox_form_data_repeater_fields( $fields ) { |
| 1276 | global $thepostid, $post; |
| 1277 | |
| 1278 | // Bailout. |
| 1279 | if ( ! isset( $fields['fields'] ) || empty( $fields['fields'] ) ) { |
| 1280 | return; |
| 1281 | } |
| 1282 | |
| 1283 | $group_numbering = isset( $fields['options']['group_numbering'] ) ? (int) $fields['options']['group_numbering'] : 0; |
| 1284 | $close_tabs = isset( $fields['options']['close_tabs'] ) ? (int) $fields['options']['close_tabs'] : 0; |
| 1285 | $wrapper_class = isset( $fields['wrapper_class'] ) ? $fields['wrapper_class'] : ''; |
| 1286 | ?> |
| 1287 | <div class="give-repeatable-field-section <?php echo esc_attr( $wrapper_class ); ?>" id="<?php echo "{$fields['id']}_field"; ?>" |
| 1288 | data-group-numbering="<?php echo $group_numbering; ?>" data-close-tabs="<?php echo $close_tabs; ?>"> |
| 1289 | <?php if ( ! empty( $fields['name'] ) ) : ?> |
| 1290 | <p class="give-repeater-field-name"><?php echo $fields['name']; ?></p> |
| 1291 | <?php endif; ?> |
| 1292 | |
| 1293 | <?php if ( ! empty( $fields['description'] ) ) : ?> |
| 1294 | <p class="give-repeater-field-description"><?php echo $fields['description']; ?></p> |
| 1295 | <?php endif; ?> |
| 1296 | |
| 1297 | <table class="give-repeatable-fields-section-wrapper" cellspacing="0"> |
| 1298 | <?php |
| 1299 | // Get value. |
| 1300 | $repeater_field_values = ! empty( $fields['attributes']['value'] ) |
| 1301 | ? $fields['attributes']['value'] |
| 1302 | : give_get_meta( $thepostid, $fields['id'], true ); |
| 1303 | |
| 1304 | // Setup default value. |
| 1305 | if ( empty( $repeater_field_values ) && ! empty( $fields['default'] ) ) { |
| 1306 | $repeater_field_values = $fields['default']; |
| 1307 | } |
| 1308 | |
| 1309 | $header_title = isset( $fields['options']['header_title'] ) |
| 1310 | ? $fields['options']['header_title'] |
| 1311 | : esc_attr__( 'Group', 'give' ); |
| 1312 | |
| 1313 | $add_default_donation_field = false; |
| 1314 | |
| 1315 | // Check if level is not created or we have to add default level. |
| 1316 | if ( is_array( $repeater_field_values ) && ( $fields_count = count( $repeater_field_values ) ) ) { |
| 1317 | $repeater_field_values = array_values( $repeater_field_values ); |
| 1318 | } else { |
| 1319 | $fields_count = 1; |
| 1320 | $add_default_donation_field = true; |
| 1321 | } |
| 1322 | ?> |
| 1323 | <tbody class="container"<?php echo " data-rf-row-count=\"{$fields_count}\""; ?>> |
| 1324 | <!--Repeater field group template--> |
| 1325 | <tr class="give-template give-row"> |
| 1326 | <td class="give-repeater-field-wrap give-column" colspan="2"> |
| 1327 | <div class="give-row-head give-move"> |
| 1328 | <button type="button" class="handlediv button-link"><span class="toggle-indicator"></span> |
| 1329 | </button> |
| 1330 | <span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-</span> |
| 1331 | <h2> |
| 1332 | <span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span> |
| 1333 | </h2> |
| 1334 | </div> |
| 1335 | <div class="give-row-body"> |
| 1336 | <?php foreach ( $fields['fields'] as $field ) : ?> |
| 1337 | <?php |
| 1338 | if ( ! give_is_field_callback_exist( $field ) ) { |
| 1339 | continue; |
| 1340 | } |
| 1341 | ?> |
| 1342 | <?php |
| 1343 | $field['repeat'] = true; |
| 1344 | $field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields ); |
| 1345 | $field['id'] = str_replace( |
| 1346 | array( '[', ']' ), |
| 1347 | array( '_', '' ), |
| 1348 | $field['repeatable_field_id'] |
| 1349 | ); |
| 1350 | ?> |
| 1351 | <?php give_render_field( $field ); ?> |
| 1352 | <?php endforeach; ?> |
| 1353 | </div> |
| 1354 | </td> |
| 1355 | </tr> |
| 1356 | |
| 1357 | <?php if ( ! empty( $repeater_field_values ) ) : ?> |
| 1358 | <!--Stored repeater field group--> |
| 1359 | <?php foreach ( $repeater_field_values as $index => $field_group ) : ?> |
| 1360 | <tr class="give-row"> |
| 1361 | <td class="give-repeater-field-wrap give-column" colspan="2"> |
| 1362 | <div class="give-row-head give-move"> |
| 1363 | <button type="button" class="handlediv button-link"> |
| 1364 | <span class="toggle-indicator"></span></button> |
| 1365 | <span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">- |
| 1366 | </span> |
| 1367 | <h2> |
| 1368 | <span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span> |
| 1369 | </h2> |
| 1370 | </div> |
| 1371 | <div class="give-row-body"> |
| 1372 | <?php foreach ( $fields['fields'] as $field ) : ?> |
| 1373 | <?php |
| 1374 | if ( ! give_is_field_callback_exist( $field ) ) { |
| 1375 | continue; |
| 1376 | } |
| 1377 | ?> |
| 1378 | <?php |
| 1379 | $field['repeat'] = true; |
| 1380 | $field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, $index ); |
| 1381 | $field['attributes']['value'] = give_get_repeater_field_value( $field, $field_group, $fields ); |
| 1382 | $field['id'] = str_replace( |
| 1383 | array( '[', ']' ), |
| 1384 | array( '_', '' ), |
| 1385 | $field['repeatable_field_id'] |
| 1386 | ); |
| 1387 | ?> |
| 1388 | <?php give_render_field( $field ); ?> |
| 1389 | <?php endforeach; ?> |
| 1390 | </div> |
| 1391 | </td> |
| 1392 | </tr> |
| 1393 | <?php |
| 1394 | endforeach; |
| 1395 | ?> |
| 1396 | |
| 1397 | <?php elseif ( $add_default_donation_field ) : ?> |
| 1398 | <!--Default repeater field group--> |
| 1399 | <tr class="give-row"> |
| 1400 | <td class="give-repeater-field-wrap give-column" colspan="2"> |
| 1401 | <div class="give-row-head give-move"> |
| 1402 | <button type="button" class="handlediv button-link"> |
| 1403 | <span class="toggle-indicator"></span></button> |
| 1404 | <span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">- |
| 1405 | </span> |
| 1406 | <h2> |
| 1407 | <span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span> |
| 1408 | </h2> |
| 1409 | </div> |
| 1410 | <div class="give-row-body"> |
| 1411 | <?php |
| 1412 | foreach ( $fields['fields'] as $field ) : |
| 1413 | if ( ! give_is_field_callback_exist( $field ) ) { |
| 1414 | continue; |
| 1415 | } |
| 1416 | |
| 1417 | $field['repeat'] = true; |
| 1418 | $field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, 0 ); |
| 1419 | $field['attributes']['value'] = apply_filters( |
| 1420 | "give_default_field_group_field_{$field['id']}_value", |
| 1421 | ( ! empty( $field['default'] ) ? $field['default'] : '' ), |
| 1422 | $field, |
| 1423 | $fields |
| 1424 | ); |
| 1425 | $field['id'] = str_replace( |
| 1426 | array( '[', ']' ), |
| 1427 | array( '_', '' ), |
| 1428 | $field['repeatable_field_id'] |
| 1429 | ); |
| 1430 | give_render_field( $field ); |
| 1431 | |
| 1432 | endforeach; |
| 1433 | ?> |
| 1434 | </div> |
| 1435 | </td> |
| 1436 | </tr> |
| 1437 | <?php endif; ?> |
| 1438 | </tbody> |
| 1439 | <tfoot> |
| 1440 | <tr> |
| 1441 | <?php |
| 1442 | $add_row_btn_title = isset( $fields['options']['add_button'] ) |
| 1443 | ? $add_row_btn_title = $fields['options']['add_button'] |
| 1444 | : esc_html__( 'Add Row', 'give' ); |
| 1445 | ?> |
| 1446 | <td colspan="2" class="give-add-repeater-field-section-row-wrap"> |
| 1447 | <span class="button button-primary give-add-repeater-field-section-row"><?php echo $add_row_btn_title; ?></span> |
| 1448 | </td> |
| 1449 | </tr> |
| 1450 | </tfoot> |
| 1451 | </table> |
| 1452 | </div> |
| 1453 | <?php |
| 1454 | } |
| 1455 | |
| 1456 | |
| 1457 | /** |
| 1458 | * Set repeater field id for multi donation form. |
| 1459 | * |
| 1460 | * @since 1.8 |
| 1461 | * |
| 1462 | * @param int $field_id |
| 1463 | * @param array $field |
| 1464 | * @param array $fields |
| 1465 | * @param bool $default |
| 1466 | * |
| 1467 | * @return mixed |
| 1468 | */ |
| 1469 | function _give_set_multi_level_repeater_field_id( $field_id, $field, $fields, $default ) { |
| 1470 | $row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}'; |
| 1471 | $field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}][level_id]"; |
| 1472 | |
| 1473 | return $field_id; |
| 1474 | } |
| 1475 | |
| 1476 | add_filter( 'give_get_repeater_field__give_id_id', '_give_set_multi_level_repeater_field_id', 10, 4 ); |
| 1477 | |
| 1478 | /** |
| 1479 | * Set repeater field value for multi donation form. |
| 1480 | * |
| 1481 | * @since 1.8 |
| 1482 | * |
| 1483 | * @param string $field_value |
| 1484 | * @param array $field |
| 1485 | * @param array $field_group |
| 1486 | * @param array $fields |
| 1487 | * |
| 1488 | * @return mixed |
| 1489 | */ |
| 1490 | function _give_set_multi_level_repeater_field_value( $field_value, $field, $field_group, $fields ) { |
| 1491 | $field_value = $field_group[ $field['id'] ]['level_id']; |
| 1492 | |
| 1493 | return $field_value; |
| 1494 | } |
| 1495 | |
| 1496 | add_filter( 'give_get_repeater_field__give_id_value', '_give_set_multi_level_repeater_field_value', 10, 4 ); |
| 1497 | |
| 1498 | /** |
| 1499 | * Set default value for _give_id field. |
| 1500 | * |
| 1501 | * @since 1.8 |
| 1502 | * |
| 1503 | * @param $field |
| 1504 | * |
| 1505 | * @return string |
| 1506 | */ |
| 1507 | function _give_set_field_give_id_default_value( $field ) { |
| 1508 | return 0; |
| 1509 | } |
| 1510 | |
| 1511 | add_filter( 'give_default_field_group_field__give_id_value', '_give_set_field_give_id_default_value' ); |
| 1512 | |
| 1513 | /** |
| 1514 | * Set default value for _give_default field. |
| 1515 | * |
| 1516 | * @since 1.8 |
| 1517 | * |
| 1518 | * @param $field |
| 1519 | * |
| 1520 | * @return string |
| 1521 | */ |
| 1522 | function _give_set_field_give_default_default_value( $field ) { |
| 1523 | return 'default'; |
| 1524 | } |
| 1525 | |
| 1526 | add_filter( 'give_default_field_group_field__give_default_value', '_give_set_field_give_default_default_value' ); |
| 1527 | |
| 1528 | /** |
| 1529 | * Set repeater field editor id for field type wysiwyg. |
| 1530 | * |
| 1531 | * @since 1.8 |
| 1532 | * |
| 1533 | * @param $field_name |
| 1534 | * @param $field |
| 1535 | * |
| 1536 | * @return string |
| 1537 | */ |
| 1538 | function give_repeater_field_set_editor_id( $field_name, $field ) { |
| 1539 | if ( isset( $field['repeatable_field_id'] ) && 'wysiwyg' == $field['type'] ) { |
| 1540 | $field_name = '_give_repeater_' . uniqid() . '_wysiwyg'; |
| 1541 | } |
| 1542 | |
| 1543 | return $field_name; |
| 1544 | } |
| 1545 | |
| 1546 | add_filter( 'give_get_field_name', 'give_repeater_field_set_editor_id', 10, 2 ); |
| 1547 | |
| 1548 | /** |
| 1549 | * Output Donation form radio input box. |
| 1550 | * |
| 1551 | * @since 2.1.3 |
| 1552 | * |
| 1553 | * @param array $field { |
| 1554 | * Optional. Array of radio field arguments. |
| 1555 | * |
| 1556 | * @type string $id Field ID. Default ''. |
| 1557 | * @type string $style CSS style for input field. Default ''. |
| 1558 | * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
| 1559 | * @type string $value Value of input field. Default ''. |
| 1560 | * @type string $name Name of input field. Default ''. |
| 1561 | * @type string $description Description of input field. Default ''. |
| 1562 | * @type array $attributes List of attributes of input field. Default array(). |
| 1563 | * for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
| 1564 | * => '****' ) |
| 1565 | * @type array $options List of options. Default array(). |
| 1566 | * for example: 'options' => array( 'enable' => 'Enable', 'disable' => |
| 1567 | * 'Disable' ) |
| 1568 | * } |
| 1569 | * @return void |
| 1570 | */ |
| 1571 | function give_donation_form_goal( $field ) { |
| 1572 | global $thepostid, $post; |
| 1573 | |
| 1574 | $thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 1575 | $field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 1576 | $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 1577 | $field['value'] = give_get_field_value( $field, $thepostid ); |
| 1578 | $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 1579 | |
| 1580 | printf( |
| 1581 | '<fieldset class="give-field-wrap %s_field %s">', |
| 1582 | esc_attr( $field['id'] ), |
| 1583 | esc_attr( $field['wrapper_class'] ) |
| 1584 | ); |
| 1585 | |
| 1586 | printf( |
| 1587 | '<span class="give-field-label">%s</span>', |
| 1588 | esc_html( $field['name'] ) |
| 1589 | ); |
| 1590 | |
| 1591 | printf( |
| 1592 | '<legend class="screen-reader-text">%s</legend>', |
| 1593 | esc_html( $field['name'] ) |
| 1594 | ); |
| 1595 | ?> |
| 1596 | |
| 1597 | <ul class="give-radios"> |
| 1598 | <?php |
| 1599 | foreach ( $field['options'] as $key => $value ) { |
| 1600 | $attributes = empty( $field['attributes'] ) ? '' : give_get_attribute_str( $field['attributes'] ); |
| 1601 | printf( |
| 1602 | '<li><label><input name="%s" value="%s" type="radio" style="%s" %s %s /> %s </label></li>', |
| 1603 | give_get_field_name( $field ), |
| 1604 | esc_attr( $key ), |
| 1605 | esc_attr( $field['style'] ), |
| 1606 | checked( esc_attr( $field['value'] ), esc_attr( $key ), false ), |
| 1607 | $attributes, |
| 1608 | esc_html( $value ) |
| 1609 | ); |
| 1610 | } |
| 1611 | ?> |
| 1612 | </ul> |
| 1613 | |
| 1614 | <?php |
| 1615 | /** |
| 1616 | * Action to add HTML after donation form radio button is display and before description. |
| 1617 | * |
| 1618 | * @since 2.1.3 |
| 1619 | * |
| 1620 | * @param array $field Array of radio field arguments. |
| 1621 | */ |
| 1622 | do_action( 'give_donation_form_goal_before_description', $field ); |
| 1623 | |
| 1624 | echo give_get_field_description( $field ); |
| 1625 | |
| 1626 | echo '</fieldset>'; |
| 1627 | } |
| 1628 |