| @@ 888-897 (lines=10) @@ | ||
| 885 | ); |
|
| 886 | ||
| 887 | // Security check. |
|
| 888 | if ( ! wp_verify_nonce( $form_data['_wpnonce'], 'give-manage-donor-addresses' ) ) { |
|
| 889 | wp_send_json_error( array( |
|
| 890 | 'error' => 1, |
|
| 891 | 'error_msg' => wp_sprintf( |
|
| 892 | '<div class="notice notice-error"><p>%s</p></div>', |
|
| 893 | __( 'Error: Security issue.', 'give' ) |
|
| 894 | ), |
|
| 895 | ) |
|
| 896 | ); |
|
| 897 | } |
|
| 898 | ||
| 899 | $donor = new Give_Donor( $donorID ); |
|
| 900 | ||
| @@ 919-928 (lines=10) @@ | ||
| 916 | switch ( $response_data['action'] ) { |
|
| 917 | ||
| 918 | case 'add': |
|
| 919 | if ( ! $donor->add_address( "{$address_type}[]", $form_data ) ) { |
|
| 920 | wp_send_json_error( array( |
|
| 921 | 'error' => 1, |
|
| 922 | 'error_msg' => wp_sprintf( |
|
| 923 | '<div class="notice notice-error"><p>%s</p></div>', |
|
| 924 | __( 'Error: Unable to save the address. Please check if address already exist.', 'give' ) |
|
| 925 | ), |
|
| 926 | ) |
|
| 927 | ); |
|
| 928 | } |
|
| 929 | ||
| 930 | $total_addresses = count( $donor->address[ $address_type ] ); |
|
| 931 | ||
| @@ 963-972 (lines=10) @@ | ||
| 960 | break; |
|
| 961 | ||
| 962 | case 'remove': |
|
| 963 | if ( ! $donor->remove_address( $response_data['id'] ) ) { |
|
| 964 | wp_send_json_error( array( |
|
| 965 | 'error' => 2, |
|
| 966 | 'error_msg' => wp_sprintf( |
|
| 967 | '<div class="notice notice-error"><p>%s</p></div>', |
|
| 968 | __( 'Error: Unable to delete address.', 'give' ) |
|
| 969 | ), |
|
| 970 | ) |
|
| 971 | ); |
|
| 972 | } |
|
| 973 | ||
| 974 | $response_data['success_msg'] = wp_sprintf( |
|
| 975 | '<div class="notice updated"><p>%s</p></div>', |
|
| @@ 982-991 (lines=10) @@ | ||
| 979 | break; |
|
| 980 | ||
| 981 | case 'update': |
|
| 982 | if ( ! $donor->update_address( $response_data['id'], $form_data ) ) { |
|
| 983 | wp_send_json_error( array( |
|
| 984 | 'error' => 3, |
|
| 985 | 'error_msg' => wp_sprintf( |
|
| 986 | '<div class="notice notice-error"><p>%s</p></div>', |
|
| 987 | __( 'Error: Unable to update address. Please check if address already exist.', 'give' ) |
|
| 988 | ), |
|
| 989 | ) |
|
| 990 | ); |
|
| 991 | } |
|
| 992 | ||
| 993 | $response_data['address_html'] = __give_get_format_address( |
|
| 994 | $is_multi_address_type ? |
|