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