| 1255 | |
| 1256 | /** |
| 1257 | * Patch to find number of convertible patterns in the query and match it to the arguments count |
| 1258 | * Throw a notice if there is a mismatch in the number of covertible patterns to the argument count passed in |
| 1259 | * I recommend exception over notice but keeping backward compatibility in mind, i have used notice. |
| 1260 | */ |
| 1261 | |
| 1262 | preg_match_all('/%(%|s|d|F)/', $query, $patterns, PREG_SET_ORDER, 0); // search for %% %s %d %F in the string |
| 1263 | $convertible_pattern_count = 0; |
| 1264 | |
| 1265 | foreach ( $patterns as $pattern ) { |
| 1266 | if ( $pattern[0][0] != "%%" ) { // as %% is a escape pattern, ignore %% form the list of convertible pattern |
| 1267 | $convertible_pattern_count++; |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | if ( count( $args ) != $convertible_pattern_count ) { |
| 1272 | _doing_it_wrong( |
| 1273 | 'wpdb::prepare', |
| 1274 | sprintf('Number of argument passed is incorrect. Requires %d arguments, but %d arguments is passed', $convertible_pattern_count, count($args)), |
| 1275 | '4.8.2' //version needs to be updated accordingly |
| 1276 | ); |
| 1277 | } |
| 1278 | |