@@ -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 | $donor_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,45 +238,45 @@ 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 | } |
| 254 | 254 | } else { |
| 255 | 255 | // Add is used to ensure duplicate emails are not added |
| 256 | - if ( $donor_data->email != $data['email'] ) { |
|
| 257 | - $donor_data->add_meta( 'additional_email', ( ! empty( $data['email'] ) ? $data['email'] : $donor_data->email ) ); |
|
| 256 | + if ($donor_data->email != $data['email']) { |
|
| 257 | + $donor_data->add_meta('additional_email', ( ! empty($data['email']) ? $data['email'] : $donor_data->email)); |
|
| 258 | 258 | } |
| 259 | - $report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 ); |
|
| 259 | + $report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1); |
|
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - if ( empty( $donor_data->id ) && ! empty( $data['email'] ) ) { |
|
| 263 | + if (empty($donor_data->id) && ! empty($data['email'])) { |
|
| 264 | 264 | |
| 265 | - $donor_data = new Give_Donor( $data['email'] ); |
|
| 266 | - if ( empty( $donor_data->id ) ) { |
|
| 267 | - $donor_data = get_user_by( 'email', $data['email'] ); |
|
| 265 | + $donor_data = new Give_Donor($data['email']); |
|
| 266 | + if (empty($donor_data->id)) { |
|
| 267 | + $donor_data = get_user_by('email', $data['email']); |
|
| 268 | 268 | |
| 269 | - if ( empty( $donor_data->ID ) && isset( $import_setting['create_user'] ) && 1 === absint( $import_setting['create_user'] ) ) { |
|
| 270 | - $data['first_name'] = ( ! empty( $data['first_name'] ) ? $data['first_name'] : $data['email'] ); |
|
| 271 | - $data['last_name'] = ( ! empty( $data['last_name'] ) ? $data['last_name'] : '' ); |
|
| 272 | - $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' ) ) ); |
|
| 269 | + if (empty($donor_data->ID) && isset($import_setting['create_user']) && 1 === absint($import_setting['create_user'])) { |
|
| 270 | + $data['first_name'] = ( ! empty($data['first_name']) ? $data['first_name'] : $data['email']); |
|
| 271 | + $data['last_name'] = ( ! empty($data['last_name']) ? $data['last_name'] : ''); |
|
| 272 | + $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'))); |
|
| 273 | 273 | $donor_args = array( |
| 274 | 274 | 'user_login' => $data['email'], |
| 275 | 275 | 'user_email' => $data['email'], |
| 276 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
| 276 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
| 277 | 277 | 'user_first' => $data['first_name'], |
| 278 | 278 | 'user_last' => $data['last_name'], |
| 279 | - 'user_pass' => wp_generate_password( 8, true ), |
|
| 279 | + 'user_pass' => wp_generate_password(8, true), |
|
| 280 | 280 | 'role' => $give_role, |
| 281 | 281 | ); |
| 282 | 282 | |
@@ -285,55 +285,55 @@ discard block |
||
| 285 | 285 | * |
| 286 | 286 | * @since 1.8.13 |
| 287 | 287 | */ |
| 288 | - $donor_args = (array) apply_filters( 'give_import_insert_user_args', $donor_args, $data, $import_setting ); |
|
| 288 | + $donor_args = (array) apply_filters('give_import_insert_user_args', $donor_args, $data, $import_setting); |
|
| 289 | 289 | |
| 290 | 290 | // This action was added to remove the login when using the give register function. |
| 291 | - add_filter( 'give_log_user_in_on_register', 'give_log_user_in_on_register_callback', 11 ); |
|
| 292 | - $donor_id = give_register_and_login_new_user( $donor_args ); |
|
| 293 | - remove_filter( 'give_log_user_in_on_register', 'give_log_user_in_on_register_callback', 11 ); |
|
| 291 | + add_filter('give_log_user_in_on_register', 'give_log_user_in_on_register_callback', 11); |
|
| 292 | + $donor_id = give_register_and_login_new_user($donor_args); |
|
| 293 | + remove_filter('give_log_user_in_on_register', 'give_log_user_in_on_register_callback', 11); |
|
| 294 | 294 | |
| 295 | - update_user_meta( $donor_id, '_give_payment_import', true ); |
|
| 296 | - $donor_data = new Give_Donor( $donor_id, true ); |
|
| 295 | + update_user_meta($donor_id, '_give_payment_import', true); |
|
| 296 | + $donor_data = new Give_Donor($donor_id, true); |
|
| 297 | 297 | } else { |
| 298 | - $donor_id = ( ! empty( $donor_data->ID ) ? $donor_data->ID : false ); |
|
| 298 | + $donor_id = ( ! empty($donor_data->ID) ? $donor_data->ID : false); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - if ( ! empty( $donor_id ) || ( isset( $import_setting['create_user'] ) && 0 === absint( $import_setting['create_user'] ) ) ) { |
|
| 302 | - $donor_data = new Give_Donor( $donor_id, true ); |
|
| 301 | + if ( ! empty($donor_id) || (isset($import_setting['create_user']) && 0 === absint($import_setting['create_user']))) { |
|
| 302 | + $donor_data = new Give_Donor($donor_id, true); |
|
| 303 | 303 | |
| 304 | - if ( empty( $donor_data->id ) ) { |
|
| 304 | + if (empty($donor_data->id)) { |
|
| 305 | 305 | |
| 306 | - if ( ! empty( $data['form_id'] ) ) { |
|
| 307 | - $form = new Give_Donate_Form( $data['form_id'] ); |
|
| 306 | + if ( ! empty($data['form_id'])) { |
|
| 307 | + $form = new Give_Donate_Form($data['form_id']); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - $payment_title = ( isset( $data['form_title'] ) ? $data['form_title'] : ( isset( $form ) ? $form->get_name() : esc_html__( 'New Form', 'give' ) ) ); |
|
| 310 | + $payment_title = (isset($data['form_title']) ? $data['form_title'] : (isset($form) ? $form->get_name() : esc_html__('New Form', 'give'))); |
|
| 311 | 311 | $donor_args = array( |
| 312 | - 'name' => ! is_email( $payment_title ) ? $data['first_name'] . ' ' . $data['last_name'] : '', |
|
| 312 | + 'name' => ! is_email($payment_title) ? $data['first_name'].' '.$data['last_name'] : '', |
|
| 313 | 313 | 'email' => $data['email'], |
| 314 | 314 | ); |
| 315 | 315 | |
| 316 | - if ( ! empty( $donor_id ) ) { |
|
| 316 | + if ( ! empty($donor_id)) { |
|
| 317 | 317 | $donor_args['user_id'] = $donor_id; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - $donor_data->create( $donor_args ); |
|
| 320 | + $donor_data->create($donor_args); |
|
| 321 | 321 | |
| 322 | 322 | // Adding notes that donor is being imported from CSV. |
| 323 | 323 | $current_user = wp_get_current_user(); |
| 324 | - $donor_data->add_note( esc_html( wp_sprintf( __( 'This donor was imported by %s', 'give' ), $current_user->user_email ) ) ); |
|
| 324 | + $donor_data->add_note(esc_html(wp_sprintf(__('This donor was imported by %s', 'give'), $current_user->user_email))); |
|
| 325 | 325 | |
| 326 | - $report['create_donor'] = ( ! empty( $report['create_donor'] ) ? ( absint( $report['create_donor'] ) + 1 ) : 1 ); |
|
| 326 | + $report['create_donor'] = ( ! empty($report['create_donor']) ? (absint($report['create_donor']) + 1) : 1); |
|
| 327 | 327 | } else { |
| 328 | - $report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 ); |
|
| 328 | + $report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1); |
|
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | 331 | } else { |
| 332 | - $report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 ); |
|
| 332 | + $report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1); |
|
| 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,62 +369,62 @@ 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' ), |
|
| 372 | + return (array) apply_filters('give_import_donations_options', array( |
|
| 373 | + 'id' => __('Donation ID', 'give'), |
|
| 374 | 374 | 'amount' => array( |
| 375 | - __( 'Donation Amount', 'give' ), |
|
| 376 | - __( 'Amount', 'give' ) |
|
| 375 | + __('Donation Amount', 'give'), |
|
| 376 | + __('Amount', 'give') |
|
| 377 | 377 | ), |
| 378 | 378 | 'post_date' => array( |
| 379 | - __( 'Donation Date', 'give' ), |
|
| 380 | - __( 'Date', 'give' ), |
|
| 379 | + __('Donation Date', 'give'), |
|
| 380 | + __('Date', 'give'), |
|
| 381 | 381 | ), |
| 382 | 382 | 'first_name' => array( |
| 383 | - __( 'Donor First Name', 'give' ), |
|
| 384 | - __( 'First Name', 'give' ), |
|
| 385 | - __( 'Name', 'give' ), |
|
| 383 | + __('Donor First Name', 'give'), |
|
| 384 | + __('First Name', 'give'), |
|
| 385 | + __('Name', 'give'), |
|
| 386 | 386 | ), |
| 387 | 387 | 'last_name' => array( |
| 388 | - __( 'Donor Last Name', 'give' ), |
|
| 389 | - __( 'Last Name', 'give' ), |
|
| 388 | + __('Donor Last Name', 'give'), |
|
| 389 | + __('Last Name', 'give'), |
|
| 390 | 390 | ), |
| 391 | 391 | 'line1' => array( |
| 392 | - __( 'Address 1', 'give' ), |
|
| 393 | - __( 'Address', 'give' ), |
|
| 392 | + __('Address 1', 'give'), |
|
| 393 | + __('Address', 'give'), |
|
| 394 | 394 | ), |
| 395 | - 'line2' => __( 'Address 2', 'give' ), |
|
| 396 | - 'city' => __( 'City', 'give' ), |
|
| 395 | + 'line2' => __('Address 2', 'give'), |
|
| 396 | + 'city' => __('City', 'give'), |
|
| 397 | 397 | 'state' => array( |
| 398 | - __( 'State', 'give' ), |
|
| 399 | - __( 'Province', 'give' ), |
|
| 400 | - __( 'County', 'give' ), |
|
| 401 | - __( 'Region', 'give' ), |
|
| 398 | + __('State', 'give'), |
|
| 399 | + __('Province', 'give'), |
|
| 400 | + __('County', 'give'), |
|
| 401 | + __('Region', 'give'), |
|
| 402 | 402 | ), |
| 403 | - 'country' => __( 'Country', 'give' ), |
|
| 403 | + 'country' => __('Country', 'give'), |
|
| 404 | 404 | 'zip' => array( |
| 405 | - __( 'Zip', 'give' ), |
|
| 406 | - __( 'Zip Code', 'give' ), |
|
| 407 | - __( 'Postal Code', 'give' ), |
|
| 405 | + __('Zip', 'give'), |
|
| 406 | + __('Zip Code', 'give'), |
|
| 407 | + __('Postal Code', 'give'), |
|
| 408 | 408 | ), |
| 409 | 409 | 'email' => array( |
| 410 | - __( 'Donor Email', 'give' ), |
|
| 411 | - __( 'Email', 'give' ) |
|
| 410 | + __('Donor Email', 'give'), |
|
| 411 | + __('Email', 'give') |
|
| 412 | 412 | ), |
| 413 | 413 | 'post_status' => array( |
| 414 | - __( 'Donation Status', 'give' ), |
|
| 415 | - __( 'Status', 'give' ), |
|
| 414 | + __('Donation Status', 'give'), |
|
| 415 | + __('Status', 'give'), |
|
| 416 | 416 | ), |
| 417 | 417 | 'gateway' => array( |
| 418 | - __( 'Payment Method', 'give' ), |
|
| 419 | - __( 'Method', 'give' ), |
|
| 418 | + __('Payment Method', 'give'), |
|
| 419 | + __('Method', 'give'), |
|
| 420 | 420 | ), |
| 421 | - 'notes' => __( 'Notes', 'give' ), |
|
| 421 | + 'notes' => __('Notes', 'give'), |
|
| 422 | 422 | 'mode' => array( |
| 423 | - __( 'Test Mode', 'give' ), |
|
| 424 | - __( 'Mode', 'give' ), |
|
| 423 | + __('Test Mode', 'give'), |
|
| 424 | + __('Mode', 'give'), |
|
| 425 | 425 | ), |
| 426 | - 'post_meta' => __( 'Import as Meta', 'give' ), |
|
| 427 | - ) ); |
|
| 426 | + 'post_meta' => __('Import as Meta', 'give'), |
|
| 427 | + )); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | /** |
@@ -440,10 +440,10 @@ discard block |
||
| 440 | 440 | * |
| 441 | 441 | * @return array |
| 442 | 442 | */ |
| 443 | - return (array) apply_filters( 'give_import_donor_options', array( |
|
| 444 | - 'donor_id' => __( 'Donor ID', 'give' ), |
|
| 445 | - 'user_id' => __( 'User ID', 'give' ), |
|
| 446 | - ) ); |
|
| 443 | + return (array) apply_filters('give_import_donor_options', array( |
|
| 444 | + 'donor_id' => __('Donor ID', 'give'), |
|
| 445 | + 'user_id' => __('User ID', 'give'), |
|
| 446 | + )); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
@@ -459,23 +459,23 @@ discard block |
||
| 459 | 459 | * |
| 460 | 460 | * @return array |
| 461 | 461 | */ |
| 462 | - return (array) apply_filters( 'give_import_donation_form_options', array( |
|
| 462 | + return (array) apply_filters('give_import_donation_form_options', array( |
|
| 463 | 463 | 'form_title' => array( |
| 464 | - __( 'Donation Form Title', 'give' ), |
|
| 465 | - __( 'Donation Form', 'give' ), |
|
| 466 | - __( 'Form Name', 'give' ), |
|
| 467 | - __( 'Title', 'give' ), |
|
| 464 | + __('Donation Form Title', 'give'), |
|
| 465 | + __('Donation Form', 'give'), |
|
| 466 | + __('Form Name', 'give'), |
|
| 467 | + __('Title', 'give'), |
|
| 468 | 468 | ), |
| 469 | 469 | 'form_id' => array( |
| 470 | - __( 'Donation Form ID', 'give' ), |
|
| 471 | - __( 'Form ID', 'give' ) |
|
| 470 | + __('Donation Form ID', 'give'), |
|
| 471 | + __('Form ID', 'give') |
|
| 472 | 472 | ), |
| 473 | 473 | 'form_level' => array( |
| 474 | - __( 'Donation Level', 'give' ), |
|
| 475 | - __( 'Level', 'give' ), |
|
| 474 | + __('Donation Level', 'give'), |
|
| 475 | + __('Level', 'give'), |
|
| 476 | 476 | ), |
| 477 | - 'form_custom_amount_text' => __( 'Custom Amount Text', 'give' ), |
|
| 478 | - ) ); |
|
| 477 | + 'form_custom_amount_text' => __('Custom Amount Text', 'give'), |
|
| 478 | + )); |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | /** |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | * |
| 489 | 489 | * @return array |
| 490 | 490 | */ |
| 491 | -function give_get_donation_data_from_csv( $file_id, $start, $end, $delimiter = 'csv' ) { |
|
| 491 | +function give_get_donation_data_from_csv($file_id, $start, $end, $delimiter = 'csv') { |
|
| 492 | 492 | /** |
| 493 | 493 | * Filter to modify delimiter of Import. |
| 494 | 494 | * |
@@ -497,19 +497,19 @@ discard block |
||
| 497 | 497 | * |
| 498 | 498 | * Return string $delimiter. |
| 499 | 499 | */ |
| 500 | - $delimiter = (string) apply_filters( 'give_import_delimiter_set', $delimiter ); |
|
| 500 | + $delimiter = (string) apply_filters('give_import_delimiter_set', $delimiter); |
|
| 501 | 501 | |
| 502 | 502 | $raw_data = array(); |
| 503 | - $file_dir = get_attached_file( $file_id ); |
|
| 503 | + $file_dir = get_attached_file($file_id); |
|
| 504 | 504 | $count = 0; |
| 505 | - if ( false !== ( $handle = fopen( $file_dir, 'r' ) ) ) { |
|
| 506 | - while ( false !== ( $row = fgetcsv( $handle, 0, $delimiter ) ) ) { |
|
| 507 | - if ( $count >= $start && $count <= $end ) { |
|
| 505 | + if (false !== ($handle = fopen($file_dir, 'r'))) { |
|
| 506 | + while (false !== ($row = fgetcsv($handle, 0, $delimiter))) { |
|
| 507 | + if ($count >= $start && $count <= $end) { |
|
| 508 | 508 | $raw_data[] = $row; |
| 509 | 509 | } |
| 510 | - $count ++; |
|
| 510 | + $count++; |
|
| 511 | 511 | } |
| 512 | - fclose( $handle ); |
|
| 512 | + fclose($handle); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | return $raw_data; |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | * |
| 526 | 526 | * @return bool |
| 527 | 527 | */ |
| 528 | -function give_log_user_in_on_register_callback( $value ) { |
|
| 528 | +function give_log_user_in_on_register_callback($value) { |
|
| 529 | 529 | return false; |
| 530 | 530 | } |
| 531 | 531 | |
@@ -541,22 +541,22 @@ discard block |
||
| 541 | 541 | * |
| 542 | 542 | * @return bool |
| 543 | 543 | */ |
| 544 | -function give_save_import_donation_to_db( $raw_key, $row_data, $main_key = array(), $import_setting = array() ) { |
|
| 545 | - $data = array_combine( $raw_key, $row_data ); |
|
| 544 | +function give_save_import_donation_to_db($raw_key, $row_data, $main_key = array(), $import_setting = array()) { |
|
| 545 | + $data = array_combine($raw_key, $row_data); |
|
| 546 | 546 | $price_id = false; |
| 547 | 547 | $donor_id = 0; |
| 548 | - $import_setting['create_user'] = ( isset( $import_setting['create_user'] ) ? $import_setting['create_user'] : 1 ); |
|
| 548 | + $import_setting['create_user'] = (isset($import_setting['create_user']) ? $import_setting['create_user'] : 1); |
|
| 549 | 549 | |
| 550 | - $data = (array) apply_filters( 'give_save_import_donation_to_db', $data ); |
|
| 550 | + $data = (array) apply_filters('give_save_import_donation_to_db', $data); |
|
| 551 | 551 | |
| 552 | - $data['amount'] = give_maybe_sanitize_amount( $data['amount'] ); |
|
| 552 | + $data['amount'] = give_maybe_sanitize_amount($data['amount']); |
|
| 553 | 553 | |
| 554 | 554 | // Here come the login function. |
| 555 | - $donor_data = give_import_get_user_from_csv( $data, $import_setting ); |
|
| 556 | - if ( ! empty( $donor_data->id ) ) { |
|
| 557 | - if ( ! empty( $donor_data->user_id ) ) { |
|
| 555 | + $donor_data = give_import_get_user_from_csv($data, $import_setting); |
|
| 556 | + if ( ! empty($donor_data->id)) { |
|
| 557 | + if ( ! empty($donor_data->user_id)) { |
|
| 558 | 558 | $donor_id = $donor_data->user_id; |
| 559 | - } elseif ( ! empty( $data['user_id'] ) ) { |
|
| 559 | + } elseif ( ! empty($data['user_id'])) { |
|
| 560 | 560 | $donor_id = $data['user_id']; |
| 561 | 561 | } |
| 562 | 562 | } else { |
@@ -564,97 +564,97 @@ discard block |
||
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | // get form data or register a form data. |
| 567 | - $form = give_import_get_form_data_from_csv( $data, $import_setting ); |
|
| 568 | - if ( false == $form ) { |
|
| 567 | + $form = give_import_get_form_data_from_csv($data, $import_setting); |
|
| 568 | + if (false == $form) { |
|
| 569 | 569 | return false; |
| 570 | 570 | } else { |
| 571 | - $price_id = ( ! empty( $form->price_id ) ) ? $form->price_id : false; |
|
| 571 | + $price_id = ( ! empty($form->price_id)) ? $form->price_id : false; |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | |
| 575 | 575 | $address = array( |
| 576 | - 'line1' => ( ! empty( $data['line1'] ) ? give_clean( $data['line1'] ) : '' ), |
|
| 577 | - 'line2' => ( ! empty( $data['line1'] ) ? give_clean( $data['line2'] ) : '' ), |
|
| 578 | - 'city' => ( ! empty( $data['line1'] ) ? give_clean( $data['city'] ) : '' ), |
|
| 579 | - 'zip' => ( ! empty( $data['zip'] ) ? give_clean( $data['zip'] ) : '' ), |
|
| 580 | - 'state' => ( ! empty( $data['state'] ) ? give_clean( $data['state'] ) : '' ), |
|
| 581 | - 'country' => ( ! empty( $data['country'] ) ? ( ( $country_code = array_search( $data['country'], give_get_country_list() ) ) ? $country_code : $data['country'] ) : '' ), |
|
| 576 | + 'line1' => ( ! empty($data['line1']) ? give_clean($data['line1']) : ''), |
|
| 577 | + 'line2' => ( ! empty($data['line1']) ? give_clean($data['line2']) : ''), |
|
| 578 | + 'city' => ( ! empty($data['line1']) ? give_clean($data['city']) : ''), |
|
| 579 | + 'zip' => ( ! empty($data['zip']) ? give_clean($data['zip']) : ''), |
|
| 580 | + 'state' => ( ! empty($data['state']) ? give_clean($data['state']) : ''), |
|
| 581 | + 'country' => ( ! empty($data['country']) ? (($country_code = array_search($data['country'], give_get_country_list())) ? $country_code : $data['country']) : ''), |
|
| 582 | 582 | ); |
| 583 | 583 | |
| 584 | 584 | //Create payment_data array |
| 585 | 585 | $payment_data = array( |
| 586 | 586 | 'donor_id' => $donor_data->id, |
| 587 | 587 | 'price' => $data['amount'], |
| 588 | - 'status' => ( ! empty( $data['post_status'] ) ? $data['post_status'] : 'publish' ), |
|
| 588 | + 'status' => ( ! empty($data['post_status']) ? $data['post_status'] : 'publish'), |
|
| 589 | 589 | 'currency' => give_get_currency(), |
| 590 | 590 | 'user_info' => array( |
| 591 | 591 | 'id' => $donor_id, |
| 592 | - 'email' => ( ! empty( $data['email'] ) ? $data['email'] : ( isset( $donor_data->email ) ? $donor_data->email : false ) ), |
|
| 593 | - 'first_name' => ( ! empty( $data['first_name'] ) ? $data['first_name'] : ( ! empty( $donor_id ) && ( $first_name = get_user_meta( $donor_id, 'first_name', true ) ) ? $first_name : $donor_data->name ) ), |
|
| 594 | - 'last_name' => ( ! empty( $data['last_name'] ) ? $data['last_name'] : ( ! empty( $donor_id ) && ( $last_name = get_user_meta( $donor_id, 'last_name', true ) ) ? $last_name : $donor_data->name ) ), |
|
| 592 | + 'email' => ( ! empty($data['email']) ? $data['email'] : (isset($donor_data->email) ? $donor_data->email : false)), |
|
| 593 | + 'first_name' => ( ! empty($data['first_name']) ? $data['first_name'] : ( ! empty($donor_id) && ($first_name = get_user_meta($donor_id, 'first_name', true)) ? $first_name : $donor_data->name)), |
|
| 594 | + 'last_name' => ( ! empty($data['last_name']) ? $data['last_name'] : ( ! empty($donor_id) && ($last_name = get_user_meta($donor_id, 'last_name', true)) ? $last_name : $donor_data->name)), |
|
| 595 | 595 | 'address' => $address, |
| 596 | 596 | ), |
| 597 | - 'gateway' => ( ! empty( $data['gateway'] ) && 'offline' != strtolower( $data['gateway'] ) ? strtolower( $data['gateway'] ) : 'manual' ), |
|
| 598 | - 'give_form_title' => ( ! empty( $data['form_title'] ) ? $data['form_title'] : $form->get_name() ), |
|
| 597 | + 'gateway' => ( ! empty($data['gateway']) && 'offline' != strtolower($data['gateway']) ? strtolower($data['gateway']) : 'manual'), |
|
| 598 | + 'give_form_title' => ( ! empty($data['form_title']) ? $data['form_title'] : $form->get_name()), |
|
| 599 | 599 | 'give_form_id' => (string) $form->get_ID(), |
| 600 | 600 | 'give_price_id' => $price_id, |
| 601 | - 'purchase_key' => strtolower( md5( uniqid() ) ), |
|
| 601 | + 'purchase_key' => strtolower(md5(uniqid())), |
|
| 602 | 602 | 'user_email' => $data['email'], |
| 603 | - 'post_date' => ( ! empty( $data['post_date'] ) ? mysql2date( 'Y-m-d H:i:s', $data['post_date'] ) : current_time( 'mysql' ) ), |
|
| 604 | - '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' ) ) ), |
|
| 603 | + 'post_date' => ( ! empty($data['post_date']) ? mysql2date('Y-m-d H:i:s', $data['post_date']) : current_time('mysql')), |
|
| 604 | + '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'))), |
|
| 605 | 605 | ); |
| 606 | 606 | |
| 607 | - $payment_data = apply_filters( 'give_import_before_import_payment', $payment_data, $data, $donor_data, $form ); |
|
| 607 | + $payment_data = apply_filters('give_import_before_import_payment', $payment_data, $data, $donor_data, $form); |
|
| 608 | 608 | |
| 609 | 609 | // Get the report |
| 610 | 610 | $report = give_import_donation_report(); |
| 611 | 611 | |
| 612 | 612 | // Check for duplicate code. |
| 613 | - $donation_duplicate = give_check_import_donation_duplicate( $payment_data, $data, $form, $donor_data ); |
|
| 614 | - if ( false !== $donation_duplicate ) { |
|
| 615 | - $report['donation_details'][ $import_setting['donation_key'] ]['duplicate'] = $donation_duplicate; |
|
| 616 | - $report['duplicate_donation'] = ( ! empty( $report['duplicate_donation'] ) ? ( absint( $report['duplicate_donation'] ) + 1 ) : 1 ); |
|
| 613 | + $donation_duplicate = give_check_import_donation_duplicate($payment_data, $data, $form, $donor_data); |
|
| 614 | + if (false !== $donation_duplicate) { |
|
| 615 | + $report['donation_details'][$import_setting['donation_key']]['duplicate'] = $donation_duplicate; |
|
| 616 | + $report['duplicate_donation'] = ( ! empty($report['duplicate_donation']) ? (absint($report['duplicate_donation']) + 1) : 1); |
|
| 617 | 617 | } else { |
| 618 | - add_action( 'give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1, 1 ); |
|
| 619 | - add_filter( 'give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11, 2 ); |
|
| 620 | - add_filter( 'give_update_donor_information', 'give_donation_import_update_donor_information', 11, 3 ); |
|
| 621 | - add_action( 'give_insert_payment', 'give_import_donation_insert_payment', 11, 2 ); |
|
| 622 | - $payment = give_insert_payment( $payment_data ); |
|
| 623 | - remove_action( 'give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1 ); |
|
| 624 | - remove_filter( 'give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11 ); |
|
| 625 | - remove_filter( 'give_update_donor_information', 'give_donation_import_update_donor_information', 11 ); |
|
| 626 | - remove_action( 'give_insert_payment', 'give_import_donation_insert_payment', 11 ); |
|
| 618 | + add_action('give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1, 1); |
|
| 619 | + add_filter('give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11, 2); |
|
| 620 | + add_filter('give_update_donor_information', 'give_donation_import_update_donor_information', 11, 3); |
|
| 621 | + add_action('give_insert_payment', 'give_import_donation_insert_payment', 11, 2); |
|
| 622 | + $payment = give_insert_payment($payment_data); |
|
| 623 | + remove_action('give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1); |
|
| 624 | + remove_filter('give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11); |
|
| 625 | + remove_filter('give_update_donor_information', 'give_donation_import_update_donor_information', 11); |
|
| 626 | + remove_action('give_insert_payment', 'give_import_donation_insert_payment', 11); |
|
| 627 | 627 | |
| 628 | - if ( $payment ) { |
|
| 628 | + if ($payment) { |
|
| 629 | 629 | |
| 630 | - $report['create_donation'] = ( ! empty( $report['create_donation'] ) ? ( absint( $report['create_donation'] ) + 1 ) : 1 ); |
|
| 630 | + $report['create_donation'] = ( ! empty($report['create_donation']) ? (absint($report['create_donation']) + 1) : 1); |
|
| 631 | 631 | |
| 632 | - update_post_meta( $payment, '_give_payment_import', true ); |
|
| 632 | + update_post_meta($payment, '_give_payment_import', true); |
|
| 633 | 633 | |
| 634 | - if ( ! empty( $import_setting['csv'] ) ) { |
|
| 635 | - update_post_meta( $payment, '_give_payment_import_id', $import_setting['csv'] ); |
|
| 634 | + if ( ! empty($import_setting['csv'])) { |
|
| 635 | + update_post_meta($payment, '_give_payment_import_id', $import_setting['csv']); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | // Insert Notes. |
| 639 | - if ( ! empty( $data['notes'] ) ) { |
|
| 640 | - give_insert_payment_note( $payment, $data['notes'] ); |
|
| 639 | + if ( ! empty($data['notes'])) { |
|
| 640 | + give_insert_payment_note($payment, $data['notes']); |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | - $meta_exists = array_keys( $raw_key, 'post_meta' ); |
|
| 644 | - if ( ! empty( $main_key ) && ! empty( $meta_exists ) ) { |
|
| 645 | - foreach ( $meta_exists as $meta_exist ) { |
|
| 646 | - if ( ! empty( $main_key[ $meta_exist ] ) && ! empty( $row_data[ $meta_exist ] ) ) { |
|
| 647 | - update_post_meta( $payment, $main_key[ $meta_exist ], $row_data[ $meta_exist ] ); |
|
| 643 | + $meta_exists = array_keys($raw_key, 'post_meta'); |
|
| 644 | + if ( ! empty($main_key) && ! empty($meta_exists)) { |
|
| 645 | + foreach ($meta_exists as $meta_exist) { |
|
| 646 | + if ( ! empty($main_key[$meta_exist]) && ! empty($row_data[$meta_exist])) { |
|
| 647 | + update_post_meta($payment, $main_key[$meta_exist], $row_data[$meta_exist]); |
|
| 648 | 648 | } |
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | 651 | } else { |
| 652 | - $report['failed_donation'] = ( ! empty( $report['failed_donation'] ) ? ( absint( $report['failed_donation'] ) + 1 ) : 1 ); |
|
| 652 | + $report['failed_donation'] = ( ! empty($report['failed_donation']) ? (absint($report['failed_donation']) + 1) : 1); |
|
| 653 | 653 | } |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | // update the report |
| 657 | - give_import_donation_report_update( $report ); |
|
| 657 | + give_import_donation_report_update($report); |
|
| 658 | 658 | |
| 659 | 659 | return true; |
| 660 | 660 | } |
@@ -670,12 +670,12 @@ discard block |
||
| 670 | 670 | * |
| 671 | 671 | * @return Give_Donor |
| 672 | 672 | */ |
| 673 | -function give_donation_import_update_donor_information( $donor, $payment_id, $payment_data ) { |
|
| 673 | +function give_donation_import_update_donor_information($donor, $payment_id, $payment_data) { |
|
| 674 | 674 | $old_donor = $donor; |
| 675 | - if ( ! empty( $payment_data['donor_id'] ) ) { |
|
| 676 | - $donor_id = absint( $payment_data['donor_id'] ); |
|
| 677 | - $donor = new Give_Donor( $donor_id ); |
|
| 678 | - if ( ! empty( $donor->id ) ) { |
|
| 675 | + if ( ! empty($payment_data['donor_id'])) { |
|
| 676 | + $donor_id = absint($payment_data['donor_id']); |
|
| 677 | + $donor = new Give_Donor($donor_id); |
|
| 678 | + if ( ! empty($donor->id)) { |
|
| 679 | 679 | return $donor; |
| 680 | 680 | } |
| 681 | 681 | } |
@@ -688,12 +688,12 @@ discard block |
||
| 688 | 688 | * |
| 689 | 689 | * @since 1.8.13 |
| 690 | 690 | */ |
| 691 | -function give_import_donation_insert_payment( $payment_id, $payment_data ) { |
|
| 691 | +function give_import_donation_insert_payment($payment_id, $payment_data) { |
|
| 692 | 692 | // Update Give Customers purchase_count |
| 693 | - if ( ! empty( $payment_data['status'] ) && ( 'complete' === (string) $payment_data['status'] || 'publish' === (string) $payment_data['status'] ) ) { |
|
| 694 | - $donor_id = (int) get_post_meta( $payment_id, '_give_payment_customer_id', true ); |
|
| 695 | - if ( ! empty( $donor_id ) ) { |
|
| 696 | - $donor = new Give_Donor( $donor_id ); |
|
| 693 | + if ( ! empty($payment_data['status']) && ('complete' === (string) $payment_data['status'] || 'publish' === (string) $payment_data['status'])) { |
|
| 694 | + $donor_id = (int) get_post_meta($payment_id, '_give_payment_customer_id', true); |
|
| 695 | + if ( ! empty($donor_id)) { |
|
| 696 | + $donor = new Give_Donor($donor_id); |
|
| 697 | 697 | $donor->increase_purchase_count(); |
| 698 | 698 | } |
| 699 | 699 | } |
@@ -704,8 +704,8 @@ discard block |
||
| 704 | 704 | * |
| 705 | 705 | * @since 1.8.13 |
| 706 | 706 | */ |
| 707 | -function give_donation_import_give_insert_payment_args( $args, $payment_data ) { |
|
| 708 | - if ( ! empty( $payment_data['user_info']['id'] ) ) { |
|
| 707 | +function give_donation_import_give_insert_payment_args($args, $payment_data) { |
|
| 708 | + if ( ! empty($payment_data['user_info']['id'])) { |
|
| 709 | 709 | $args['post_author'] = (int) $payment_data['user_info']['id']; |
| 710 | 710 | } |
| 711 | 711 | |
@@ -717,11 +717,11 @@ discard block |
||
| 717 | 717 | * |
| 718 | 718 | * @since 1.8.13 |
| 719 | 719 | */ |
| 720 | -function give_check_import_donation_duplicate( $payment_data, $data, $form, $donor_data ) { |
|
| 720 | +function give_check_import_donation_duplicate($payment_data, $data, $form, $donor_data) { |
|
| 721 | 721 | $return = false; |
| 722 | - if ( ! empty( $data['post_date'] ) ) { |
|
| 723 | - $post_date = mysql2date( 'Y-m-d-H-i-s', $data['post_date'] ); |
|
| 724 | - $post_date = explode( '-', $post_date ); |
|
| 722 | + if ( ! empty($data['post_date'])) { |
|
| 723 | + $post_date = mysql2date('Y-m-d-H-i-s', $data['post_date']); |
|
| 724 | + $post_date = explode('-', $post_date); |
|
| 725 | 725 | $args = array( |
| 726 | 726 | 'output' => 'post', |
| 727 | 727 | 'cache_results' => false, |
@@ -742,7 +742,7 @@ discard block |
||
| 742 | 742 | 'meta_query' => array( |
| 743 | 743 | array( |
| 744 | 744 | 'key' => '_give_payment_total', |
| 745 | - 'value' => preg_replace( '/[\$,]/', '', $payment_data['price'] ), |
|
| 745 | + 'value' => preg_replace('/[\$,]/', '', $payment_data['price']), |
|
| 746 | 746 | 'compare' => 'LIKE', |
| 747 | 747 | ), |
| 748 | 748 | array( |
@@ -764,9 +764,9 @@ discard block |
||
| 764 | 764 | ), |
| 765 | 765 | ); |
| 766 | 766 | |
| 767 | - $payments = new Give_Payments_Query( $args ); |
|
| 767 | + $payments = new Give_Payments_Query($args); |
|
| 768 | 768 | $donations = $payments->get_payments(); |
| 769 | - if ( ! empty( $donations ) ) { |
|
| 769 | + if ( ! empty($donations)) { |
|
| 770 | 770 | $return = $donations; |
| 771 | 771 | } |
| 772 | 772 | } |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | * |
| 777 | 777 | * @since 1.8.18 |
| 778 | 778 | */ |
| 779 | - return apply_filters( 'give_check_import_donation_duplicate', $return, $payment_data, $data, $form, $donor_data ); |
|
| 779 | + return apply_filters('give_check_import_donation_duplicate', $return, $payment_data, $data, $form, $donor_data); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
@@ -788,9 +788,9 @@ discard block |
||
| 788 | 788 | * |
| 789 | 789 | * @return void |
| 790 | 790 | */ |
| 791 | -function give_donation_import_insert_default_payment_note( $payment_id ) { |
|
| 791 | +function give_donation_import_insert_default_payment_note($payment_id) { |
|
| 792 | 792 | $current_user = wp_get_current_user(); |
| 793 | - give_insert_payment_note( $payment_id, esc_html( wp_sprintf( __( 'This donation was imported by %s', 'give' ), $current_user->user_email ) ) ); |
|
| 793 | + give_insert_payment_note($payment_id, esc_html(wp_sprintf(__('This donation was imported by %s', 'give'), $current_user->user_email))); |
|
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | /** |
@@ -802,14 +802,14 @@ discard block |
||
| 802 | 802 | * |
| 803 | 803 | * @return string URL |
| 804 | 804 | */ |
| 805 | -function give_import_page_url( $parameter = array() ) { |
|
| 805 | +function give_import_page_url($parameter = array()) { |
|
| 806 | 806 | $defalut_query_arg = array( |
| 807 | 807 | 'post_type' => 'give_forms', |
| 808 | 808 | 'page' => 'give-tools', |
| 809 | 809 | 'tab' => 'import', |
| 810 | 810 | 'importer-type' => 'import_donations', |
| 811 | 811 | ); |
| 812 | - $import_query_arg = wp_parse_args( $parameter, $defalut_query_arg ); |
|
| 812 | + $import_query_arg = wp_parse_args($parameter, $defalut_query_arg); |
|
| 813 | 813 | |
| 814 | - return add_query_arg( $import_query_arg, admin_url( 'edit.php' ) ); |
|
| 814 | + return add_query_arg($import_query_arg, admin_url('edit.php')); |
|
| 815 | 815 | } |
| 816 | 816 | \ No newline at end of file |