Passed
Pull Request — master (#126)
by Kiran
03:53
created
includes/admin/register-settings.php 1 patch
Indentation   +326 added lines, -326 removed lines patch added patch discarded remove patch
@@ -868,322 +868,322 @@  discard block
 block discarded – undo
868 868
 }
869 869
 
870 870
 function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
871
-	$pages_options = array();
871
+    $pages_options = array();
872 872
 
873
-	if( $default_label !== NULL && $default_label !== false ) {
874
-		$pages_options = array( '' => $default_label ); // Blank option
875
-	}
873
+    if( $default_label !== NULL && $default_label !== false ) {
874
+        $pages_options = array( '' => $default_label ); // Blank option
875
+    }
876 876
 
877
-	$pages = get_pages();
878
-	if ( $pages ) {
879
-		foreach ( $pages as $page ) {
880
-			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
877
+    $pages = get_pages();
878
+    if ( $pages ) {
879
+        foreach ( $pages as $page ) {
880
+            $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
881 881
             $pages_options[ $page->ID ] = $title;
882
-		}
883
-	}
882
+        }
883
+    }
884 884
 
885
-	return $pages_options;
885
+    return $pages_options;
886 886
 }
887 887
 
888 888
 function wpinv_header_callback( $args ) {
889
-	if ( !empty( $args['desc'] ) ) {
889
+    if ( !empty( $args['desc'] ) ) {
890 890
         echo $args['desc'];
891 891
     }
892 892
 }
893 893
 
894 894
 function wpinv_hidden_callback( $args ) {
895
-	global $wpinv_options;
896
-
897
-	if ( isset( $args['set_value'] ) ) {
898
-		$value = $args['set_value'];
899
-	} elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
900
-		$value = $wpinv_options[ $args['id'] ];
901
-	} else {
902
-		$value = isset( $args['std'] ) ? $args['std'] : '';
903
-	}
904
-
905
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
906
-		$args['readonly'] = true;
907
-		$value = isset( $args['std'] ) ? $args['std'] : '';
908
-		$name  = '';
909
-	} else {
910
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
911
-	}
912
-
913
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
895
+    global $wpinv_options;
896
+
897
+    if ( isset( $args['set_value'] ) ) {
898
+        $value = $args['set_value'];
899
+    } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
900
+        $value = $wpinv_options[ $args['id'] ];
901
+    } else {
902
+        $value = isset( $args['std'] ) ? $args['std'] : '';
903
+    }
904
+
905
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
906
+        $args['readonly'] = true;
907
+        $value = isset( $args['std'] ) ? $args['std'] : '';
908
+        $name  = '';
909
+    } else {
910
+        $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
911
+    }
912
+
913
+    $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
914 914
     
915
-	echo $html;
915
+    echo $html;
916 916
 }
917 917
 
918 918
 function wpinv_checkbox_callback( $args ) {
919
-	global $wpinv_options;
919
+    global $wpinv_options;
920 920
     
921 921
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
922 922
 
923
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
924
-		$name = '';
925
-	} else {
926
-		$name = 'name="wpinv_settings[' . $sanitize_id . ']"';
927
-	}
923
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
924
+        $name = '';
925
+    } else {
926
+        $name = 'name="wpinv_settings[' . $sanitize_id . ']"';
927
+    }
928 928
 
929
-	$checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : '';
930
-	$html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>';
931
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
929
+    $checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : '';
930
+    $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>';
931
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
932 932
 
933
-	echo $html;
933
+    echo $html;
934 934
 }
935 935
 
936 936
 function wpinv_multicheck_callback( $args ) {
937
-	global $wpinv_options;
937
+    global $wpinv_options;
938 938
 	
939
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
939
+    $sanitize_id = wpinv_sanitize_key( $args['id'] );
940 940
 	
941
-	if ( ! empty( $args['options'] ) ) {
942
-		foreach( $args['options'] as $key => $option ):
943
-			$sanitize_key = wpinv_sanitize_key( $key );
944
-			if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { 
945
-				$enabled = $sanitize_key;
946
-			} else { 
947
-				$enabled = NULL; 
948
-			}
949
-			echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
950
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label><br/>';
951
-		endforeach;
952
-		echo '<p class="description">' . $args['desc'] . '</p>';
953
-	}
941
+    if ( ! empty( $args['options'] ) ) {
942
+        foreach( $args['options'] as $key => $option ):
943
+            $sanitize_key = wpinv_sanitize_key( $key );
944
+            if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { 
945
+                $enabled = $sanitize_key;
946
+            } else { 
947
+                $enabled = NULL; 
948
+            }
949
+            echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
950
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label><br/>';
951
+        endforeach;
952
+        echo '<p class="description">' . $args['desc'] . '</p>';
953
+    }
954 954
 }
955 955
 
