delete_user_setting

函数
delete_user_setting ( $names )
参数
  • (string) $names The name or array of names of the setting to be deleted.
    Required:
返回值
  • (bool|null) True if deleted successfully, false otherwise. Null if the current user is not a member of the site.
定义位置
相关方法
delete_all_user_settingsget_user_settingset_user_settingdelete_user_optiondelete_user_meta
引入
2.7.0
弃用
-

delete_user_setting: 这个函数删除一个用户的设置。设置名称和用户ID应被指定为参数。

删除用户界面设置。

删除设置会将它们重置为默认值。

这个函数必须在任何输出开始之前使用,因为它调用`setcookie()`。

function delete_user_setting( $names ) {
	if ( headers_sent() ) {
		return false;
	}

	$all_user_settings = get_all_user_settings();
	$names             = (array) $names;
	$deleted           = false;

	foreach ( $names as $name ) {
		if ( isset( $all_user_settings[ $name ] ) ) {
			unset( $all_user_settings[ $name ] );
			$deleted = true;
		}
	}

	if ( $deleted ) {
		return wp_set_all_user_settings( $all_user_settings );
	}

	return false;
}

常见问题

FAQs
查看更多 >