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