956 956
 function wpinv_payment_icons_callback( $args ) {
957
-	global $wpinv_options;
957
+    global $wpinv_options;
958 958
     
959 959
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
960 960
 
961
-	if ( ! empty( $args['options'] ) ) {
962
-		foreach( $args['options'] as $key => $option ) {
961
+    if ( ! empty( $args['options'] ) ) {
962
+        foreach( $args['options'] as $key => $option ) {
963 963
             $sanitize_key = wpinv_sanitize_key( $key );
964 964
             
965
-			if( isset( $wpinv_options[$args['id']][$key] ) ) {
966
-				$enabled = $option;
967
-			} else {
968
-				$enabled = NULL;
969
-			}
970
-
971
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
972
-
973
-				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
974
-
975
-				if ( wpinv_string_is_image_url( $key ) ) {
976
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
977
-				} else {
978
-					$card = strtolower( str_replace( ' ', '', $option ) );
979
-
980
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
981
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
982
-					} else {
983
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
984
-						$content_dir = WP_CONTENT_DIR;
985
-
986
-						if ( function_exists( 'wp_normalize_path' ) ) {
987
-							// Replaces backslashes with forward slashes for Windows systems
988
-							$image = wp_normalize_path( $image );
989
-							$content_dir = wp_normalize_path( $content_dir );
990
-						}
991
-
992
-						$image = str_replace( $content_dir, content_url(), $image );
993
-					}
994
-
995
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
996
-				}
997
-			echo $option . '</label>';
998
-		}
999
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
1000
-	}
965
+            if( isset( $wpinv_options[$args['id']][$key] ) ) {
966
+                $enabled = $option;
967
+            } else {
968
+                $enabled = NULL;
969
+            }
970
+
971
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
972
+
973
+                echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
974
+
975
+                if ( wpinv_string_is_image_url( $key ) ) {
976
+                    echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
977
+                } else {
978
+                    $card = strtolower( str_replace( ' ', '', $option ) );
979
+
980
+                    if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
981
+                        $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
982
+                    } else {
983
+                        $image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
984
+                        $content_dir = WP_CONTENT_DIR;
985
+
986
+                        if ( function_exists( 'wp_normalize_path' ) ) {
987
+                            // Replaces backslashes with forward slashes for Windows systems
988
+                            $image = wp_normalize_path( $image );
989
+                            $content_dir = wp_normalize_path( $content_dir );
990
+                        }
991
+
992
+                        $image = str_replace( $content_dir, content_url(), $image );
993
+                    }
994
+
995
+                    echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
996
+                }
997
+            echo $option . '</label>';
998
+        }
999
+        echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
1000
+    }
1001 1001
 }
1002 1002
 
1003 1003
 function wpinv_radio_callback( $args ) {
1004
-	global $wpinv_options;
1004
+    global $wpinv_options;
1005 1005
     
1006 1006
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
1007 1007
     
1008 1008
     foreach ( $args['options'] as $key => $option ) :
1009
-		$sanitize_key = wpinv_sanitize_key( $key );
1009
+        $sanitize_key = wpinv_sanitize_key( $key );
1010 1010
         
1011 1011
         $checked = false;
1012 1012
 
1013
-		if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key )
1014
-			$checked = true;
1015
-		elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) )
1016
-			$checked = true;
1013
+        if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key )
1014
+            $checked = true;
1015
+        elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) )
1016
+            $checked = true;
1017 1017
 
1018
-		echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/>&nbsp;';
1019
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>';
1020
-	endforeach;
1018
+        echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/>&nbsp;';
1019
+        echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>';
1020
+    endforeach;
1021 1021
 
1022
-	echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
1022
+    echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
1023 1023
 }
1024 1024
 
1025 1025
 function wpinv_gateways_callback( $args ) {
1026
-	global $wpinv_options;
1026
+    global $wpinv_options;
1027 1027
     
1028 1028
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
1029 1029
 
1030
-	foreach ( $args['options'] as $key => $option ) :
1031
-		$sanitize_key = wpinv_sanitize_key( $key );
1030
+    foreach ( $args['options'] as $key => $option ) :
1031
+        $sanitize_key = wpinv_sanitize_key( $key );
1032 1032
         
1033 1033
         if ( isset( $wpinv_options['gateways'][ $key ] ) )
1034
-			$enabled = '1';
1035
-		else
1036
-			$enabled = null;
1034
+            $enabled = '1';
1035
+        else
1036
+            $enabled = null;
1037 1037
 
1038
-		echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
1039
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
1040
-	endforeach;
1038
+        echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
1039
+        echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
1040
+    endforeach;
1041 1041
 }
1042 1042
 
1043 1043
 function wpinv_gateway_select_callback($args) {
1044
-	global $wpinv_options;
1044
+    global $wpinv_options;
1045 1045
     
1046 1046
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
1047 1047
 
1048
-	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']">';
1048
+    echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']">';
1049 1049
 
1050
-	foreach ( $args['options'] as $key => $option ) :
1051
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
1050
+    foreach ( $args['options'] as $key => $option ) :
1051
+        if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
1052 1052
             $selected = selected( $key, $args['selected'], false );
1053 1053
         } else {
1054 1054
             $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : '';
1055 1055
         }
1056
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
1057
-	endforeach;
1056
+        echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
1057
+    endforeach;
1058 1058
 
1059
-	echo '</select>';
1060
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1059
+    echo '</select>';
1060
+    echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1061 1061
 }
1062 1062
 
1063 1063
 function wpinv_text_callback( $args ) {
1064
-	global $wpinv_options;
1064
+    global $wpinv_options;
1065 1065
     
1066 1066
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
1067 1067
 
1068
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1069
-		$value = $wpinv_options[ $args['id'] ];
1070
-	} else {
1071
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1072
-	}
1073
-
1074
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1075
-		$args['readonly'] = true;
1076
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1077
-		$name  = '';
1078
-	} else {
1079
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1080
-	}
1081
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
1082
-
1083
-	$readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
1084
-	$size     = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1085
-	$html     = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
1086
-	$html    .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1087
-
1088
-	echo $html;
1068
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1069
+        $value = $wpinv_options[ $args['id'] ];
1070
+    } else {
1071
+        $value = isset( $args['std'] ) ? $args['std'] : '';
1072
+    }
1073
+
1074
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1075
+        $args['readonly'] = true;
1076
+        $value = isset( $args['std'] ) ? $args['std'] : '';
1077
+        $name  = '';
1078
+    } else {
1079
+        $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1080
+    }
1081
+    $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
1082
+
1083
+    $readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
1084
+    $size     = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1085
+    $html     = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
1086
+    $html    .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1087
+
1088
+    echo $html;
1089 1089
 }
