| @@ 968-977 (lines=10) @@ | ||
| 965 | ); |
|
| 966 | ||
| 967 | // Security check. |
|
| 968 | if ( ! wp_verify_nonce( $form_data['_wpnonce'], 'give-manage-donor-addresses' ) ) { |
|
| 969 | wp_send_json_error( |
|
| 970 | array( |
|
| 971 | 'error' => 1, |
|
| 972 | 'error_msg' => wp_sprintf( |
|
| 973 | '<div class="notice notice-error"><p>%s</p></div>', |
|
| 974 | __( 'Error: Security issue.', 'give' ) |
|
| 975 | ), |
|
| 976 | ) |
|
| 977 | ); |
|
| 978 | } |
|
| 979 | ||
| 980 | $donor = new Give_Donor( $donorID ); |
|
| @@ 1002-1011 (lines=10) @@ | ||
| 999 | switch ( $response_data['action'] ) { |
|
| 1000 | ||
| 1001 | case 'add': |
|
| 1002 | if ( ! $donor->add_address( "{$address_type}[]", $form_data ) ) { |
|
| 1003 | wp_send_json_error( |
|
| 1004 | array( |
|
| 1005 | 'error' => 1, |
|
| 1006 | 'error_msg' => wp_sprintf( |
|
| 1007 | '<div class="notice notice-error"><p>%s</p></div>', |
|
| 1008 | __( 'Error: Unable to save the address. Please check if address already exist.', 'give' ) |
|
| 1009 | ), |
|
| 1010 | ) |
|
| 1011 | ); |
|
| 1012 | } |
|
| 1013 | ||
| 1014 | $total_addresses = count( $donor->address[ $address_type ] ); |
|
| @@ 1047-1056 (lines=10) @@ | ||
| 1044 | break; |
|
| 1045 | ||
| 1046 | case 'remove': |
|
| 1047 | if ( ! $donor->remove_address( $response_data['id'] ) ) { |
|
| 1048 | wp_send_json_error( |
|
| 1049 | array( |
|
| 1050 | 'error' => 2, |
|
| 1051 | 'error_msg' => wp_sprintf( |
|
| 1052 | '<div class="notice notice-error"><p>%s</p></div>', |
|
| 1053 | __( 'Error: Unable to delete address.', 'give' ) |
|
| 1054 | ), |
|
| 1055 | ) |
|
| 1056 | ); |
|
| 1057 | } |
|
| 1058 | ||
| 1059 | $response_data['success_msg'] = wp_sprintf( |
|
| @@ 1067-1076 (lines=10) @@ | ||
| 1064 | break; |
|
| 1065 | ||
| 1066 | case 'update': |
|
| 1067 | if ( ! $donor->update_address( $response_data['id'], $form_data ) ) { |
|
| 1068 | wp_send_json_error( |
|
| 1069 | array( |
|
| 1070 | 'error' => 3, |
|
| 1071 | 'error_msg' => wp_sprintf( |
|
| 1072 | '<div class="notice notice-error"><p>%s</p></div>', |
|
| 1073 | __( 'Error: Unable to update address. Please check if address already exist.', 'give' ) |
|
| 1074 | ), |
|
| 1075 | ) |
|
| 1076 | ); |
|
| 1077 | } |
|
| 1078 | ||
| 1079 | $response_data['address_html'] = __give_get_format_address( |
|