Skip to content

Commit

Permalink
Merge branch 'release/2.0.2' of https://github.com/WordImpress/Give i…
Browse files Browse the repository at this point in the history
…nto release/2.0.2

* 'release/2.0.2' of https://github.com/WordImpress/Give:
  Remove code repetation #2737
  Fix price level #2737
  Fix coding standard #2737
  Remove meta update when form is alredy being created #2737
  • Loading branch information
DevinWalker committed Jan 31, 2018
2 parents a8f8898 + a876141 commit e5f11b6
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions includes/import-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,20 @@ function give_import_get_form_data_from_csv( $data, $import_setting = array() )
}

if ( ! empty( $form ) && $form->get_ID() ) {
if ( ! empty( $data['form_level'] ) && 'custom' != (string) strtolower( $data['form_level'] ) ) {

$price_option = 'set';
$form_level = strtolower( preg_replace('/\s+/', '', $data['form_level'] ) );

if ( ! empty( $data['form_level'] ) && 'custom' != $form_level ) {
$prices = (array) $form->get_prices();
$price_text = array();
foreach ( $prices as $key => $price ) {
if ( isset( $price['_give_id']['level_id'] ) ) {
$price_text[ $price['_give_id']['level_id'] ] = ( ! empty( $price['_give_text'] ) ? $price['_give_text'] : '' );
$price_text[ $price['_give_id']['level_id'] ] = ( ! empty( $price['_give_text'] ) ? strtolower( preg_replace('/\s+/', '', $price['_give_text'] ) ) : '' );
}
}

if ( ! in_array( $data['form_level'], $price_text ) ) {
if ( ! in_array( $form_level, $price_text ) ) {

// For generating unquiet level id.
$count = 1;
Expand All @@ -125,7 +129,7 @@ function give_import_get_form_data_from_csv( $data, $import_setting = array() )
),
);

$price_text[ $new_level ] = $data['form_level'];
$price_text[ $new_level ] = strtolower( preg_replace('/\s+/', '', $data['form_level'] ) );

if ( ! empty( $prices ) && is_array( $prices ) && ! empty( $prices[0] ) ) {
$prices = wp_parse_args( $multi_level_donations, $prices );
Expand All @@ -146,7 +150,7 @@ function give_import_get_form_data_from_csv( $data, $import_setting = array() )
// Set the first $price of the $prices as defalut.
$prices[0]['_give_default'] = 'default';
}
$form->price_id = array_search( $data['form_level'], $price_text );
$form->price_id = array_search( $form_level, $price_text );

$donation_levels_amounts = wp_list_pluck( $prices, '_give_amount' );
$min_amount = min( $donation_levels_amounts );
Expand All @@ -155,16 +159,16 @@ function give_import_get_form_data_from_csv( $data, $import_setting = array() )
$meta = array(
'_give_levels_minimum_amount' => $min_amount,
'_give_levels_maximum_amount' => $max_amount,
'_give_price_option' => 'multi',
'_give_donation_levels' => array_values( $prices ),
);

$price_option = 'multi';
} else {
$form->price_id = 'custom';
}

$defaults = array(
'_give_set_price' => give_sanitize_amount_for_db( $data['amount'] ),
'_give_price_option' => 'set',
'_give_set_price' => give_sanitize_amount_for_db( $data['amount'] ),
);

// If new form is created.
Expand All @@ -180,6 +184,7 @@ function give_import_get_form_data_from_csv( $data, $import_setting = array() )
'_give_product_type' => 'default',
'_give_default_gateway' => 'global',
'_give_show_register_form' => 'both',
'_give_price_option' => $price_option,
);
$defaults = wp_parse_args( $defaults, $new_form );
}
Expand Down

0 comments on commit e5f11b6

Please sign in to comment.