1090 1090
 
1091 1091
 function wpinv_number_callback( $args ) {
1092
-	global $wpinv_options;
1092
+    global $wpinv_options;
1093 1093
     
1094 1094
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
1095 1095
 
1096
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1097
-		$value = $wpinv_options[ $args['id'] ];
1098
-	} else {
1099
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1100
-	}
1101
-
1102
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1103
-		$args['readonly'] = true;
1104
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1105
-		$name  = '';
1106
-	} else {
1107
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1108
-	}
1109
-
1110
-	$max  = isset( $args['max'] ) ? $args['max'] : 999999;
1111
-	$min  = isset( $args['min'] ) ? $args['min'] : 0;
1112
-	$step = isset( $args['step'] ) ? $args['step'] : 1;
1113
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
1114
-
1115
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1116
-	$html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>';
1117
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1118
-
1119
-	echo $html;
1096
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1097
+        $value = $wpinv_options[ $args['id'] ];
1098
+    } else {
1099
+        $value = isset( $args['std'] ) ? $args['std'] : '';
1100
+    }
1101
+
1102
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1103
+        $args['readonly'] = true;
1104
+        $value = isset( $args['std'] ) ? $args['std'] : '';
1105
+        $name  = '';
1106
+    } else {
1107
+        $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1108
+    }
1109
+
1110
+    $max  = isset( $args['max'] ) ? $args['max'] : 999999;
1111
+    $min  = isset( $args['min'] ) ? $args['min'] : 0;
1112
+    $step = isset( $args['step'] ) ? $args['step'] : 1;
1113
+    $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
1114
+
1115
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1116
+    $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>';
1117
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1118
+
1119
+    echo $html;
1120 1120
 }
1121 1121
 
1122 1122
 function wpinv_textarea_callback( $args ) {
1123
-	global $wpinv_options;
1123
+    global $wpinv_options;
1124 1124
     
1125 1125
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
1126 1126
 
1127
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1128
-		$value = $wpinv_options[ $args['id'] ];
1129
-	} else {
1130
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1131
-	}
1127
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1128
+        $value = $wpinv_options[ $args['id'] ];
1129
+    } else {
1130
+        $value = isset( $args['std'] ) ? $args['std'] : '';
1131
+    }
1132 1132
     
1133 1133
     $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1134 1134
     $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
1135 1135
 
1136
-	$html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
1137
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1136
+    $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
1137
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1138 1138
 
1139
-	echo $html;
1139
+    echo $html;
1140 1140
 }
1141 1141
 
1142 1142
 function wpinv_password_callback( $args ) {
1143
-	global $wpinv_options;
1143
+    global $wpinv_options;
1144 1144
     
1145 1145
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
1146 1146
 
1147
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1148
-		$value = $wpinv_options[ $args['id'] ];
1149
-	} else {
1150
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1151
-	}
1147
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1148
+        $value = $wpinv_options[ $args['id'] ];
1149
+    } else {
1150
+        $value = isset( $args['std'] ) ? $args['std'] : '';
1151
+    }
1152 1152
 
1153
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1154
-	$html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
1155
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1153
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1154
+    $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
1155
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1156 1156
 
1157
-	echo $html;
1157
+    echo $html;
1158 1158
 }
1159 1159
 
1160 1160
 function wpinv_missing_callback($args) {
1161
-	printf(
1162
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
1163
-		'<strong>' . $args['id'] . '</strong>'
1164
-	);
1161
+    printf(
1162
+        __( 'The callback function used for the %s setting is missing.', 'invoicing' ),
1163
+        '<strong>' . $args['id'] . '</strong>'
1164
+    );
1165 1165
 }
1166 1166
 
1167 1167
 function wpinv_select_callback($args) {
1168
-	global $wpinv_options;
1168
+    global $wpinv_options;
1169 1169
     
1170 1170
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
1171 1171
 
1172
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1173
-		$value = $wpinv_options[ $args['id'] ];
1174
-	} else {
1175
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1176
-	}
1172
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1173
+        $value = $wpinv_options[ $args['id'] ];
1174
+    } else {
1175
+        $value = isset( $args['std'] ) ? $args['std'] : '';
1176
+    }
1177 1177
     
1178 1178
     if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
1179 1179
         $value = $args['selected'];
1180 1180
     }
1181 1181
 
1182
-	if ( isset( $args['placeholder'] ) ) {
1183
-		$placeholder = $args['placeholder'];
1184
-	} else {
1185
-		$placeholder = '';
1186
-	}
1182
+    if ( isset( $args['placeholder'] ) ) {
1183
+        $placeholder = $args['placeholder'];
1184
+    } else {
1185
+        $placeholder = '';
1186
+    }
1187 1187
     
1188 1188
     if( !empty( $args['onchange'] ) ) {
1189 1189
         $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
@@ -1191,142 +1191,142 @@  discard block
 block discarded – undo
1191 1191
         $onchange = '';
1192 1192
     }
1193 1193
 
1194
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />';
1194
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />';
1195 1195
 
