Changeset 32164 for trunk/src/wp-includes/formatting.php
- Timestamp:
- 04/20/2015 05:41:37 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/formatting.php
r32161 r32164 1363 1363 1364 1364 /** 1365 * Ensures a string is a valid SQL order by clause. 1366 * 1367 * Accepts one or more columns, with or without ASC/DESC, and also accepts 1368 * RAND(). 1365 * Ensures a string is a valid SQL 'order by' clause. 1366 * 1367 * Accepts one or more columns, with or without a sort order (ASC / DESC). 1368 * e.g. 'column_1', 'column_1, column_2', 'column_1 ASC, column_2 DESC' etc. 1369 * 1370 * Also accepts 'RAND()'. 1369 1371 * 1370 1372 * @since 2.5.1 1371 1373 * 1372 * @param string $orderby Order by string to be checked.1373 * @return false|string Returns the order by clause if it is a match, false otherwise.1374 */ 1375 function sanitize_sql_orderby( $orderby ) {1376 preg_match('/^\s*([a-z0-9_]+(\s+(ASC|DESC))?(\s*,\s*|\s*$))+|^\s*RAND\(\s*\)\s*$/i', $orderby, $obmatches);1377 if ( !$obmatches )1378 return false;1379 return $orderby;1374 * @param string $orderby Order by clause to be validated. 1375 * @return string|bool Returns $orderby if valid, false otherwise. 1376 */ 1377 function sanitize_sql_orderby( $orderby ) { 1378 if ( preg_match( '/^\s*(([a-z0-9_]+|`[a-z0-9_]+`)(\s+(ASC|DESC))?\s*(,\s*(?=[a-z0-9_`])|$))+$/i', $orderby ) || preg_match( '/^\s*RAND\(\s*\)\s*$/i', $orderby ) ) { 1379 return $orderby; 1380 } 1381 return false; 1380 1382 } 1381 1383
Note: See TracChangeset
for help on using the changeset viewer.