@@ -666,6 +666,7 @@ |
||
| 666 | 666 | * Check if Import donation is duplicate |
| 667 | 667 | * |
| 668 | 668 | * @since 1.8.13 |
| 669 | + * @param Give_Donate_Form $form |
|
| 669 | 670 | */ |
| 670 | 671 | function give_check_import_donation_duplicate( $payment_data, $data, $form, $donor_data ) { |
| 671 | 672 | $return = false; |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @since 1.8.13 |
| 21 | 21 | */ |
| 22 | 22 | function give_import_donation_report() { |
| 23 | - return get_option( 'give_import_donation_report', array() ); |
|
| 23 | + return get_option('give_import_donation_report', array()); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
@@ -29,8 +29,8 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @since 1.8.13 |
| 31 | 31 | */ |
| 32 | -function give_import_donation_report_update( $value = array() ) { |
|
| 33 | - update_option( 'give_import_donation_report', $value ); |
|
| 32 | +function give_import_donation_report_update($value = array()) { |
|
| 33 | + update_option('give_import_donation_report', $value); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @since 1.8.13 |
| 41 | 41 | */ |
| 42 | 42 | function give_import_donation_report_reset() { |
| 43 | - update_option( 'give_import_donation_report', array() ); |
|
| 43 | + update_option('give_import_donation_report', array()); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return array|bool|Give_Donate_Form|int|null|WP_Post |
| 54 | 54 | */ |
| 55 | -function give_import_get_form_data_from_csv( $data, $import_setting = array() ) { |
|
| 55 | +function give_import_get_form_data_from_csv($data, $import_setting = array()) { |
|
| 56 | 56 | $new_form = false; |
| 57 | 57 | |
| 58 | 58 | // Get the import report |
@@ -61,58 +61,58 @@ discard block |
||
| 61 | 61 | $form = false; |
| 62 | 62 | $meta = array(); |
| 63 | 63 | |
| 64 | - if ( ! empty( $data['form_id'] ) ) { |
|
| 65 | - $form = new Give_Donate_Form( $data['form_id'] ); |
|
| 64 | + if ( ! empty($data['form_id'])) { |
|
| 65 | + $form = new Give_Donate_Form($data['form_id']); |
|
| 66 | 66 | // Add support to older php version. |
| 67 | 67 | $form_id = $form->get_ID(); |
| 68 | - if ( empty( $form_id ) ) { |
|
| 69 | - $report['duplicate_form'] = ( ! empty( $report['duplicate_form'] ) ? ( absint( $report['duplicate_form'] ) + 1 ) : 1 ); |
|
| 68 | + if (empty($form_id)) { |
|
| 69 | + $report['duplicate_form'] = ( ! empty($report['duplicate_form']) ? (absint($report['duplicate_form']) + 1) : 1); |
|
| 70 | 70 | $form = false; |
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if ( false === $form && ! empty( $data['form_title'] ) ) { |
|
| 75 | - $form = get_page_by_title( $data['form_title'], OBJECT, 'give_forms' ); |
|
| 74 | + if (false === $form && ! empty($data['form_title'])) { |
|
| 75 | + $form = get_page_by_title($data['form_title'], OBJECT, 'give_forms'); |
|
| 76 | 76 | |
| 77 | - if ( ! empty( $form->ID ) ) { |
|
| 77 | + if ( ! empty($form->ID)) { |
|
| 78 | 78 | |
| 79 | - $report['duplicate_form'] = ( ! empty( $report['duplicate_form'] ) ? ( absint( $report['duplicate_form'] ) + 1 ) : 1 ); |
|
| 79 | + $report['duplicate_form'] = ( ! empty($report['duplicate_form']) ? (absint($report['duplicate_form']) + 1) : 1); |
|
| 80 | 80 | |
| 81 | - $form = new Give_Donate_Form( $form->ID ); |
|
| 81 | + $form = new Give_Donate_Form($form->ID); |
|
| 82 | 82 | } else { |
| 83 | 83 | $form = new Give_Donate_Form(); |
| 84 | 84 | $args = array( |
| 85 | 85 | 'post_title' => $data['form_title'], |
| 86 | 86 | 'post_status' => 'publish', |
| 87 | 87 | ); |
| 88 | - $form = $form->create( $args ); |
|
| 89 | - $report['create_form'] = ( ! empty( $report['create_form'] ) ? ( absint( $report['create_form'] ) + 1 ) : 1 ); |
|
| 88 | + $form = $form->create($args); |
|
| 89 | + $report['create_form'] = ( ! empty($report['create_form']) ? (absint($report['create_form']) + 1) : 1); |
|
| 90 | 90 | $new_form = true; |
| 91 | 91 | |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - $form = get_page_by_title( $data['form_title'], OBJECT, 'give_forms' ); |
|
| 95 | - $form = new Give_Donate_Form( $form->ID ); |
|
| 94 | + $form = get_page_by_title($data['form_title'], OBJECT, 'give_forms'); |
|
| 95 | + $form = new Give_Donate_Form($form->ID); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if ( ! empty( $form ) && $form->get_ID() ) { |
|
| 99 | - if ( ! empty( $data['form_level'] ) && 'custom' != (string) strtolower( $data['form_level'] ) ) { |
|
| 98 | + if ( ! empty($form) && $form->get_ID()) { |
|
| 99 | + if ( ! empty($data['form_level']) && 'custom' != (string) strtolower($data['form_level'])) { |
|
| 100 | 100 | $prices = (array) $form->get_prices(); |
| 101 | 101 | $price_text = array(); |
| 102 | - foreach ( $prices as $key => $price ) { |
|
| 103 | - if ( isset( $price['_give_id']['level_id'] ) ) { |
|
| 104 | - $price_text[ $price['_give_id']['level_id'] ] = ( ! empty( $price['_give_text'] ) ? $price['_give_text'] : '' ); |
|
| 102 | + foreach ($prices as $key => $price) { |
|
| 103 | + if (isset($price['_give_id']['level_id'])) { |
|
| 104 | + $price_text[$price['_give_id']['level_id']] = ( ! empty($price['_give_text']) ? $price['_give_text'] : ''); |
|
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if ( ! in_array( $data['form_level'], $price_text ) ) { |
|
| 108 | + if ( ! in_array($data['form_level'], $price_text)) { |
|
| 109 | 109 | |
| 110 | 110 | // For generating unquiet level id. |
| 111 | 111 | $count = 1; |
| 112 | - $new_level = count( $prices ) + $count; |
|
| 113 | - while ( array_key_exists( $new_level, $price_text ) ) { |
|
| 114 | - $count ++; |
|
| 115 | - $new_level = count( $prices ) + $count; |
|
| 112 | + $new_level = count($prices) + $count; |
|
| 113 | + while (array_key_exists($new_level, $price_text)) { |
|
| 114 | + $count++; |
|
| 115 | + $new_level = count($prices) + $count; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | $multi_level_donations = array( |
@@ -120,57 +120,57 @@ discard block |
||
| 120 | 120 | '_give_id' => array( |
| 121 | 121 | 'level_id' => $new_level, |
| 122 | 122 | ), |
| 123 | - '_give_amount' => give_sanitize_amount_for_db( $data['amount'] ), |
|
| 123 | + '_give_amount' => give_sanitize_amount_for_db($data['amount']), |
|
| 124 | 124 | '_give_text' => $data['form_level'], |
| 125 | 125 | ), |
| 126 | 126 | ); |
| 127 | 127 | |
| 128 | - $price_text[ $new_level ] = $data['form_level']; |
|
| 128 | + $price_text[$new_level] = $data['form_level']; |
|
| 129 | 129 | |
| 130 | - if ( ! empty( $prices ) && is_array( $prices ) && ! empty( $prices[0] ) ) { |
|
| 131 | - $prices = wp_parse_args( $multi_level_donations, $prices ); |
|
| 130 | + if ( ! empty($prices) && is_array($prices) && ! empty($prices[0])) { |
|
| 131 | + $prices = wp_parse_args($multi_level_donations, $prices); |
|
| 132 | 132 | |
| 133 | 133 | // Sort $prices by amount in ascending order. |
| 134 | - $prices = wp_list_sort( $prices, '_give_amount', 'ASC' ); |
|
| 134 | + $prices = wp_list_sort($prices, '_give_amount', 'ASC'); |
|
| 135 | 135 | } else { |
| 136 | 136 | $prices = $multi_level_donations; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // Unset _give_default key from $prices. |
| 140 | - foreach ( $prices as $key => $price ) { |
|
| 141 | - if ( isset( $prices[ $key ]['_give_default'] ) ) { |
|
| 142 | - unset( $prices[ $key ]['_give_default'] ); |
|
| 140 | + foreach ($prices as $key => $price) { |
|
| 141 | + if (isset($prices[$key]['_give_default'])) { |
|
| 142 | + unset($prices[$key]['_give_default']); |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | // Set the first $price of the $prices as defalut. |
| 147 | 147 | $prices[0]['_give_default'] = 'default'; |
| 148 | 148 | } |
| 149 | - $form->price_id = array_search( $data['form_level'], $price_text ); |
|
| 149 | + $form->price_id = array_search($data['form_level'], $price_text); |
|
| 150 | 150 | |
| 151 | - $donation_levels_amounts = wp_list_pluck( $prices, '_give_amount' ); |
|
| 152 | - $min_amount = min( $donation_levels_amounts ); |
|
| 153 | - $max_amount = max( $donation_levels_amounts ); |
|
| 151 | + $donation_levels_amounts = wp_list_pluck($prices, '_give_amount'); |
|
| 152 | + $min_amount = min($donation_levels_amounts); |
|
| 153 | + $max_amount = max($donation_levels_amounts); |
|
| 154 | 154 | |
| 155 | 155 | $meta = array( |
| 156 | 156 | '_give_levels_minimum_amount' => $min_amount, |
| 157 | 157 | '_give_levels_maximum_amount' => $max_amount, |
| 158 | 158 | '_give_price_option' => 'multi', |
| 159 | - '_give_donation_levels' => array_values( $prices ), |
|
| 159 | + '_give_donation_levels' => array_values($prices), |
|
| 160 | 160 | ); |
| 161 | 161 | } else { |
| 162 | 162 | $form->price_id = 'custom'; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | $defaults = array( |
| 166 | - '_give_set_price' => give_sanitize_amount_for_db( $data['amount'] ), |
|
| 166 | + '_give_set_price' => give_sanitize_amount_for_db($data['amount']), |
|
| 167 | 167 | '_give_price_option' => 'set', |
| 168 | 168 | ); |
| 169 | 169 | |
| 170 | 170 | // If new form is created. |
| 171 | - if ( ! empty( $new_form ) ) { |
|
| 171 | + if ( ! empty($new_form)) { |
|
| 172 | 172 | $new_form = array( |
| 173 | - '_give_custom_amount_text' => ( ! empty( $data['form_custom_amount_text'] ) ? $data['form_custom_amount_text'] : 'Custom' ), |
|
| 173 | + '_give_custom_amount_text' => ( ! empty($data['form_custom_amount_text']) ? $data['form_custom_amount_text'] : 'Custom'), |
|
| 174 | 174 | '_give_logged_in_only' => 'enabled', |
| 175 | 175 | '_give_custom_amount' => 'enabled', |
| 176 | 176 | '_give_payment_import' => true, |
@@ -181,18 +181,18 @@ discard block |
||
| 181 | 181 | '_give_default_gateway' => 'global', |
| 182 | 182 | '_give_show_register_form' => 'both', |
| 183 | 183 | ); |
| 184 | - $defaults = wp_parse_args( $defaults, $new_form ); |
|
| 184 | + $defaults = wp_parse_args($defaults, $new_form); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - $meta = wp_parse_args( $meta, $defaults ); |
|
| 187 | + $meta = wp_parse_args($meta, $defaults); |
|
| 188 | 188 | |
| 189 | - foreach ( $meta as $key => $value ) { |
|
| 190 | - give_update_meta( $form->get_ID(), $key, $value ); |
|
| 189 | + foreach ($meta as $key => $value) { |
|
| 190 | + give_update_meta($form->get_ID(), $key, $value); |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | // update the report |
| 195 | - give_import_donation_report_update( $report ); |
|
| 195 | + give_import_donation_report_update($report); |
|
| 196 | 196 | |
| 197 | 197 | return $form; |
| 198 | 198 | } |
@@ -206,30 +206,30 @@ discard block |
||
| 206 | 206 | * |
| 207 | 207 | * @return bool|false|WP_User |
| 208 | 208 | */ |
| 209 | -function give_import_get_user_from_csv( $data, $import_setting = array() ) { |
|
| 209 | +function give_import_get_user_from_csv($data, $import_setting = array()) { |
|
| 210 | 210 | $report = give_import_donation_report(); |
| 211 | 211 | $donor_data = false; |
| 212 | 212 | $customer_id = false; |
| 213 | 213 | |
| 214 | 214 | // check if donor id is not empty |
| 215 | - if ( ! empty( $data['donor_id'] ) ) { |
|
| 216 | - $donor_data = new Give_Donor( (int) $data['donor_id'] ); |
|
| 217 | - if ( ! empty( $donor_data->id ) ) { |
|
| 218 | - $report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 ); |
|
| 215 | + if ( ! empty($data['donor_id'])) { |
|
| 216 | + $donor_data = new Give_Donor((int) $data['donor_id']); |
|
| 217 | + if ( ! empty($donor_data->id)) { |
|
| 218 | + $report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1); |
|
| 219 | 219 | } |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - if ( empty( $donor_data->id ) && ! empty( $data['user_id'] ) ) { |
|
| 222 | + if (empty($donor_data->id) && ! empty($data['user_id'])) { |
|
| 223 | 223 | $user_id = (int) $data['user_id']; |
| 224 | - $donor_data = new Give_Donor( $user_id, true ); |
|
| 224 | + $donor_data = new Give_Donor($user_id, true); |
|
| 225 | 225 | |
| 226 | 226 | |
| 227 | - if ( empty( $donor_data->id ) ) { |
|
| 228 | - $donor_data = get_user_by( 'id', $user_id ); |
|
| 229 | - if ( ! empty( $donor_data->ID ) ) { |
|
| 230 | - $first_name = ( ! empty( $data['first_name'] ) ? $data['first_name'] : $donor_data->user_nicename ); |
|
| 231 | - $last_name = ( ! empty( $data['last_name'] ) ? $data['last_name'] : ( ( $lastname = get_user_meta( $donor_data->ID, 'last_name', true ) ) ? $lastname : '' ) ); |
|
| 232 | - $name = $first_name . ' ' . $last_name; |
|
| 227 | + if (empty($donor_data->id)) { |
|
| 228 | + $donor_data = get_user_by('id', $user_id); |
|
| 229 | + if ( ! empty($donor_data->ID)) { |
|
| 230 | + $first_name = ( ! empty($data['first_name']) ? $data['first_name'] : $donor_data->user_nicename); |
|
| 231 | + $last_name = ( ! empty($data['last_name']) ? $data['last_name'] : (($lastname = get_user_meta($donor_data->ID, 'last_name', true)) ? $lastname : '')); |
|
| 232 | + $name = $first_name.' '.$last_name; |
|
| 233 | 233 | $user_email = $donor_data->user_email; |
| 234 | 234 | $donor_args = array( |
| 235 | 235 | 'name' => $name, |
@@ -238,44 +238,44 @@ discard block |
||
| 238 | 238 | ); |
| 239 | 239 | |
| 240 | 240 | $donor_data = new Give_Donor(); |
| 241 | - $donor_data->create( $donor_args ); |
|
| 241 | + $donor_data->create($donor_args); |
|
| 242 | 242 | |
| 243 | 243 | // Adding notes that donor is being imported from CSV. |
| 244 | 244 | $current_user = wp_get_current_user(); |
| 245 | - $donor_data->add_note( esc_html( wp_sprintf( __( 'This donor was imported by %s', 'give' ), $current_user->user_email ) ) ); |
|
| 245 | + $donor_data->add_note(esc_html(wp_sprintf(__('This donor was imported by %s', 'give'), $current_user->user_email))); |
|
| 246 | 246 | |
| 247 | 247 | // Add is used to ensure duplicate emails are not added |
| 248 | - if ( $user_email != $data['email'] && ! empty( $data['email'] ) ) { |
|
| 249 | - $donor_data->add_meta( 'additional_email', $data['email'] ); |
|
| 248 | + if ($user_email != $data['email'] && ! empty($data['email'])) { |
|
| 249 | + $donor_data->add_meta('additional_email', $data['email']); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - $report['create_donor'] = ( ! empty( $report['create_donor'] ) ? ( absint( $report['create_donor'] ) + 1 ) : 1 ); |
|
| 252 | + $report['create_donor'] = ( ! empty($report['create_donor']) ? (absint($report['create_donor']) + 1) : 1); |
|
| 253 | 253 | } else { |
| 254 | 254 | } |
| 255 | 255 | } else { |
| 256 | 256 | // Add is used to ensure duplicate emails are not added |
| 257 | - if ( $donor_data->email != $data['email'] ) { |
|
| 258 | - $donor_data->add_meta( 'additional_email', ( ! empty( $data['email'] ) ? $data['email'] : $donor_data->email ) ); |
|
| 257 | + if ($donor_data->email != $data['email']) { |
|
| 258 | + $donor_data->add_meta('additional_email', ( ! empty($data['email']) ? $data['email'] : $donor_data->email)); |
|
| 259 | 259 | } |
| 260 | - $report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 ); |
|
| 260 | + $report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1); |
|
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - if ( empty( $donor_data->id ) && ! empty( $data['email'] ) ) { |
|
| 264 | + if (empty($donor_data->id) && ! empty($data['email'])) { |
|
| 265 | 265 | |
| 266 | - $donor_data = new Give_Donor( $data['email'] ); |
|
| 267 | - if ( empty( $donor_data->id ) ) { |
|
| 268 | - $donor_data = get_user_by( 'email', $data['email'] ); |
|
| 266 | + $donor_data = new Give_Donor($data['email']); |
|
| 267 | + if (empty($donor_data->id)) { |
|
| 268 | + $donor_data = get_user_by('email', $data['email']); |
|
| 269 | 269 | |
| 270 | - if ( empty( $donor_data->ID ) && ! empty( $data['first_name'] ) && ! empty( $data['last_name'] ) && isset( $import_setting['create_user'] ) && 1 === absint( $import_setting['create_user'] ) ) { |
|
| 271 | - $give_role = (array) give_get_option( 'donor_default_user_role', get_option( 'default_role', ( ( $give_donor = wp_roles()->is_role( 'give_donor' ) ) && ! empty( $give_donor ) ? 'give_donor' : 'subscriber' ) ) ); |
|
| 270 | + if (empty($donor_data->ID) && ! empty($data['first_name']) && ! empty($data['last_name']) && isset($import_setting['create_user']) && 1 === absint($import_setting['create_user'])) { |
|
| 271 | + $give_role = (array) give_get_option('donor_default_user_role', get_option('default_role', (($give_donor = wp_roles()->is_role('give_donor')) && ! empty($give_donor) ? 'give_donor' : 'subscriber'))); |
|
| 272 | 272 | $donor_args = array( |
| 273 | 273 | 'user_login' => $data['email'], |
| 274 | 274 | 'user_email' => $data['email'], |
| 275 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
| 275 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
| 276 | 276 | 'user_first' => $data['first_name'], |
| 277 | 277 | 'user_last' => $data['last_name'], |
| 278 | - 'user_pass' => wp_generate_password( 8, true ), |
|
| 278 | + 'user_pass' => wp_generate_password(8, true), |
|
| 279 | 279 | 'role' => $give_role, |
| 280 | 280 | ); |
| 281 | 281 | |
@@ -284,56 +284,56 @@ discard block |
||
| 284 | 284 | * |
| 285 | 285 | * @since 1.8.13 |
| 286 | 286 | */ |
| 287 | - $donor_args = (array) apply_filters( 'give_import_insert_user_args', $donor_args, $data, $import_setting ); |
|
| 287 | + $donor_args = (array) apply_filters('give_import_insert_user_args', $donor_args, $data, $import_setting); |
|
| 288 | 288 | |
| 289 | 289 | // This action was added to remove the login when using the give register function. |
| 290 | - add_filter( 'give_log_user_in_on_register', 'give_log_user_in_on_register_callback', 11 ); |
|
| 291 | - $customer_id = give_register_and_login_new_user( $donor_args ); |
|
| 292 | - remove_filter( 'give_log_user_in_on_register', 'give_log_user_in_on_register_callback', 11 ); |
|
| 290 | + add_filter('give_log_user_in_on_register', 'give_log_user_in_on_register_callback', 11); |
|
| 291 | + $customer_id = give_register_and_login_new_user($donor_args); |
|
| 292 | + remove_filter('give_log_user_in_on_register', 'give_log_user_in_on_register_callback', 11); |
|
| 293 | 293 | |
| 294 | - update_user_meta( $customer_id, '_give_payment_import', true ); |
|
| 295 | - $donor_data = new Give_Donor( $customer_id, true ); |
|
| 294 | + update_user_meta($customer_id, '_give_payment_import', true); |
|
| 295 | + $donor_data = new Give_Donor($customer_id, true); |
|
| 296 | 296 | } else { |
| 297 | - $customer_id = ( ! empty( $donor_data->ID ) ? $donor_data->ID : false ); |
|
| 297 | + $customer_id = ( ! empty($donor_data->ID) ? $donor_data->ID : false); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - if ( ! empty( $customer_id ) || ( isset( $import_setting['create_user'] ) && 0 === absint( $import_setting['create_user'] ) ) ) { |
|
| 301 | - $donor_data = new Give_Donor( $customer_id, true ); |
|
| 300 | + if ( ! empty($customer_id) || (isset($import_setting['create_user']) && 0 === absint($import_setting['create_user']))) { |
|
| 301 | + $donor_data = new Give_Donor($customer_id, true); |
|
| 302 | 302 | |
| 303 | - if ( empty( $donor_data->id ) ) { |
|
| 303 | + if (empty($donor_data->id)) { |
|
| 304 | 304 | |
| 305 | - if ( ! empty( $data['form_id'] ) ) { |
|
| 306 | - $form = new Give_Donate_Form( $data['form_id'] ); |
|
| 305 | + if ( ! empty($data['form_id'])) { |
|
| 306 | + $form = new Give_Donate_Form($data['form_id']); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - $payment_title = ( isset( $data['form_title'] ) ? $data['form_title'] : ( isset( $form ) ? $form->get_name() : esc_html__( 'New Form', 'give' ) ) ); |
|
| 309 | + $payment_title = (isset($data['form_title']) ? $data['form_title'] : (isset($form) ? $form->get_name() : esc_html__('New Form', 'give'))); |
|
| 310 | 310 | $donor_args = array( |
| 311 | - 'name' => ! is_email( $payment_title ) ? $data['first_name'] . ' ' . $data['last_name'] : '', |
|
| 311 | + 'name' => ! is_email($payment_title) ? $data['first_name'].' '.$data['last_name'] : '', |
|
| 312 | 312 | 'email' => $data['email'], |
| 313 | 313 | ); |
| 314 | 314 | |
| 315 | - if ( ! empty( $customer_id ) ) { |
|
| 315 | + if ( ! empty($customer_id)) { |
|
| 316 | 316 | $donor_args['user_id'] = $customer_id; |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - $donor_data->create( $donor_args ); |
|
| 319 | + $donor_data->create($donor_args); |
|
| 320 | 320 | |
| 321 | 321 | // Adding notes that donor is being imported from CSV. |
| 322 | 322 | $current_user = wp_get_current_user(); |
| 323 | - $donor_data->add_note( esc_html( wp_sprintf( __( 'This donor was imported by %s', 'give' ), $current_user->user_email ) ) ); |
|
| 323 | + $donor_data->add_note(esc_html(wp_sprintf(__('This donor was imported by %s', 'give'), $current_user->user_email))); |
|
| 324 | 324 | |
| 325 | - $report['create_donor'] = ( ! empty( $report['create_donor'] ) ? ( absint( $report['create_donor'] ) + 1 ) : 1 ); |
|
| 325 | + $report['create_donor'] = ( ! empty($report['create_donor']) ? (absint($report['create_donor']) + 1) : 1); |
|
| 326 | 326 | } else { |
| 327 | - $report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 ); |
|
| 327 | + $report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1); |
|
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | } else { |
| 331 | - $report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 ); |
|
| 331 | + $report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | // update the report |
| 336 | - give_import_donation_report_update( $report ); |
|
| 336 | + give_import_donation_report_update($report); |
|
| 337 | 337 | |
| 338 | 338 | return $donor_data; |
| 339 | 339 | } |
@@ -351,9 +351,9 @@ discard block |
||
| 351 | 351 | * |
| 352 | 352 | * @return array |
| 353 | 353 | */ |
| 354 | - return (array) apply_filters( 'give_import_default_options', array( |
|
| 355 | - '' => __( 'Do not import', 'give' ), |
|
| 356 | - ) ); |
|
| 354 | + return (array) apply_filters('give_import_default_options', array( |
|
| 355 | + '' => __('Do not import', 'give'), |
|
| 356 | + )); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -369,25 +369,25 @@ discard block |
||
| 369 | 369 | * |
| 370 | 370 | * @return array |
| 371 | 371 | */ |
| 372 | - return (array) apply_filters( 'give_import_donations_options', array( |
|
| 373 | - 'id' => __( 'Donation ID', 'give' ), |
|
| 374 | - 'amount' => __( 'Donation Amount', 'give' ), |
|
| 375 | - 'post_date' => __( 'Donation Date', 'give' ), |
|
| 376 | - 'first_name' => __( 'Donor First Name', 'give' ), |
|
| 377 | - 'last_name' => __( 'Donor Last Name', 'give' ), |
|
| 378 | - 'line1' => __( 'Address 1', 'give' ), |
|
| 379 | - 'line2' => __( 'Address 2', 'give' ), |
|
| 380 | - 'city' => __( 'City', 'give' ), |
|
| 381 | - 'state' => __( 'State', 'give' ), |
|
| 382 | - 'country' => __( 'Country', 'give' ), |
|
| 383 | - 'zip' => __( 'Zip', 'give' ), |
|
| 384 | - 'email' => __( 'Donor Email', 'give' ), |
|
| 385 | - 'post_status' => __( 'Donation Status', 'give' ), |
|
| 386 | - 'gateway' => __( 'Payment Method', 'give' ), |
|
| 387 | - 'notes' => __( 'Notes', 'give' ), |
|
| 388 | - 'mode' => __( 'Test Mode', 'give' ), |
|
| 389 | - 'post_meta' => __( 'Import as Meta', 'give' ), |
|
| 390 | - ) ); |
|
| 372 | + return (array) apply_filters('give_import_donations_options', array( |
|
| 373 | + 'id' => __('Donation ID', 'give'), |
|
| 374 | + 'amount' => __('Donation Amount', 'give'), |
|
| 375 | + 'post_date' => __('Donation Date', 'give'), |
|
| 376 | + 'first_name' => __('Donor First Name', 'give'), |
|
| 377 | + 'last_name' => __('Donor Last Name', 'give'), |
|
| 378 | + 'line1' => __('Address 1', 'give'), |
|
| 379 | + 'line2' => __('Address 2', 'give'), |
|
| 380 | + 'city' => __('City', 'give'), |
|
| 381 | + 'state' => __('State', 'give'), |
|
| 382 | + 'country' => __('Country', 'give'), |
|
| 383 | + 'zip' => __('Zip', 'give'), |
|
| 384 | + 'email' => __('Donor Email', 'give'), |
|
| 385 | + 'post_status' => __('Donation Status', 'give'), |
|
| 386 | + 'gateway' => __('Payment Method', 'give'), |
|
| 387 | + 'notes' => __('Notes', 'give'), |
|
| 388 | + 'mode' => __('Test Mode', 'give'), |
|
| 389 | + 'post_meta' => __('Import as Meta', 'give'), |
|
| 390 | + )); |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | /** |
@@ -403,10 +403,10 @@ discard block |
||
| 403 | 403 | * |
| 404 | 404 | * @return array |
| 405 | 405 | */ |
| 406 | - return (array) apply_filters( 'give_import_donor_options', array( |
|
| 407 | - 'donor_id' => __( 'Donor ID', 'give' ), |
|
| 408 | - 'user_id' => __( 'User ID', 'give' ), |
|
| 409 | - ) ); |
|
| 406 | + return (array) apply_filters('give_import_donor_options', array( |
|
| 407 | + 'donor_id' => __('Donor ID', 'give'), |
|
| 408 | + 'user_id' => __('User ID', 'give'), |
|
| 409 | + )); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -422,12 +422,12 @@ discard block |
||
| 422 | 422 | * |
| 423 | 423 | * @return array |
| 424 | 424 | */ |
| 425 | - return (array) apply_filters( 'give_import_donation_form_options', array( |
|
| 426 | - 'form_title' => __( 'Donation Form', 'give' ), |
|
| 427 | - 'form_id' => __( 'Donation Form ID', 'give' ), |
|
| 428 | - 'form_level' => __( 'Donation Level', 'give' ), |
|
| 429 | - 'form_custom_amount_text' => __( 'Custom Amount Text', 'give' ), |
|
| 430 | - ) ); |
|
| 425 | + return (array) apply_filters('give_import_donation_form_options', array( |
|
| 426 | + 'form_title' => __('Donation Form', 'give'), |
|
| 427 | + 'form_id' => __('Donation Form ID', 'give'), |
|
| 428 | + 'form_level' => __('Donation Level', 'give'), |
|
| 429 | + 'form_custom_amount_text' => __('Custom Amount Text', 'give'), |
|
| 430 | + )); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | * |
| 441 | 441 | * @return array |
| 442 | 442 | */ |
| 443 | -function give_get_donation_data_from_csv( $file_id, $start, $end, $delimiter = 'csv' ) { |
|
| 443 | +function give_get_donation_data_from_csv($file_id, $start, $end, $delimiter = 'csv') { |
|
| 444 | 444 | /** |
| 445 | 445 | * Filter to modify delimiter of Import. |
| 446 | 446 | * |
@@ -449,19 +449,19 @@ discard block |
||
| 449 | 449 | * |
| 450 | 450 | * Return string $delimiter. |
| 451 | 451 | */ |
| 452 | - $delimiter = (string) apply_filters( 'give_import_delimiter_set', $delimiter ); |
|
| 452 | + $delimiter = (string) apply_filters('give_import_delimiter_set', $delimiter); |
|
| 453 | 453 | |
| 454 | 454 | $raw_data = array(); |
| 455 | - $file_dir = get_attached_file( $file_id ); |
|
| 455 | + $file_dir = get_attached_file($file_id); |
|
| 456 | 456 | $count = 0; |
| 457 | - if ( false !== ( $handle = fopen( $file_dir, 'r' ) ) ) { |
|
| 458 | - while ( false !== ( $row = fgetcsv( $handle, 0, $delimiter ) ) ) { |
|
| 459 | - if ( $count >= $start && $count <= $end ) { |
|
| 457 | + if (false !== ($handle = fopen($file_dir, 'r'))) { |
|
| 458 | + while (false !== ($row = fgetcsv($handle, 0, $delimiter))) { |
|
| 459 | + if ($count >= $start && $count <= $end) { |
|
| 460 | 460 | $raw_data[] = $row; |
| 461 | 461 | } |
| 462 | - $count ++; |
|
| 462 | + $count++; |
|
| 463 | 463 | } |
| 464 | - fclose( $handle ); |
|
| 464 | + fclose($handle); |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | return $raw_data; |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | * |
| 478 | 478 | * @return bool |
| 479 | 479 | */ |
| 480 | -function give_log_user_in_on_register_callback( $value ) { |
|
| 480 | +function give_log_user_in_on_register_callback($value) { |
|
| 481 | 481 | return false; |
| 482 | 482 | } |
| 483 | 483 | |
@@ -493,22 +493,22 @@ discard block |
||
| 493 | 493 | * |
| 494 | 494 | * @return bool |
| 495 | 495 | */ |
| 496 | -function give_save_import_donation_to_db( $raw_key, $row_data, $main_key = array(), $import_setting = array() ) { |
|
| 497 | - $data = array_combine( $raw_key, $row_data ); |
|
| 496 | +function give_save_import_donation_to_db($raw_key, $row_data, $main_key = array(), $import_setting = array()) { |
|
| 497 | + $data = array_combine($raw_key, $row_data); |
|
| 498 | 498 | $price_id = false; |
| 499 | 499 | $customer_id = 0; |
| 500 | - $import_setting['create_user'] = ( isset( $import_setting['create_user'] ) ? $import_setting['create_user'] : 1 ); |
|
| 500 | + $import_setting['create_user'] = (isset($import_setting['create_user']) ? $import_setting['create_user'] : 1); |
|
| 501 | 501 | |
| 502 | - $data = (array) apply_filters( 'give_save_import_donation_to_db', $data ); |
|
| 502 | + $data = (array) apply_filters('give_save_import_donation_to_db', $data); |
|
| 503 | 503 | |
| 504 | - $data['amount'] = give_maybe_sanitize_amount( $data['amount'] ); |
|
| 504 | + $data['amount'] = give_maybe_sanitize_amount($data['amount']); |
|
| 505 | 505 | |
| 506 | 506 | // Here come the login function. |
| 507 | - $donor_data = give_import_get_user_from_csv( $data, $import_setting ); |
|
| 508 | - if ( ! empty( $donor_data->id ) ) { |
|
| 509 | - if ( ! empty( $donor_data->user_id ) ) { |
|
| 507 | + $donor_data = give_import_get_user_from_csv($data, $import_setting); |
|
| 508 | + if ( ! empty($donor_data->id)) { |
|
| 509 | + if ( ! empty($donor_data->user_id)) { |
|
| 510 | 510 | $customer_id = $donor_data->user_id; |
| 511 | - } elseif ( ! empty( $data['user_id'] ) ) { |
|
| 511 | + } elseif ( ! empty($data['user_id'])) { |
|
| 512 | 512 | $customer_id = $data['user_id']; |
| 513 | 513 | } |
| 514 | 514 | } else { |
@@ -516,95 +516,95 @@ discard block |
||
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | // get form data or register a form data. |
| 519 | - $form = give_import_get_form_data_from_csv( $data, $import_setting ); |
|
| 520 | - if ( false == $form ) { |
|
| 519 | + $form = give_import_get_form_data_from_csv($data, $import_setting); |
|
| 520 | + if (false == $form) { |
|
| 521 | 521 | return false; |
| 522 | 522 | } else { |
| 523 | - $price_id = ( ! empty( $form->price_id ) ) ? $form->price_id : false; |
|
| 523 | + $price_id = ( ! empty($form->price_id)) ? $form->price_id : false; |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | |
| 527 | 527 | $address = array( |
| 528 | - 'line1' => ( ! empty( $data['line1'] ) ? give_clean( $data['line1'] ) : '' ), |
|
| 529 | - 'line2' => ( ! empty( $data['line1'] ) ? give_clean( $data['line2'] ) : '' ), |
|
| 530 | - 'city' => ( ! empty( $data['line1'] ) ? give_clean( $data['city'] ) : '' ), |
|
| 531 | - 'zip' => ( ! empty( $data['zip'] ) ? give_clean( $data['zip'] ) : '' ), |
|
| 532 | - 'state' => ( ! empty( $data['state'] ) ? give_clean( $data['state'] ) : '' ), |
|
| 533 | - 'country' => ( ! empty( $data['country'] ) ? ( ( $country_code = array_search( $data['country'], give_get_country_list() ) ) ? $country_code : $data['country'] ) : '' ), |
|
| 528 | + 'line1' => ( ! empty($data['line1']) ? give_clean($data['line1']) : ''), |
|
| 529 | + 'line2' => ( ! empty($data['line1']) ? give_clean($data['line2']) : ''), |
|
| 530 | + 'city' => ( ! empty($data['line1']) ? give_clean($data['city']) : ''), |
|
| 531 | + 'zip' => ( ! empty($data['zip']) ? give_clean($data['zip']) : ''), |
|
| 532 | + 'state' => ( ! empty($data['state']) ? give_clean($data['state']) : ''), |
|
| 533 | + 'country' => ( ! empty($data['country']) ? (($country_code = array_search($data['country'], give_get_country_list())) ? $country_code : $data['country']) : ''), |
|
| 534 | 534 | ); |
| 535 | 535 | |
| 536 | 536 | //Create payment_data array |
| 537 | 537 | $payment_data = array( |
| 538 | 538 | 'donor_id' => $donor_data->id, |
| 539 | 539 | 'price' => $data['amount'], |
| 540 | - 'status' => ( ! empty( $data['post_status'] ) ? $data['post_status'] : 'publish' ), |
|
| 540 | + 'status' => ( ! empty($data['post_status']) ? $data['post_status'] : 'publish'), |
|
| 541 | 541 | 'currency' => give_get_currency(), |
| 542 | 542 | 'user_info' => array( |
| 543 | 543 | 'id' => $customer_id, |
| 544 | - 'email' => ( ! empty( $data['email'] ) ? $data['email'] : ( isset( $donor_data->email ) ? $donor_data->email : false ) ), |
|
| 545 | - 'first_name' => ( ! empty( $data['first_name'] ) ? $data['first_name'] : ( ! empty( $customer_id ) && ( $first_name = get_user_meta( $customer_id, 'first_name', true ) ) ? $first_name : $donor_data->name ) ), |
|
| 546 | - 'last_name' => ( ! empty( $data['last_name'] ) ? $data['last_name'] : ( ! empty( $customer_id ) && ( $last_name = get_user_meta( $customer_id, 'last_name', true ) ) ? $last_name : $donor_data->name ) ), |
|
| 544 | + 'email' => ( ! empty($data['email']) ? $data['email'] : (isset($donor_data->email) ? $donor_data->email : false)), |
|
| 545 | + 'first_name' => ( ! empty($data['first_name']) ? $data['first_name'] : ( ! empty($customer_id) && ($first_name = get_user_meta($customer_id, 'first_name', true)) ? $first_name : $donor_data->name)), |
|
| 546 | + 'last_name' => ( ! empty($data['last_name']) ? $data['last_name'] : ( ! empty($customer_id) && ($last_name = get_user_meta($customer_id, 'last_name', true)) ? $last_name : $donor_data->name)), |
|
| 547 | 547 | 'address' => $address, |
| 548 | 548 | ), |
| 549 | - 'gateway' => ( ! empty( $data['gateway'] ) && 'offline' != strtolower( $data['gateway'] ) ? strtolower( $data['gateway'] ) : 'manual' ), |
|
| 550 | - 'give_form_title' => ( ! empty( $data['form_title'] ) ? $data['form_title'] : $form->get_name() ), |
|
| 549 | + 'gateway' => ( ! empty($data['gateway']) && 'offline' != strtolower($data['gateway']) ? strtolower($data['gateway']) : 'manual'), |
|
| 550 | + 'give_form_title' => ( ! empty($data['form_title']) ? $data['form_title'] : $form->get_name()), |
|
| 551 | 551 | 'give_form_id' => (string) $form->get_ID(), |
| 552 | 552 | 'give_price_id' => $price_id, |
| 553 | - 'purchase_key' => strtolower( md5( uniqid() ) ), |
|
| 553 | + 'purchase_key' => strtolower(md5(uniqid())), |
|
| 554 | 554 | 'user_email' => $data['email'], |
| 555 | - 'post_date' => ( ! empty( $data['post_date'] ) ? mysql2date( 'Y-m-d H:i:s', $data['post_date'] ) : current_time( 'mysql' ) ), |
|
| 556 | - 'mode' => ( ! empty( $data['mode'] ) ? ( 'true' == (string) $data['mode'] || 'TRUE' == (string) $data['mode'] ? 'test' : 'live' ) : ( isset( $import_setting['mode'] ) ? ( true == (bool) $import_setting['mode'] ? 'test' : 'live' ) : ( give_is_test_mode() ? 'test' : 'live' ) ) ), |
|
| 555 | + 'post_date' => ( ! empty($data['post_date']) ? mysql2date('Y-m-d H:i:s', $data['post_date']) : current_time('mysql')), |
|
| 556 | + 'mode' => ( ! empty($data['mode']) ? ('true' == (string) $data['mode'] || 'TRUE' == (string) $data['mode'] ? 'test' : 'live') : (isset($import_setting['mode']) ? (true == (bool) $import_setting['mode'] ? 'test' : 'live') : (give_is_test_mode() ? 'test' : 'live'))), |
|
| 557 | 557 | ); |
| 558 | 558 | |
| 559 | - $payment_data = apply_filters( 'give_import_before_import_payment', $payment_data, $data, $donor_data, $form ); |
|
| 559 | + $payment_data = apply_filters('give_import_before_import_payment', $payment_data, $data, $donor_data, $form); |
|
| 560 | 560 | |
| 561 | 561 | // Get the report |
| 562 | 562 | $report = give_import_donation_report(); |
| 563 | 563 | |
| 564 | 564 | // Check for duplicate code. |
| 565 | - if ( true === give_check_import_donation_duplicate( $payment_data, $data, $form, $donor_data ) ) { |
|
| 566 | - $report['duplicate_donation'] = ( ! empty( $report['duplicate_donation'] ) ? ( absint( $report['duplicate_donation'] ) + 1 ) : 1 ); |
|
| 565 | + if (true === give_check_import_donation_duplicate($payment_data, $data, $form, $donor_data)) { |
|
| 566 | + $report['duplicate_donation'] = ( ! empty($report['duplicate_donation']) ? (absint($report['duplicate_donation']) + 1) : 1); |
|
| 567 | 567 | } else { |
| 568 | - add_action( 'give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1, 1 ); |
|
| 569 | - add_filter( 'give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11, 2 ); |
|
| 570 | - add_filter( 'give_update_donor_information', 'give_donation_import_update_donor_information', 11, 3 ); |
|
| 571 | - add_action( 'give_insert_payment', 'give_import_donation_insert_payment', 11, 2 ); |
|
| 572 | - $payment = give_insert_payment( $payment_data ); |
|
| 573 | - remove_action( 'give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1 ); |
|
| 574 | - remove_filter( 'give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11 ); |
|
| 575 | - remove_filter( 'give_update_donor_information', 'give_donation_import_update_donor_information', 11 ); |
|
| 576 | - remove_action( 'give_insert_payment', 'give_import_donation_insert_payment', 11 ); |
|
| 568 | + add_action('give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1, 1); |
|
| 569 | + add_filter('give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11, 2); |
|
| 570 | + add_filter('give_update_donor_information', 'give_donation_import_update_donor_information', 11, 3); |
|
| 571 | + add_action('give_insert_payment', 'give_import_donation_insert_payment', 11, 2); |
|
| 572 | + $payment = give_insert_payment($payment_data); |
|
| 573 | + remove_action('give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1); |
|
| 574 | + remove_filter('give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11); |
|
| 575 | + remove_filter('give_update_donor_information', 'give_donation_import_update_donor_information', 11); |
|
| 576 | + remove_action('give_insert_payment', 'give_import_donation_insert_payment', 11); |
|
| 577 | 577 | |
| 578 | - if ( $payment ) { |
|
| 578 | + if ($payment) { |
|
| 579 | 579 | |
| 580 | - $report['create_donation'] = ( ! empty( $report['create_donation'] ) ? ( absint( $report['create_donation'] ) + 1 ) : 1 ); |
|
| 580 | + $report['create_donation'] = ( ! empty($report['create_donation']) ? (absint($report['create_donation']) + 1) : 1); |
|
| 581 | 581 | |
| 582 | - update_post_meta( $payment, '_give_payment_import', true ); |
|
| 582 | + update_post_meta($payment, '_give_payment_import', true); |
|
| 583 | 583 | |
| 584 | - if ( ! empty( $import_setting['csv'] ) ) { |
|
| 585 | - update_post_meta( $payment, '_give_payment_import_id', $import_setting['csv'] ); |
|
| 584 | + if ( ! empty($import_setting['csv'])) { |
|
| 585 | + update_post_meta($payment, '_give_payment_import_id', $import_setting['csv']); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | // Insert Notes. |
| 589 | - if ( ! empty( $data['notes'] ) ) { |
|
| 590 | - give_insert_payment_note( $payment, $data['notes'] ); |
|
| 589 | + if ( ! empty($data['notes'])) { |
|
| 590 | + give_insert_payment_note($payment, $data['notes']); |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - $meta_exists = array_keys( $raw_key, 'post_meta' ); |
|
| 594 | - if ( ! empty( $main_key ) && ! empty( $meta_exists ) ) { |
|
| 595 | - foreach ( $meta_exists as $meta_exist ) { |
|
| 596 | - if ( ! empty( $main_key[ $meta_exist ] ) && ! empty( $row_data[ $meta_exist ] ) ) { |
|
| 597 | - update_post_meta( $payment, $main_key[ $meta_exist ], $row_data[ $meta_exist ] ); |
|
| 593 | + $meta_exists = array_keys($raw_key, 'post_meta'); |
|
| 594 | + if ( ! empty($main_key) && ! empty($meta_exists)) { |
|
| 595 | + foreach ($meta_exists as $meta_exist) { |
|
| 596 | + if ( ! empty($main_key[$meta_exist]) && ! empty($row_data[$meta_exist])) { |
|
| 597 | + update_post_meta($payment, $main_key[$meta_exist], $row_data[$meta_exist]); |
|
| 598 | 598 | } |
| 599 | 599 | } |
| 600 | 600 | } |
| 601 | 601 | } else { |
| 602 | - $report['failed_donation'] = ( ! empty( $report['failed_donation'] ) ? ( absint( $report['failed_donation'] ) + 1 ) : 1 ); |
|
| 602 | + $report['failed_donation'] = ( ! empty($report['failed_donation']) ? (absint($report['failed_donation']) + 1) : 1); |
|
| 603 | 603 | } |
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | // update the report |
| 607 | - give_import_donation_report_update( $report ); |
|
| 607 | + give_import_donation_report_update($report); |
|
| 608 | 608 | |
| 609 | 609 | return true; |
| 610 | 610 | } |
@@ -620,12 +620,12 @@ discard block |
||
| 620 | 620 | * |
| 621 | 621 | * @return Give_Donor |
| 622 | 622 | */ |
| 623 | -function give_donation_import_update_donor_information( $donor, $payment_id, $payment_data ) { |
|
| 623 | +function give_donation_import_update_donor_information($donor, $payment_id, $payment_data) { |
|
| 624 | 624 | $old_donor = $donor; |
| 625 | - if ( ! empty( $payment_data['donor_id'] ) ) { |
|
| 626 | - $donor_id = absint( $payment_data['donor_id'] ); |
|
| 627 | - $donor = new Give_Donor( $donor_id ); |
|
| 628 | - if ( ! empty( $donor->id ) ) { |
|
| 625 | + if ( ! empty($payment_data['donor_id'])) { |
|
| 626 | + $donor_id = absint($payment_data['donor_id']); |
|
| 627 | + $donor = new Give_Donor($donor_id); |
|
| 628 | + if ( ! empty($donor->id)) { |
|
| 629 | 629 | return $donor; |
| 630 | 630 | } |
| 631 | 631 | } |
@@ -638,12 +638,12 @@ discard block |
||
| 638 | 638 | * |
| 639 | 639 | * @since 1.8.13 |
| 640 | 640 | */ |
| 641 | -function give_import_donation_insert_payment( $payment_id, $payment_data ) { |
|
| 641 | +function give_import_donation_insert_payment($payment_id, $payment_data) { |
|
| 642 | 642 | // Update Give Customers purchase_count |
| 643 | - if ( ! empty( $payment_data['status'] ) && ( 'complete' === (string) $payment_data['status'] || 'publish' === (string) $payment_data['status'] ) ) { |
|
| 644 | - $donor_id = (int) get_post_meta( $payment_id, '_give_payment_customer_id', true ); |
|
| 645 | - if ( ! empty( $donor_id ) ) { |
|
| 646 | - $donor = new Give_Donor( $donor_id ); |
|
| 643 | + if ( ! empty($payment_data['status']) && ('complete' === (string) $payment_data['status'] || 'publish' === (string) $payment_data['status'])) { |
|
| 644 | + $donor_id = (int) get_post_meta($payment_id, '_give_payment_customer_id', true); |
|
| 645 | + if ( ! empty($donor_id)) { |
|
| 646 | + $donor = new Give_Donor($donor_id); |
|
| 647 | 647 | $donor->increase_purchase_count(); |
| 648 | 648 | } |
| 649 | 649 | } |
@@ -654,8 +654,8 @@ discard block |
||
| 654 | 654 | * |
| 655 | 655 | * @since 1.8.13 |
| 656 | 656 | */ |
| 657 | -function give_donation_import_give_insert_payment_args( $args, $payment_data ) { |
|
| 658 | - if ( ! empty( $payment_data['user_info']['id'] ) ) { |
|
| 657 | +function give_donation_import_give_insert_payment_args($args, $payment_data) { |
|
| 658 | + if ( ! empty($payment_data['user_info']['id'])) { |
|
| 659 | 659 | $args['post_author'] = (int) $payment_data['user_info']['id']; |
| 660 | 660 | } |
| 661 | 661 | |
@@ -667,11 +667,11 @@ discard block |
||
| 667 | 667 | * |
| 668 | 668 | * @since 1.8.13 |
| 669 | 669 | */ |
| 670 | -function give_check_import_donation_duplicate( $payment_data, $data, $form, $donor_data ) { |
|
| 670 | +function give_check_import_donation_duplicate($payment_data, $data, $form, $donor_data) { |
|
| 671 | 671 | $return = false; |
| 672 | - if ( ! empty( $data['post_date'] ) ) { |
|
| 673 | - $post_date = mysql2date( 'Y-m-d-H-i-s', $data['post_date'] ); |
|
| 674 | - $post_date = explode( '-', $post_date ); |
|
| 672 | + if ( ! empty($data['post_date'])) { |
|
| 673 | + $post_date = mysql2date('Y-m-d-H-i-s', $data['post_date']); |
|
| 674 | + $post_date = explode('-', $post_date); |
|
| 675 | 675 | $args = array( |
| 676 | 676 | 'post_type' => 'give_payment', |
| 677 | 677 | 'cache_results' => false, |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | 'meta_query' => array( |
| 693 | 693 | array( |
| 694 | 694 | 'key' => '_give_payment_total', |
| 695 | - 'value' => preg_replace( '/[\$,]/', '', $payment_data['price'] ), |
|
| 695 | + 'value' => preg_replace('/[\$,]/', '', $payment_data['price']), |
|
| 696 | 696 | 'compare' => 'LIKE', |
| 697 | 697 | ), |
| 698 | 698 | array( |
@@ -709,9 +709,9 @@ discard block |
||
| 709 | 709 | ), |
| 710 | 710 | ); |
| 711 | 711 | |
| 712 | - $payments = new Give_Payments_Query( $args ); |
|
| 712 | + $payments = new Give_Payments_Query($args); |
|
| 713 | 713 | $donations = $payments->get_payments(); |
| 714 | - if ( ! empty( $donations ) ) { |
|
| 714 | + if ( ! empty($donations)) { |
|
| 715 | 715 | return true; |
| 716 | 716 | } |
| 717 | 717 | } |
@@ -728,9 +728,9 @@ discard block |
||
| 728 | 728 | * |
| 729 | 729 | * @return void |
| 730 | 730 | */ |
| 731 | -function give_donation_import_insert_default_payment_note( $payment_id ) { |
|
| 731 | +function give_donation_import_insert_default_payment_note($payment_id) { |
|
| 732 | 732 | $current_user = wp_get_current_user(); |
| 733 | - give_insert_payment_note( $payment_id, esc_html( wp_sprintf( __( 'This donation was imported by %s', 'give' ), $current_user->user_email ) ) ); |
|
| 733 | + give_insert_payment_note($payment_id, esc_html(wp_sprintf(__('This donation was imported by %s', 'give'), $current_user->user_email))); |
|
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | /** |
@@ -742,14 +742,14 @@ discard block |
||
| 742 | 742 | * |
| 743 | 743 | * @return string URL |
| 744 | 744 | */ |
| 745 | -function give_import_page_url( $parameter = array() ) { |
|
| 745 | +function give_import_page_url($parameter = array()) { |
|
| 746 | 746 | $defalut_query_arg = array( |
| 747 | 747 | 'post_type' => 'give_forms', |
| 748 | 748 | 'page' => 'give-tools', |
| 749 | 749 | 'tab' => 'import', |
| 750 | 750 | 'importer-type' => 'import_donations', |
| 751 | 751 | ); |
| 752 | - $import_query_arg = wp_parse_args( $parameter, $defalut_query_arg ); |
|
| 752 | + $import_query_arg = wp_parse_args($parameter, $defalut_query_arg); |
|
| 753 | 753 | |
| 754 | - return add_query_arg( $import_query_arg, admin_url( 'edit.php' ) ); |
|
| 754 | + return add_query_arg($import_query_arg, admin_url('edit.php')); |
|
| 755 | 755 | } |
| 756 | 756 | \ No newline at end of file |