1196
-	foreach ( $args['options'] as $option => $name ) {
1197
-		$selected = selected( $option, $value, false );
1198
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1199
-	}
1196
+    foreach ( $args['options'] as $option => $name ) {
1197
+        $selected = selected( $option, $value, false );
1198
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1199
+    }
1200 1200
 
1201
-	$html .= '</select>';
1202
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1201
+    $html .= '</select>';
1202
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1203 1203
 
1204
-	echo $html;
1204
+    echo $html;
1205 1205
 }
1206 1206
 
1207 1207
 function wpinv_color_select_callback( $args ) {
1208
-	global $wpinv_options;
1208
+    global $wpinv_options;
1209 1209
     
1210 1210
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
1211 1211
 
1212
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1213
-		$value = $wpinv_options[ $args['id'] ];
1214
-	} else {
1215
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1216
-	}
1212
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1213
+        $value = $wpinv_options[ $args['id'] ];
1214
+    } else {
1215
+        $value = isset( $args['std'] ) ? $args['std'] : '';
1216
+    }
1217 1217
 
1218
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
1218
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
1219 1219
 
1220
-	foreach ( $args['options'] as $option => $color ) {
1221
-		$selected = selected( $option, $value, false );
1222
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
1223
-	}
1220
+    foreach ( $args['options'] as $option => $color ) {
1221
+        $selected = selected( $option, $value, false );
1222
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
1223
+    }
1224 1224
 
1225
-	$html .= '</select>';
1226
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1225
+    $html .= '</select>';
1226
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1227 1227
 
1228
-	echo $html;
1228
+    echo $html;
1229 1229
 }
1230 1230
 
1231 1231
 function wpinv_rich_editor_callback( $args ) {
1232
-	global $wpinv_options, $wp_version;
1232
+    global $wpinv_options, $wp_version;
1233 1233
     
1234 1234
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
1235 1235
 
1236
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1237
-		$value = $wpinv_options[ $args['id'] ];
1236
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1237
+        $value = $wpinv_options[ $args['id'] ];
1238 1238
 
1239
-		if( empty( $args['allow_blank'] ) && empty( $value ) ) {
1240
-			$value = isset( $args['std'] ) ? $args['std'] : '';
1241
-		}
1242
-	} else {
1243
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1244
-	}
1239
+        if( empty( $args['allow_blank'] ) && empty( $value ) ) {
1240
+            $value = isset( $args['std'] ) ? $args['std'] : '';
1241
+        }
1242
+    } else {
1243
+        $value = isset( $args['std'] ) ? $args['std'] : '';
1244
+    }
1245 1245
 
1246
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
1246
+    $rows = isset( $args['size'] ) ? $args['size'] : 20;
1247 1247
 
1248
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
1249
-		ob_start();
1250
-		wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ) ) );
1251
-		$html = ob_get_clean();
1252
-	} else {
1253
-		$html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
1254
-	}
1248
+    if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
1249
+        ob_start();
1250
+        wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ) ) );
1251
+        $html = ob_get_clean();
1252
+    } else {
1253
+        $html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
1254
+    }
1255 1255
 
1256
-	$html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1256
+    $html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1257 1257
 
1258
-	echo $html;
1258
+    echo $html;
1259 1259
 }
1260 1260
 
1261 1261
 function wpinv_upload_callback( $args ) {
1262
-	global $wpinv_options;
1262
+    global $wpinv_options;
1263 1263
     
1264 1264
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
1265 1265
 
1266
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1267
-		$value = $wpinv_options[$args['id']];
1268
-	} else {
1269
-		$value = isset($args['std']) ? $args['std'] : '';
1270
-	}
1266
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1267
+        $value = $wpinv_options[$args['id']];
1268
+    } else {
1269
+        $value = isset($args['std']) ? $args['std'] : '';
1270
+    }
1271 1271
 
1272
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1273
-	$html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
1274
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
1275
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1272
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1273
+    $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
1274
+    $html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
1275
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1276 1276
 
1277
-	echo $html;
1277
+    echo $html;
1278 1278
 }
1279 1279
 
1280 1280
 function wpinv_color_callback( $args ) {
1281
-	global $wpinv_options;
1281
+    global $wpinv_options;
1282 1282
     
1283 1283
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
1284 1284
 
1285
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1286
-		$value = $wpinv_options[ $args['id'] ];
1287
-	} else {
1288
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1289
-	}
1285
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1286
+        $value = $wpinv_options[ $args['id'] ];
1287
+    } else {
1288
+        $value = isset( $args['std'] ) ? $args['std'] : '';
1289
+    }
1290 1290
 
1291
-	$default = isset( $args['std'] ) ? $args['std'] : '';
1291
+    $default = isset( $args['std'] ) ? $args['std'] : '';
1292 1292
 
1293
-	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
1294
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1293
+    $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
1294
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1295 1295
 
1296
-	echo $html;
1296
+    echo $html;
1297 1297
 }
1298 1298
 
1299 1299
 function wpinv_country_states_callback($args) {
1300
-	global $wpinv_options;
1300
+    global $wpinv_options;
1301 1301
     
1302 1302
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
1303 1303
 
1304
-	if ( isset( $args['placeholder'] ) ) {
1305
-		$placeholder = $args['placeholder'];
1306
-	} else {
1307
-		$placeholder = '';
1308
-	}
1304
+    if ( isset( $args['placeholder'] ) ) {
1305
+        $placeholder = $args['placeholder'];
1306
+    } else {
1307
+        $placeholder = '';
1308
+    }
1309 1309
 
1310
-	$states = wpinv_get_country_states();
1310
+    $states = wpinv_get_country_states();
1311 1311
 
1312
-	$class = empty( $states ) ? ' class="wpinv-no-states"' : '';
1313
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
1312
+    $class = empty( $states ) ? ' class="wpinv-no-states"' : '';
1313
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
1314 1314
 
1315
-	foreach ( $states as $option => $name ) {
1316
-		$selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
1317
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1318
-	}
1315
+    foreach ( $states as $option => $name ) {
1316
+        $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
1317
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1318
+    }
1319 1319
 
1320
-	$html .= '</select>';
1321
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1320
+    $html .= '</select>';
1321
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1322 1322
 
1323
-	echo $html;
1323
+    echo $html;
1324 1324
 }
