| @@ -85,26 +85,17 @@ | ||
| 85 | 85 | ]; |
| 86 | 86 | |
| 87 | 87 | $r = wp_parse_args( $args, $defaults ); |
| 88 | 88 | |
| 89 | - $query = $wpdb->prepare( | |
| 90 | - " | |
| 91 | - SELECT id, form_id, user_id, INET_NTOA( user_ip ) as ip_address, created_at | |
| 92 | - FROM $wpdb->weforms_entries | |
| 93 | - WHERE form_id = %d AND status = %s | |
| 94 | - ORDER BY %s %s | |
| 95 | - LIMIT %d, %d | |
| 96 | - ", | |
| 97 | - array( | |
| 98 | - $form_id, | |
| 99 | - $r['status'], | |
| 100 | - $r['orderby'], | |
| 101 | - $r['order'], | |
| 102 | - $r['offset'], | |
| 103 | - $r['number'], | |
| 104 | - ) | |
| 105 | - ); | |
| 89 | + $query = 'SELECT id, form_id, user_id, INET_NTOA( user_ip ) as ip_address, created_at | |
| 90 | + FROM ' . $wpdb->weforms_entries . | |
| 91 | + ' WHERE form_id = ' . $form_id . ' AND status = \'' . $r['status'] . '\'' . | |
| 92 | + ' ORDER BY ' . $r['orderby'] . ' ' . $r['order']; | |
| 106 | 93 | |
| 94 | + if ( !empty( $r['offset'] ) && !empty( $r['number'] ) ) { | |
| 95 | + $query .= ' LIMIT ' . $r['offset'] . ', ' . $r['number']; | |
| 96 | + } | |
| 97 | + | |
| 107 | 98 | $results = $wpdb->get_results( $query ); |
| 108 | 99 | |
| 109 | 100 | return $results; |
| 110 | 101 | } |
| @@ -119,8 +110,10 @@ | ||
| 119 | 110 | function weforms_count_entries( $args = [] ) { |
| 120 | 111 | global $wpdb; |
| 121 | 112 | |
| 122 | 113 | $defaults = [ |
| 114 | + 'number' => -1, | |
| 115 | + 'offset' => 0, | |
| 123 | 116 | 'orderby' => 'created_at', |
| 124 | 117 | 'status' => 'publish', |
| 125 | 118 | 'order' => 'DESC', |
| 126 | 119 | ]; |
| @@ -126,22 +119,17 @@ | ||
| 126 | 119 | ]; |
| 127 | 120 | |
| 128 | 121 | $r = wp_parse_args( $args, $defaults ); |
| 129 | 122 | |
| 130 | - $query = $wpdb->prepare( | |
| 131 | - " | |
| 132 | - SELECT id, form_id, user_id, INET_NTOA( user_ip ) as ip_address, created_at | |
| 133 | - FROM $wpdb->weforms_entries | |
| 134 | - WHERE status = %s | |
| 135 | - ORDER BY %s %s | |
| 136 | - ", | |
| 137 | - array( | |
| 138 | - $r['status'], | |
| 139 | - $r['orderby'], | |
| 140 | - $r['order'], | |
| 141 | - ) | |
| 142 | - ); | |
| 123 | + $query = 'SELECT id, form_id, user_id, INET_NTOA( user_ip ) as ip_address, created_at | |
| 124 | + FROM ' . $wpdb->weforms_entries . | |
| 125 | + ' WHERE status = \'' . $r['status'] . '\'' . | |
| 126 | + ' ORDER BY ' . $r['orderby'] . ' ' . $r['order']; | |
| 143 | 127 | |
| 128 | + if ( !empty( $r['offset'] ) && !empty( $r['number'] ) ) { | |
| 129 | + $query .= ' LIMIT ' . $r['offset'] . ', ' . $r['number']; | |
| 130 | + } | |
| 131 | + | |
| 144 | 132 | $results = $wpdb->get_results( $query ); |
| 145 | 133 | |
| 146 | 134 | return count( $results ); |
| 147 | 135 | } |
| @@ -165,24 +153,12 @@ | ||
| 165 | 153 | ]; |
| 166 | 154 | |
| 167 | 155 | $r = wp_parse_args( $args, $defaults ); |
| 168 | 156 | |
| 169 | - $query = $wpdb->prepare( | |
| 170 | - " | |
| 171 | - SELECT * | |
| 172 | - FROM wp_weforms_payments | |
| 173 | - WHERE form_id = %d | |
| 174 | - ORDER BY %s %s | |
| 175 | - LIMIT %d, %d | |
| 176 | - ", | |
| 177 | - array( | |
| 178 | - $form_id, | |
| 179 | - $r['orderby'], | |
| 180 | - $r['order'], | |
| 181 | - $r['offset'], | |
| 182 | - $r['number'], | |
| 183 | - ) | |
| 184 | - ); | |
| 157 | + $query = 'SELECT * FROM ' . $wpdb->prefix . 'weforms_payments' . | |
| 158 | + ' WHERE form_id = ' . $form_id . | |
| 159 | + ' ORDER BY ' . $r['orderby'] . ' ' . $r['order'] . | |
| 160 | + ' LIMIT ' . $r['offset'] . ', ' . $r['number']; | |
| 185 | 161 | |
| 186 | 162 | $results = $wpdb->get_results( $query ); |
| 187 | 163 | |
| 188 | 164 | return $results; |
| @@ -197,19 +173,11 @@ | ||
| 197 | 173 | */ |
| 198 | 174 | function weforms_get_entry_payment( $entry_id ) { |
| 199 | 175 | global $wpdb; |
| 200 | 176 | |
| 201 | - $query = $wpdb->prepare( | |
| 202 | - " | |
| 203 | - SELECT transaction_id | |
| 204 | - FROM $wpdb->prefix 'weforms_payments' | |
| 205 | - WHERE entry_id = %d | |
| 206 | - ", | |
| 207 | - array( | |
| 208 | - $entry_id | |
| 209 | - ) | |
| 210 | - ); | |
| 211 | - $payment = $wpdb->get_row( $query ); | |
| 177 | + $query = 'SELECT transaction_id FROM ' . $wpdb->prefix . 'weforms_payments' . | |
| 178 | + ' WHERE entry_id = ' . $entry_id; | |
| 179 | + $payment = $wpdb->get_row( $query, $entry_id ); | |
| 212 | 180 | |
| 213 | 181 | return $payment; |
| 214 | 182 | } |
| 215 | 183 | |
| @@ -255,9 +223,9 @@ | ||
| 255 | 223 | 'form_id' => 0, |
| 256 | 224 | 'user_id' => get_current_user_id(), |
| 257 | 225 | 'user_ip' => ip2long( weforms_get_client_ip() ), |
| 258 | 226 | 'user_device' => $browser['name'] . '/' . $browser['platform'], |
| 259 | - 'referer' => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '', | |
| 227 | + 'referer' => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '', | |
| 260 | 228 | 'created_at' => current_time( 'mysql' ) |
| 261 | 229 | ]; |
| 262 | 230 | |
| 263 | 231 | $r = wp_parse_args( $args, $defaults ); |
| @@ -1247,17 +1215,16 @@ | ||
| 1247 | 1215 | * |
| 1248 | 1216 | * @return string |
| 1249 | 1217 | **/ |
| 1250 | 1218 | function weforms_get_pain_text( $value ) { |
| 1251 | - // Security fix: Removed unsafe unserialize() call to prevent PHP Object Injection. | |
| 1252 | - // WordPress's get_metadata() already handles deserialization safely. | |
| 1253 | - // Any serialized strings at this point should be treated as untrusted user input. | |
| 1219 | + if ( is_serialized( $value ) ) { | |
| 1220 | + $value = unserialize( $value ); | |
| 1221 | + } | |
| 1254 | 1222 | |
| 1255 | 1223 | if ( is_array( $value ) ) { |
| 1256 | 1224 | $string_value = []; |
| 1257 | 1225 | foreach ( $value as $key => $single_value ) { |
| 1258 | - // Only recursively process arrays, not serialized strings | |
| 1259 | - if ( is_array( $single_value ) ) { | |
| 1226 | + if ( is_array( $single_value ) || is_serialized( $single_value ) ) { | |
| 1260 | 1227 | $single_value = weforms_get_pain_text( $single_value ); |
| 1261 | 1228 | } |
| 1262 | 1229 | |
| 1263 | 1230 | $single_value = ucwords( str_replace( [ '_', '-' ], ' ', $key ) ) . ': ' . ucwords( $single_value ); |
| @@ -1352,7 +1319,7 @@ | ||
| 1352 | 1319 | function weforms_clean( $var ) { |
| 1353 | 1320 | if ( is_array( $var ) ) { |
| 1354 | 1321 | return array_map( 'weforms_clean', $var ); |
| 1355 | 1322 | } else { |
| 1356 | - return is_scalar( $var ) ? sanitize_textarea_field( wp_unslash( $var ) ) : $var; | |
| 1323 | + return is_scalar( $var ) ? sanitize_text_field( wp_unslash( $var ) ) : $var; | |
| 1357 | 1324 | } |
| 1358 | 1325 | } |