| Conditions | 32 |
| Paths | > 20000 |
| Total Lines | 126 |
| Code Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 271 | function __give_get_payment_meta( $check, $object_id, $meta_key, $meta_value ) { |
||
| 272 | // Bailout. |
||
| 273 | if ( |
||
| 274 | 'give_payment' !== get_post_type( $object_id ) || |
||
| 275 | '_give_payment_meta' !== $meta_key || |
||
| 276 | ! give_has_upgrade_completed( 'v20_upgrades_payment_metadata' ) |
||
| 277 | ) { |
||
| 278 | return $check; |
||
| 279 | } |
||
| 280 | |||
| 281 | // Remove filter. |
||
| 282 | remove_filter( 'get_post_metadata', '__give_get_payment_meta', 0 ); |
||
| 283 | |||
| 284 | // Get all payment meta. |
||
| 285 | $payment_meta = give_get_meta( $object_id ); |
||
| 286 | |||
| 287 | |||
| 288 | // Set default value to array. |
||
| 289 | if ( empty( $payment_meta ) ) { |
||
| 290 | return $meta_value; |
||
| 291 | } |
||
| 292 | |||
| 293 | // Donation key. |
||
| 294 | $payment_meta['key'] = ! empty( $payment_meta['_give_payment_purchase_key'] ) ? current( $payment_meta['_give_payment_purchase_key'] ) : ''; |
||
| 295 | |||
| 296 | // Donation form. |
||
| 297 | $payment_meta['form_title'] = ! empty( $payment_meta['_give_payment_form_title'] ) ? current( $payment_meta['_give_payment_form_title'] ) : ''; |
||
| 298 | |||
| 299 | // Donor email. |
||
| 300 | $payment_meta['email'] = ! empty( $payment_meta['_give_payment_donor_email'] ) ? current( $payment_meta['_give_payment_donor_email'] ) : ''; |
||
| 301 | $payment_meta['email'] = ! empty( $payment_meta['email'] ) ? |
||
| 302 | $payment_meta['email'] : |
||
| 303 | Give()->donors->get_column( 'email', give_get_payment_donor_id( $object_id ) ); |
||
| 304 | |||
| 305 | // Form id. |
||
| 306 | $payment_meta['form_id'] = ! empty( $payment_meta['_give_payment_form_id'] ) ? current( $payment_meta['_give_payment_form_id'] ) : ''; |
||
| 307 | |||
| 308 | // Price id. |
||
| 309 | $payment_meta['price_id'] = ! empty( $payment_meta['_give_payment_price_id'] ) ? current( $payment_meta['_give_payment_price_id'] ) : ''; |
||
| 310 | |||
| 311 | // Date. |
||
| 312 | $payment_meta['date'] = ! empty( $payment_meta['_give_payment_date'] ) ? current( $payment_meta['_give_payment_date'] ) : ''; |
||
| 313 | $payment_meta['date'] = ! empty( $payment_meta['date'] ) ? |
||
| 314 | $payment_meta['date'] : |
||
| 315 | get_post_field( 'post_date', $object_id ); |
||
| 316 | |||
| 317 | |||
| 318 | // Currency. |
||
| 319 | $payment_meta['currency'] = ! empty( $payment_meta['_give_payment_currency'] ) ? current( $payment_meta['_give_payment_currency'] ) : ''; |
||
| 320 | |||
| 321 | // Decode donor data. |
||
| 322 | $donor_names = give_get_donor_name_by( ( ! empty( $payment_meta['_give_payment_donor_id'] ) ? current( $payment_meta['_give_payment_donor_id'] ) : 0 ), 'donor' ); |
||
| 323 | $donor_names = explode( ' ', $donor_names, 2 ); |
||
| 324 | |||
| 325 | |||
| 326 | // Donor first name. |
||
| 327 | $donor_data['first_name'] = ! empty( $payment_meta['_give_payment_billing_first_name'] ) ? current( $payment_meta['_give_payment_billing_first_name'] ) : ''; |
||
| 328 | $donor_data['first_name'] = ! empty( $donor_data['first_name'] ) ? |
||
| 329 | $donor_data['first_name'] : |
||
| 330 | $donor_names[0]; |
||
| 331 | |||
| 332 | // Donor last name. |
||
| 333 | $donor_data['last_name'] = ! empty( $payment_meta['_give_payment_billing_last_name'] ) ? current( $payment_meta['_give_payment_billing_last_name'] ) : ''; |
||
| 334 | $donor_data['last_name'] = ! empty( $donor_data['last_name'] ) ? |
||
| 335 | $donor_data['last_name'] : |
||
| 336 | ( isset( $donor_names[1] ) ? $donor_names[1] : '' ); |
||
| 337 | |||
| 338 | // Donor email. |
||
| 339 | $donor_data['email'] = $payment_meta['email']; |
||
| 340 | |||
| 341 | // User ID. |
||
| 342 | $donor_data['id'] = give_get_payment_user_id( $object_id ); |
||
| 343 | |||
| 344 | $donor_data['address'] = false; |
||
| 345 | |||
| 346 | // Address1. |
||
| 347 | $address1 = ! empty( $payment_meta['_give_payment_billing_address1'] ) ? $payment_meta['_give_payment_billing_address1'] : ''; |
||
| 348 | if ( $address1 ) { |
||
| 349 | $donor_data['address']['line1'] = $address1; |
||
| 350 | } |
||
| 351 | |||
| 352 | // Address2. |
||
| 353 | $address2 = ! empty( $payment_meta['_give_payment_billing_address2'] ) ? $payment_meta['_give_payment_billing_address2'] : ''; |
||
| 354 | if ( $address2 ) { |
||
| 355 | $donor_data['address']['line2'] = $address2; |
||
| 356 | } |
||
| 357 | |||
| 358 | // City. |
||
| 359 | $city = ! empty( $payment_meta['_give_payment_billing_city'] ) ? $payment_meta['_give_payment_billing_city'] : ''; |
||
| 360 | if ( $city ) { |
||
| 361 | $donor_data['address']['city'] = $city; |
||
| 362 | } |
||
| 363 | |||
| 364 | // Zip. |
||
| 365 | $zip = ! empty( $payment_meta['_give_payment_billing_zip'] ) ? $payment_meta['_give_payment_billing_zip'] : ''; |
||
| 366 | if ( $zip ) { |
||
| 367 | $donor_data['address']['zip'] = $zip; |
||
| 368 | } |
||
| 369 | |||
| 370 | // State. |
||
| 371 | $state = ! empty( $payment_meta['_give_payment_billing_state'] ) ? $payment_meta['_give_payment_billing_state'] : ''; |
||
| 372 | if ( $state ) { |
||
| 373 | $donor_data['address']['state'] = $state; |
||
| 374 | } |
||
| 375 | |||
| 376 | // Country. |
||
| 377 | $country = ! empty( $payment_meta['_give_payment_billing_country'] ) ? $payment_meta['_give_payment_billing_country'] : ''; |
||
| 378 | if ( $country ) { |
||
| 379 | $donor_data['address']['country'] = $country; |
||
| 380 | } |
||
| 381 | |||
| 382 | $payment_meta['user_info'] = $donor_data; |
||
| 383 | |||
| 384 | // Add filter |
||
| 385 | add_filter( 'get_post_metadata', '__give_get_payment_meta', 0, 4 ); |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Filter the payment meta |
||
| 389 | * Add custom meta key to payment meta |
||
| 390 | * |
||
| 391 | * @since 2.0 |
||
| 392 | */ |
||
| 393 | $payment_meta[0] = apply_filters( 'give_get_payment_meta', $payment_meta, $object_id, $meta_key ); |
||
| 394 | |||
| 395 | return $payment_meta; |
||
| 396 | } |
||
| 397 | |||
| 425 | add_action( 'give_insert_payment', 'give_payment_save_page_data' ); |