1325 1325
 
1326 1326
 function wpinv_tax_rates_callback($args) {
1327
-	global $wpinv_options;
1328
-	$rates = wpinv_get_tax_rates();
1329
-	ob_start(); ?>
1327
+    global $wpinv_options;
1328
+    $rates = wpinv_get_tax_rates();
1329
+    ob_start(); ?>
1330 1330
     </td><tr>
1331 1331
     <td colspan="2" class="wpinv_tax_tdbox">
1332 1332
 	<p><?php echo $args['desc']; ?></p>
@@ -1350,39 +1350,39 @@  discard block
 block discarded – undo
1350 1350
 			<tr>
1351 1351
 				<td class="wpinv_tax_country">
1352 1352
 					<?php
1353
-					echo wpinv_html_select( array(
1354
-						'options'          => wpinv_get_country_list( true ),
1355
-						'name'             => 'tax_rates[' . $sanitized_key . '][country]',
1353
+                    echo wpinv_html_select( array(
1354
+                        'options'          => wpinv_get_country_list( true ),
1355
+                        'name'             => 'tax_rates[' . $sanitized_key . '][country]',
1356 1356
                         'id'               => 'tax_rates[' . $sanitized_key . '][country]',
1357
-						'selected'         => $rate['country'],
1358
-						'show_option_all'  => false,
1359
-						'show_option_none' => false,
1360
-						'class'            => 'wpinv-tax-country',
1361
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
1362
-					) );
1363
-					?>
1357
+                        'selected'         => $rate['country'],
1358
+                        'show_option_all'  => false,
1359
+                        'show_option_none' => false,
1360
+                        'class'            => 'wpinv-tax-country',
1361
+                        'placeholder'      => __( 'Choose a country', 'invoicing' )
1362
+                    ) );
1363
+                    ?>
1364 1364
 				</td>
1365 1365
 				<td class="wpinv_tax_state">
1366 1366
 					<?php
1367
-					$states = wpinv_get_country_states( $rate['country'] );
1368
-					if( !empty( $states ) ) {
1369
-						echo wpinv_html_select( array(
1370
-							'options'          => array_merge( array( '' => '' ), $states ),
1371
-							'name'             => 'tax_rates[' . $sanitized_key . '][state]',
1367
+                    $states = wpinv_get_country_states( $rate['country'] );
1368
+                    if( !empty( $states ) ) {
1369
+                        echo wpinv_html_select( array(
1370
+                            'options'          => array_merge( array( '' => '' ), $states ),
1371
+                            'name'             => 'tax_rates[' . $sanitized_key . '][state]',
1372 1372
                             'id'               => 'tax_rates[' . $sanitized_key . '][state]',
1373
-							'selected'         => $rate['state'],
1374
-							'show_option_all'  => false,
1375
-							'show_option_none' => false,
1376
-							'placeholder'      => __( 'Choose a state', 'invoicing' )
1377
-						) );
1378
-					} else {
1379
-						echo wpinv_html_text( array(
1380
-							'name'  => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'],
1381
-							'value' => ! empty( $rate['state'] ) ? $rate['state'] : '',
1373
+                            'selected'         => $rate['state'],
1374
+                            'show_option_all'  => false,
1375
+                            'show_option_none' => false,
1376
+                            'placeholder'      => __( 'Choose a state', 'invoicing' )
1377
+                        ) );
1378
+                    } else {
1379
+                        echo wpinv_html_text( array(
1380
+                            'name'  => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'],
1381
+                            'value' => ! empty( $rate['state'] ) ? $rate['state'] : '',
1382 1382
                             'id'    => 'tax_rates[' . $sanitized_key . '][state]',
1383
-						) );
1384
-					}
1385
-					?>
1383
+                        ) );
1384
+                    }
1385
+                    ?>
1386 1386
 				</td>
1387 1387
 				<td class="wpinv_tax_global">
1388 1388
 					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/>
@@ -1397,19 +1397,19 @@  discard block
 block discarded – undo
1397 1397
 			<tr>
1398 1398
 				<td class="wpinv_tax_country">
1399 1399
 					<?php
1400
-					echo wpinv_html_select( array(
1401
-						'options'          => wpinv_get_country_list( true ),
1402
-						'name'             => 'tax_rates[0][country]',
1403
-						'show_option_all'  => false,
1404
-						'show_option_none' => false,
1405
-						'class'            => 'wpinv-tax-country',
1406
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
1407
-					) ); ?>
1400
+                    echo wpinv_html_select( array(
1401
+                        'options'          => wpinv_get_country_list( true ),
1402
+                        'name'             => 'tax_rates[0][country]',
1403
+                        'show_option_all'  => false,
1404
+                        'show_option_none' => false,
1405
+                        'class'            => 'wpinv-tax-country',
1406
+                        'placeholder'      => __( 'Choose a country', 'invoicing' )
1407
+                    ) ); ?>
1408 1408
 				</td>
1409 1409
 				<td class="wpinv_tax_state">
1410 1410
 					<?php echo wpinv_html_text( array(
1411
-						'name' => 'tax_rates[0][state]'
1412
-					) ); ?>
1411
+                        'name' => 'tax_rates[0][state]'
1412
+                    ) ); ?>
1413 1413
 				</td>
