sanitize_sql_orderby() - WordPress 函数参考中文文档

返回介绍

sanitize_sql_orderby()

发布于 2017-09-11 字数 1298 浏览 937 评论 0

sanitize_sql_orderby( string $orderby )

Ensures a string is a valid SQL ‘order by’ clause.


描述

Accepts one or more columns, with or without a sort order (ASC / DESC). e.g. ‘column_1’, ‘column_1, column_2’, ‘column_1 ASC, column_2 DESC’ etc.

Also accepts ‘RAND()’.


参数

$orderby

(string)
(Required)
Order by clause to be validated.


返回值

(string|false) Returns $orderby if valid, false otherwise.


源代码

File: wp-includes/formatting.php

function sanitize_sql_orderby( $orderby ) {
	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 ) ) {
		return $orderby;
	}
	return false;
}

更新日志

Version 描述
2.5.1 Introduced.

User Contributed Notes

上一篇:sanitize_post_field()

下一篇:sanitize_term()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!