From 16e28a5c41d775a9fbaae8dbc80f0c3ef89a2d65 Mon Sep 17 00:00:00 2001
From: Roman Kelesidis
Date: Wed, 20 Aug 2025 13:13:26 +0300
Subject: [PATCH] feat: Allow setting custom ban reason when banning users
(#2094)
* feat: Allow setting custom ban reason when banning users
* Updated
* Update usercp_viewprofile.tpl
* Update usercp_viewprofile.tpl
---
admin/admin_user_ban.php | 6 +++++-
library/includes/ucp/viewprofile.php | 2 +-
styles/templates/admin/admin_user_ban.tpl | 4 ++++
styles/templates/default/usercp_viewprofile.tpl | 13 ++++++++++---
viewtopic.php | 5 +----
5 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/admin/admin_user_ban.php b/admin/admin_user_ban.php
index af4c31b81..eb69da229 100644
--- a/admin/admin_user_ban.php
+++ b/admin/admin_user_ban.php
@@ -29,7 +29,11 @@ if ($submit) {
}
if (!getBanInfo((int)$this_userdata['user_id'])) {
- $sql = 'INSERT INTO ' . BB_BANLIST . ' (ban_userid) VALUES (' . $this_userdata['user_id'] . ')';
+ $ban_reason = '';
+ if (!empty($_POST['ban_reason'])) {
+ $ban_reason = trim($_POST['ban_reason']);
+ }
+ $sql = 'INSERT INTO ' . BB_BANLIST . ' (ban_userid, ban_reason) VALUES (' . $this_userdata['user_id'] . ', "' . DB()->escape($ban_reason) . '")';
if (!DB()->sql_query($sql)) {
bb_die('Could not insert ban_userid info into database');
}
diff --git a/library/includes/ucp/viewprofile.php b/library/includes/ucp/viewprofile.php
index 7dbc44541..7f97dc118 100644
--- a/library/includes/ucp/viewprofile.php
+++ b/library/includes/ucp/viewprofile.php
@@ -83,7 +83,7 @@ if ($bb_cfg['ratio_null_enabled'] && $btu = get_bt_userdata($profiledata['user_i
if ($banInfo = getBanInfo((int)$profiledata['user_id'])) {
$template->assign_block_vars('ban', [
'IS_BANNED' => true,
- 'BAN_REASON' => $banInfo['ban_reason']
+ 'BAN_REASON' => IS_ADMIN ? $banInfo['ban_reason'] : '',
]);
}
diff --git a/styles/templates/admin/admin_user_ban.tpl b/styles/templates/admin/admin_user_ban.tpl
index 65b6e9284..0483c0613 100644
--- a/styles/templates/admin/admin_user_ban.tpl
+++ b/styles/templates/admin/admin_user_ban.tpl
@@ -13,6 +13,10 @@
{L_USERNAME}: |
{S_HIDDEN_FIELDS} |
+
+ {L_REASON}: |
+ |
+
{L_UNBAN_USERNAME} |
diff --git a/styles/templates/default/usercp_viewprofile.tpl b/styles/templates/default/usercp_viewprofile.tpl
index d4a11e354..162fa42d4 100644
--- a/styles/templates/default/usercp_viewprofile.tpl
+++ b/styles/templates/default/usercp_viewprofile.tpl
@@ -229,6 +229,16 @@ ajax.callback.group_membership = function(data) {
{RANK_IMAGE}
+
+
+
+ {L_BANNED}
+
+
+ {L_REASON}: {ban.BAN_REASON}
+
+
+
{BIRTHDAY_ICON}
{L_CONTACT} {USERNAME}
@@ -300,9 +310,6 @@ ajax.callback.group_membership = function(data) {
{L_USERNAME}: |
{USERNAME}
-
- ({L_BANNED})
-
|
diff --git a/viewtopic.php b/viewtopic.php
index 0ed14fd11..529b25d4a 100644
--- a/viewtopic.php
+++ b/viewtopic.php
@@ -738,10 +738,7 @@ for ($i = 0; $i < $total_posts; $i++) {
// Ban information
if ($banInfo = getBanInfo((int)$poster_id)) {
- $template->assign_block_vars('postrow.ban', [
- 'IS_BANNED' => true,
- 'BAN_REASON' => $banInfo['ban_reason']
- ]);
+ $template->assign_block_vars('postrow.ban', ['IS_BANNED' => true]);
}
if (isset($postrow[$i]['post_attachment']) && $is_auth['auth_download'] && function_exists('display_post_attachments')) {