1414 1414
 				<td class="wpinv_tax_global">
1415 1415
 					<input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/>
@@ -1424,7 +1424,7 @@  discard block
 block discarded – undo
1424 1424
         <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot>
1425 1425
 	</table>
1426 1426
 	<?php
1427
-	echo ob_get_clean();
1427
+    echo ob_get_clean();
1428 1428
 }
1429 1429
 
1430 1430
 function wpinv_tools_callback($args) {
@@ -1452,15 +1452,15 @@  discard block
 block discarded – undo
1452 1452
 }
1453 1453
 
1454 1454
 function wpinv_descriptive_text_callback( $args ) {
1455
-	echo wp_kses_post( $args['desc'] );
1455
+    echo wp_kses_post( $args['desc'] );
1456 1456
 }
1457 1457
 
1458 1458
 function wpinv_hook_callback( $args ) {
1459
-	do_action( 'wpinv_' . $args['id'], $args );
1459
+    do_action( 'wpinv_' . $args['id'], $args );
1460 1460
 }
1461 1461
 
1462 1462
 function wpinv_set_settings_cap() {
1463
-	return 'manage_options';
1463
+    return 'manage_options';
1464 1464
 }
1465 1465
 add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1466 1466
 
Please login to merge, or discard this patch.
includes/gateways/paypal.php 1 patch
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -218,261 +218,261 @@  discard block
 block discarded – undo
218 218
 add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
219 219
 
220 220
 function wpinv_process_paypal_ipn() {
221
-	// Check the request method is POST
222
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
223
-		return;
224
-	}
225
-
226
-	// Set initial post data to empty string
227
-	$post_data = '';
228
-
229
-	// Fallback just in case post_max_size is lower than needed
230
-	if ( ini_get( 'allow_url_fopen' ) ) {
231
-		$post_data = file_get_contents( 'php://input' );
232
-	} else {
233
-		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
234
-		ini_set( 'post_max_size', '12M' );
235
-	}
236
-	// Start the encoded data collection with notification command
237
-	$encoded_data = 'cmd=_notify-validate';
238
-
239
-	// Get current arg separator
240
-	$arg_separator = wpinv_get_php_arg_separator_output();
241
-
242
-	// Verify there is a post_data
243
-	if ( $post_data || strlen( $post_data ) > 0 ) {
244
-		// Append the data
245
-		$encoded_data .= $arg_separator.$post_data;
246
-	} else {
247
-		// Check if POST is empty
248
-		if ( empty( $_POST ) ) {
249
-			// Nothing to do
250
-			return;
251
-		} else {
252
-			// Loop through each POST
253
-			foreach ( $_POST as $key => $value ) {
254
-				// Encode the value and append the data
255
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
256
-			}
257
-		}
258
-	}
259
-
260
-	// Convert collected post data to an array
261
-	parse_str( $encoded_data, $encoded_data_array );
262
-
263
-	foreach ( $encoded_data_array as $key => $value ) {
264
-		if ( false !== strpos( $key, 'amp;' ) ) {
265
-			$new_key = str_replace( '&amp;', '&', $key );
266
-			$new_key = str_replace( 'amp;', '&' , $new_key );
267
-
268
-			unset( $encoded_data_array[ $key ] );
269
-			$encoded_data_array[ $new_key ] = $value;
270
-		}
271
-	}
272
-
273
-	// Get the PayPal redirect uri
274
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
275
-
276
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
277
-		// Validate the IPN
278
-
279
-		$remote_post_vars      = array(
280
-			'method'           => 'POST',
281
-			'timeout'          => 45,
282
-			'redirection'      => 5,
283
-			'httpversion'      => '1.1',
284
-			'blocking'         => true,
285
-			'headers'          => array(
286
-				'host'         => 'www.paypal.com',
287
-				'connection'   => 'close',
288
-				'content-type' => 'application/x-www-form-urlencoded',
289
-				'post'         => '/cgi-bin/webscr HTTP/1.1',
290
-
291
-			),
292
-			'sslverify'        => false,
293
-			'body'             => $encoded_data_array
294
-		);
295
-
296
-		// Get response
297
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
298
-
299
-		if ( is_wp_error( $api_response ) ) {
300
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
301
-			return; // Something went wrong
302
-		}
303
-
304
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
305
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
306
-			return; // Response not okay
307
-		}
308
-	}
309
-
310
-	// Check if $post_data_array has been populated
311
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
312
-		return;
313
-
314
-	$defaults = array(
315
-		'txn_type'       => '',
316
-		'payment_status' => ''
317
-	);
318
-
319
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
320
-
321
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
221
+    // Check the request method is POST
222
+    if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
223
+        return;
224
+    }
225
+
226
+    // Set initial post data to empty string
227
+    $post_data = '';
228
+
229
+    // Fallback just in case post_max_size is lower than needed
230
+    if ( ini_get( 'allow_url_fopen' ) ) {
231
+        $post_data = file_get_contents( 'php://input' );
232
+    } else {
233
+        // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
234
+        ini_set( 'post_max_size', '12M' );
235
+    }
236
+    // Start the encoded data collection with notification command
237
+    $encoded_data = 'cmd=_notify-validate';
238
+
239
+    // Get current arg separator
240
+    $arg_separator = wpinv_get_php_arg_separator_output();
241
+
242
+    // Verify there is a post_data
243
+    if ( $post_data || strlen( $post_data ) > 0 ) {
244
+        // Append the data
245
+        $encoded_data .= $arg_separator.$post_data;
246
+    } else {
247
+        // Check if POST is empty
248
+        if ( empty( $_POST ) ) {
249
+            // Nothing to do
250
+            return;
251
+        } else {
252
+            // Loop through each POST
253
+            foreach ( $_POST as $key => $value ) {
254
+                // Encode the value and append the data
255
+                $encoded_data .= $arg_separator."$key=" . urlencode( $value );
256
+            }
257
+        }
258
+    }
259
+
260
+    // Convert collected post data to an array
261
+    parse_str( $encoded_data, $encoded_data_array );
262
+
263
+    foreach ( $encoded_data_array as $key => $value ) {
264
+        if ( false !== strpos( $key, 'amp;' ) ) {
265
+            $new_key = str_replace( '&amp;', '&', $key );
266
+            $new_key = str_replace( 'amp;', '&' , $new_key );
267
+
268
+            unset( $encoded_data_array[ $key ] );
269
+            $encoded_data_array[ $new_key ] = $value;
270
+        }
271
+    }
272
+
273
+    // Get the PayPal redirect uri
274
+    $paypal_redirect = wpinv_get_paypal_redirect( true );
275
+
276
+    if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
277
+        // Validate the IPN
278
+
279
+        $remote_post_vars      = array(
280
+            'method'           => 'POST',
281
+            'timeout'          => 45,
282
+            'redirection'      => 5,
283
+            'httpversion'      => '1.1',
284
+            'blocking'         => true,
285
+            'headers'          => array(
286
+                'host'         => 'www.paypal.com',
287
+                'connection'   => 'close',
288
+                'content-type' => 'application/x-www-form-urlencoded',
289
+                'post'         => '/cgi-bin/webscr HTTP/1.1',
290
+
291
+            ),
292
+            'sslverify'        => false,
293
+            'body'             => $encoded_data_array
294
+        );
295
+
296
+        // Get response
297
+        $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
298
+
299
+        if ( is_wp_error( $api_response ) ) {
300
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
301
+            return; // Something went wrong
302
+        }
303
+
304
+        if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
305
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
306
+            return; // Response not okay
307
+        }
308
+    }
309
+
310
+    // Check if $post_data_array has been populated
311
+    if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
312
+        return;
313
+
314
+    $defaults = array(
315
+        'txn_type'       => '',
316
+        'payment_status' => ''
317
+    );
318
+
319
+    $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
320
+
321
+    $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
322 322
     
