Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #902 #908

Merged
merged 1 commit into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}