Skip to content

Commit

Permalink
Merge pull request #908 from ravinderk/issue/902
Browse files Browse the repository at this point in the history
Fix issue #902
  • Loading branch information
Devin Walker committed Aug 17, 2016
2 parents e8aff2b + 7a64397 commit cc4e8a4
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 16 deletions.
2 changes: 1 addition & 1 deletion assets/css/give-admin.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions assets/scss/admin/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ div.cmb-type-levels-repeater-header + div.cmb-repeat-group-wrap {

.give-money-symbol-after {
border-left: 0;
margin-left: -4px;
}

.give-underline {
Expand Down
2 changes: 1 addition & 1 deletion assets/sourcemaps/give-admin.css.map

Large diffs are not rendered by default.

25 changes: 11 additions & 14 deletions includes/admin/forms/metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ function give_single_forms_cmb2_metaboxes( array $meta_boxes ) {
'id' => $prefix . 'set_price',
'type' => 'text_small',
'row_classes' => 'give-subfield',
'before_field' => give_get_option( 'currency_position' ) == 'before' ? '<span class="give-money-symbol give-money-symbol-before">' . give_currency_symbol() . '</span>' : '',
'after_field' => give_get_option( 'currency_position' ) == 'after' ? '<span class="give-money-symbol give-money-symbol-after">' . give_currency_symbol() . '</span>' : '',
'sanitization_cb' => 'give_sanitize_price_field_value',
'render_row_cb' => 'give_cmb_amount_field_render_row_cb',
'sanitization_cb' => 'give_sanitize_price_field_value',
'attributes' => array(
'placeholder' => give_format_decimal( '1.00' ),
'value' => give_format_decimal( $price ),
Expand Down Expand Up @@ -159,15 +158,14 @@ function give_single_forms_cmb2_metaboxes( array $meta_boxes ) {
),
),
array(
'name' => esc_html__( 'Custom Amount Minimum', 'give' ),
'description' => esc_html__( 'If you would like to set a minimum custom donation amount please enter it here.', 'give' ),
'id' => $prefix . 'custom_amount_minimum',
'type' => 'text_small',
'row_classes' => 'give-subfield',
'before_field' => give_get_option( 'currency_position' ) == 'before' ? '<span class="give-money-symbol give-money-symbol-before">' . give_currency_symbol() . '</span>' : '',
'after_field' => give_get_option( 'currency_position' ) == 'after' ? '<span class="give-money-symbol give-money-symbol-after">' . give_currency_symbol() . '</span>' : '',
'sanitization_cb' => 'give_sanitize_price_field_value',
'attributes' => array(
'name' => esc_html__( 'Custom Amount Minimum', 'give' ),
'description' => esc_html__( 'If you would like to set a minimum custom donation amount please enter it here.', 'give' ),
'id' => $prefix . 'custom_amount_minimum',
'type' => 'text_small',
'row_classes' => 'give-subfield',
'render_row_cb' => 'give_cmb_amount_field_render_row_cb',
'sanitization_cb' => 'give_sanitize_price_field_value',
'attributes' => array(
'placeholder' => give_format_decimal('1.00'),
'value' => give_format_decimal( $custom_amount_minimum ),
'class' => 'cmb-type-text-small give-money-field',
Expand Down Expand Up @@ -202,8 +200,7 @@ function give_single_forms_cmb2_metaboxes( array $meta_boxes ) {
'id' => $prefix . 'set_goal',
'type' => 'text_small',
'row_classes' => 'give-subfield',
'before_field' => give_get_option( 'currency_position' ) == 'before' ? '<span class="give-money-symbol give-money-symbol-before">' . give_currency_symbol() . '</span>' : '',
'after_field' => give_get_option( 'currency_position' ) == 'after' ? '<span class="give-money-symbol give-money-symbol-after">' . give_currency_symbol() . '</span>' : '',
'render_row_cb' => 'give_cmb_amount_field_render_row_cb',
'sanitization_cb' => 'give_sanitize_price_field_value',
'attributes' => array(
'placeholder' => give_format_decimal( '0.00' ),
Expand Down
51 changes: 51 additions & 0 deletions includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,55 @@ function give_sanitize_number_decimals( $value, $field_args, $field ){
*/
function give_sanitize_price_field_value( $value, $field_args, $field ){
return give_sanitize_amount( $value );
}


/**
* Manually render amount field.
*
* @since 1.7
*
* @param array $field_args Array of field arguments.
* @param CMB2_Field $field The field object
*
* @return void
*/
function give_cmb_amount_field_render_row_cb( $field_args, $field ) {

// Get args.
$id = $field->args('id');
$label = $field->args( 'name' );
$name = $field->args( '_name' );
$description = $field->args( 'description' );
$attributes = $field->args( 'attributes' );
$attributes_string = '';
$row_class = $field->row_classes();

// Get attributes.
if( ! empty( $attributes ) ) {
foreach ( $attributes as $attribute_name => $attribute_val ) {
$attributes_string[] = "$attribute_name=\"$attribute_val\"";
}

$attributes_string = implode( ' ', $attributes_string );
}

// Get row class.
if( ! empty( $row_class ) && is_array( $row_class ) ) {
$row_class = implode( ' ', $row_class );
}
?>
<div class="cmb-row <?php echo $row_class; ?>">
<div class="cmb-th">
<label for="<?php echo $id; ?>"><?php echo $label; ?></label>
</div>
<div class="cmb-td">
<?php echo ( give_get_option( 'currency_position' ) == 'before' ? '<span class="give-money-symbol give-money-symbol-before">' . give_currency_symbol() . '</span>' : '' ); ?>
<input id="<?php echo $id; ?>" type="text" name="<?php echo $name; ?>" <?php echo $attributes_string?>/>
<?php echo ( give_get_option( 'currency_position' ) == 'after' ? '<span class="give-money-symbol give-money-symbol-after">' . give_currency_symbol() . '</span>' : '' ); ?>

<span class="cmb2-metabox-description"><?php echo $description; ?></span>
</div>
</div>
<?php
}

0 comments on commit cc4e8a4

Please sign in to comment.