323
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
324
-
325
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
326
-		// Allow PayPal IPN types to be processed separately
327
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
328
-	} else {
329
-		// Fallback to web accept just in case the txn_type isn't present
330
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
331
-	}
332
-	exit;
323
+    wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
324
+
325
+    if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
326
+        // Allow PayPal IPN types to be processed separately
327
+        do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
328
+    } else {
329
+        // Fallback to web accept just in case the txn_type isn't present
330
+        do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
331
+    }
332
+    exit;
333 333
 }
334 334
 add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
335 335
 
336 336
 function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
337
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
338
-		return;
339
-	}
340
-
341
-	if( empty( $invoice_id ) ) {
342
-		return;
343
-	}
344
-
345
-	// Collect payment details
346
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
347
-	$paypal_amount  = $data['mc_gross'];
348
-	$payment_status = strtolower( $data['payment_status'] );
349
-	$currency_code  = strtolower( $data['mc_currency'] );
350
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
351
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id );
352
-
353
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
354
-		return; // this isn't a PayPal standard IPN
355
-	}
356
-
357
-	// Verify payment recipient
358
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
359
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
360
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
361
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) );
362
-		return;
363
-	}
364
-
365
-	// Verify payment currency
366
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
367
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
368
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
369
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) );
370
-		return;
371
-	}
372
-
373
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
374
-		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
375
-		// No email associated with purchase, so store from PayPal
376
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
377
-
378
-		// Setup and store the customer's details
379
-		$user_info = array(
380
-			'user_id'    => '-1',
381
-			'email'      => sanitize_text_field( $data['payer_email'] ),
382
-			'first_name' => sanitize_text_field( $data['first_name'] ),
383
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
384
-			'discount'   => '',
385
-		);
386
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
387
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
388
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
389
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
390
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
391
-
392
-		$payment_meta['user_info'] = $user_info;
393
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
394
-	}
395
-
396
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
397
-		// Process a refund
398
-		wpinv_process_paypal_refund( $data, $invoice_id );
399
-	} else {
400
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
401
-			return; // Only paid payments once
402
-		}
403
-
404
-		// Retrieve the total purchase amount (before PayPal)
405
-		$payment_amount = wpinv_payment_total( $invoice_id );
406
-
407
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
408
-			// The prices don't match
409
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
410
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
411
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) );
412
-			return;
413
-		}
414
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
415
-			// Purchase keys don't match
416
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
417
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
418
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) );
419
-			return;
420
-		}
421
-
422
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
423
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) );
424
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
425
-			wpinv_update_payment_status( $invoice_id, 'publish' );
426
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
427
-			// Look for possible pending reasons, such as an echeck
428
-			$note = '';
429
-
430
-			switch( strtolower( $data['pending_reason'] ) ) {
431
-				case 'echeck' :
432
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
433
-					break;
337
+    if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
338
+        return;
339
+    }
340
+
341
+    if( empty( $invoice_id ) ) {
342
+        return;
343
+    }
344
+
345
+    // Collect payment details
346
+    $purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
347
+    $paypal_amount  = $data['mc_gross'];
348
+    $payment_status = strtolower( $data['payment_status'] );
349
+    $currency_code  = strtolower( $data['mc_currency'] );
350
+    $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
351
+    $payment_meta   = wpinv_get_invoice_meta( $invoice_id );
352
+
353
+    if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
354
+        return; // this isn't a PayPal standard IPN
355
+    }
356
+
357
+    // Verify payment recipient
358
+    if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
359
+        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
360
+        wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
361
+        wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) );
362
+        return;
363
+    }
364
+
365
+    // Verify payment currency
366
+    if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
367
+        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
368
+        wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
369
+        wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) );
370
+        return;
371
+    }
372
+
373
+    if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
374
+        // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
375
+        // No email associated with purchase, so store from PayPal
376
+        wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
377
+
378
+        // Setup and store the customer's details
379
+        $user_info = array(
380
+            'user_id'    => '-1',
381
+            'email'      => sanitize_text_field( $data['payer_email'] ),
382
+            'first_name' => sanitize_text_field( $data['first_name'] ),
383
+            'last_name'  => sanitize_text_field( $data['last_name'] ),
384
+            'discount'   => '',
385
+        );
386
+        $user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
387
+        $user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
388
+        $user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
389
+        $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
390
+        $user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
391
+
392
+        $payment_meta['user_info'] = $user_info;
393
+        wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
394
+    }
395
+
396
+    if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
397
+        // Process a refund
398
+        wpinv_process_paypal_refund( $data, $invoice_id );
399
+    } else {
400
+        if ( get_post_status( $invoice_id ) == 'publish' ) {
401
+            return; // Only paid payments once
402
+        }
403
+
404
+        // Retrieve the total purchase amount (before PayPal)
405
+        $payment_amount = wpinv_payment_total( $invoice_id );
406
+
407
+        if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
408
+            // The prices don't match
409
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
410
+            wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
411
+            wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) );
412
+            return;
413
+        }
414
+        if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
415
+            // Purchase keys don't match
416
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
417
+            wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
418
+            wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) );
419
+            return;
420
+        }
421
+
422
+        if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
423
+            wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) );
424
+            wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
425
+            wpinv_update_payment_status( $invoice_id, 'publish' );
426
+        } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
427
+            // Look for possible pending reasons, such as an echeck
428
+            $note = '';
429
+
430
+            switch( strtolower( $data['pending_reason'] ) ) {
431
+                case 'echeck' :
432
+                    $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
433
+                    break;
434 434
 				
435 435
                 case 'address' :
436
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
437
-					break;
436
+                    $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
437
+                    break;
438 438
 				
439 439
                 case 'intl' :
440
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
441
-					break;
440
+                    $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
441
+                    break;
442 442
 				
443 443
                 case 'multi-currency' :
444
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
445
-					break;
444
+                    $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
445
+                    break;
446 446
 				
447 447
                 case 'paymentreview' :
448 448
                 case 'regulatory_review' :
449
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
450
-					break;
449
+                    $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
450
+                    break;
451 451
 				
452 452
                 case 'unilateral' :
453
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
454
-					break;
453
+                    $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
454
+                    break;
455 455
 				
456 456
                 case 'upgrade' :
457
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
458
-					break;
457
+                    $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
458
+                    break;
459 459
 				
460 460
                 case 'verify' :
461
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
462
-					break;
463
-
464
-				case 'other' :
465
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
466
-					break;
467
-			}
468
-
469
-			if ( ! empty( $note ) ) {
470
-				wpinv_insert_payment_note( $invoice_id, $note );
471
-			}
472
-		} else {
473
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) );
474
-		}
475
-	}
461
+                    $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
462
+                    break;
463
+
464
+                case 'other' :
465
+                    $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
466
+                    break;
467
+            }
468
+
469
+            if ( ! empty( $note ) ) {
470
+                wpinv_insert_payment_note( $invoice_id, $note );
471
+            }
472
+        } else {
473
+            wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) );
474
+        }
475
+    }
476 476
 }
