sanitize_user_object

函数
sanitize_user_object ( $user, $context = 'display' )
参数
  • (object|array) $user The user object or array.
    Required:
  • (string) $context Optional. How to sanitize user fields. Default 'display'.
    Required:
    Default: 'display'
返回值
  • (object|array) The now sanitized user object or array (will be the same type as $user).
定义位置
相关方法
sanitize_usersanitize_user_fieldrest_sanitize_objectsanitize_urlsanitize_term_field
引入
2.3.0
弃用
3.3.0

sanitize_user_object: 这是一个WordPress的函数,它对一个用户对象进行净化,并返回一个经过净化的副本。它被用来创建一个用户对象的安全副本,而不修改原始对象: 这个函数需要一个参数,就是要被净化的用户对象。

对每个用户字段进行净化。

如果上下文是”原始”,那么用户对象或数组将得到最小的int字段的净化处理。

function sanitize_user_object($user, $context = 'display') {
	_deprecated_function( __FUNCTION__, '3.3.0' );

	if ( is_object($user) ) {
		if ( !isset($user->ID) )
			$user->ID = 0;
		if ( ! ( $user instanceof WP_User ) ) {
			$vars = get_object_vars($user);
			foreach ( array_keys($vars) as $field ) {
				if ( is_string($user->$field) || is_numeric($user->$field) )
					$user->$field = sanitize_user_field($field, $user->$field, $user->ID, $context);
			}
		}
		$user->filter = $context;
	} else {
		if ( !isset($user['ID']) )
			$user['ID'] = 0;
		foreach ( array_keys($user) as $field )
			$user[$field] = sanitize_user_field($field, $user[$field], $user['ID'], $context);
		$user['filter'] = $context;
	}

	return $user;
}

常见问题

FAQs
查看更多 >