477 477
 add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
478 478
 
@@ -693,27 +693,27 @@  discard block
 block discarded – undo
693 693
 }
694 694
 
695 695
 function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
696
-	// Collect payment details
696
+    // Collect payment details
697 697
 
698
-	if( empty( $invoice_id ) ) {
699
-		return;
700
-	}
698
+    if( empty( $invoice_id ) ) {
699
+        return;
700
+    }
701 701
 
702
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
703
-		return; // Only refund payments once
704
-	}
702
+    if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
703
+        return; // Only refund payments once
704
+    }
705 705
 
706
-	$payment_amount = wpinv_payment_total( $invoice_id );
707
-	$refund_amount  = $data['mc_gross'] * -1;
706
+    $payment_amount = wpinv_payment_total( $invoice_id );
707
+    $refund_amount  = $data['mc_gross'] * -1;
708 708
 
709
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
710
-		wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) );
711
-		return; // This is a partial refund
712
-	}
709
+    if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
710
+        wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) );
711
+        return; // This is a partial refund
712
+    }
713 713
 
714
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) );
715
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) );
716
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
714
+    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) );
715
+    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) );
716
+    wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
717 717
 }
718 718
 
719 719
 function wpinv_get_paypal_redirect( $ssl_check = false ) {
Please login to merge, or discard this patch.