之前有人分享,不过好像有bug。找ai修好了,展示页面的表单还是只适配电脑端哦。
部署教程
/wp-content/themes/zibll/pages目录下创建block_banned.php文件把以下代码放进去
<?php
/**
* Template Name: XY-用户封禁
* Description: block page
*/
get_header();
global $wpdb;
$total = (int) $wpdb->get_var(
"SELECT COUNT(user_id) FROM {$wpdb->usermeta}
WHERE meta_key = 'banned'
AND meta_value IN ('1', '2')"
);
if (!function_exists('xy_block_banned_get_paged')) {
function xy_block_banned_get_paged()
{
$paged = (int) get_query_var('paged');
$page = (int) get_query_var('page');
return max(1, $paged, $page);
}
}
if (!function_exists('xy_block_banned')) {
function xy_block_banned()
{
global $wpdb;
$limit = 20;
$paged = xy_block_banned_get_paged();
$offset = ($paged - 1) * $limit;
$total = (int) $wpdb->get_var(
"SELECT COUNT(user_id) FROM {$wpdb->usermeta}
WHERE meta_key = 'banned'
AND meta_value IN ('1', '2')"
);
$pages = $total > 0 ? (int) ceil($total / $limit) : 1;
$banned = $wpdb->get_results(
$wpdb->prepare(
"SELECT user_id, meta_key, meta_value FROM {$wpdb->usermeta}
WHERE meta_key = %s
AND meta_value IN ('1', '2')
ORDER BY user_id DESC
LIMIT %d OFFSET %d",
'banned',
$limit,
$offset
)
);
ob_start();
?>
<div class="zib-widget">
<div class="xypro_describe">
<div class="xypro_describe_title">
封禁列表:<?php echo esc_html($total); ?> 名成员
</div>
<div id="xy_hide" class="xypro_describe_content xy_height_hide">
<table class="yq">
<thead>
<tr>
<th align="center" width="5%"><strong>用户名</strong></th>
<th align="center" width="5%"><strong>封禁时间</strong></th>
<th align="center" width="5%"><strong>封禁类型</strong></th>
<th align="center" width="5%"><strong>封禁时长</strong></th>
<th align="center" width="5%"><strong>封禁原因</strong></th>
<th align="center" width="5%"><strong>备注</strong></th>
</tr>
</thead>
<tbody class="link-list">
<?php
if (!empty($banned)) {
foreach ($banned as $ban_user) {
$user_id = isset($ban_user->user_id) ? (int) $ban_user->user_id : 0;
if (!$user_id || !function_exists('zib_get_user_ban_info')) {
continue;
}
$is_ban = zib_get_user_ban_info($user_id);
$is_ban = is_array($is_ban) ? $is_ban : array();
$name = function_exists('zib_get_user_name_link')
? zib_get_user_name_link($user_id)
: esc_html(get_the_author_meta('display_name', $user_id));
$start_time = !empty($is_ban['time']) ? $is_ban['time'] : '';
$end_time = !empty($is_ban['banned_time']) ? $is_ban['banned_time'] : '';
$duration = '永久';
if ($start_time && $end_time) {
$start_timestamp = strtotime($start_time);
$end_timestamp = strtotime($end_time);
if ($start_timestamp && $end_timestamp && $end_timestamp > $start_timestamp) {
$duration = ceil(($end_timestamp - $start_timestamp) / 86400) . '天';
}
}
$no_appeal = !empty($is_ban['no_appeal']) ? '(不可申诉)' : '(可申诉)';
$type = isset($is_ban['type']) && (int) $is_ban['type'] === 2 ? '封号' : '小黑屋';
$reason = !empty($is_ban['reason']) ? $is_ban['reason'] : '';
$desc = !empty($is_ban['desc']) ? $is_ban['desc'] : '';
?>
<tr class="yq_link">
<td><?php echo $name; ?></td>
<td><?php echo esc_html($start_time); ?></td>
<td><?php echo esc_html($type); ?></td>
<td>
<?php echo esc_html($duration); ?>
<span style="color:var(--theme-color);"><?php echo esc_html($no_appeal); ?></span>
</td>
<td><?php echo esc_html($reason); ?></td>
<td><?php echo esc_html($desc); ?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<?php
if (!empty($banned)) {
echo xy2_pages($pages, $paged);
} else {
echo '<div class="text-center ajax-item"><img style="width:280px;opacity:.7;border:none;" src="' . esc_url(ZIB_TEMPLATE_DIRECTORY_URI . '/img/null.svg') . '"><p class="em09 muted-3-color separator">暂无封禁用户</p></div>';
}
?>
</div>
</div>
</div>
<?php
return ob_get_clean();
}
}
if (!function_exists('xy2_pages')) {
function xy2_pages($max_page, $paged)
{
$max_page = (int) $max_page;
$paged = max(1, (int) $paged);
if ($max_page <= 1) {
return '';
}
$p = 2;
ob_start();
?>
<span class="pagination">
<ul>
<?php if ($paged > 1) : ?>
<li><a href="<?php echo esc_url(get_pagenum_link(1)); ?>">首页</a></li>
<?php endif; ?>
<?php
for ($i = $paged - $p; $i <= $paged + $p; $i++) {
if ($i > 0 && $i <= $max_page) {
if ($i === $paged) {
echo '<li class="active"><span>' . esc_html($i) . '</span></li>';
} else {
echo '<li><a href="' . esc_url(get_pagenum_link($i)) . '">' . esc_html($i) . '</a></li>';
}
}
}
?>
<?php if ($paged < $max_page) : ?>
<li><a href="<?php echo esc_url(get_pagenum_link($max_page)); ?>">尾页</a></li>
<?php endif; ?>
</ul>
</span>
<?php
return ob_get_clean();
}
}
?>
<style>
.xypro_describe{position:relative;border:1px dashed #dcdfe6;line-height:26px;margin-top:10px}
.xypro_describe_title{position:absolute;top:0;left:8px;transform:translateY(-50%);background:var(--main-bg-color);padding:0 5px;font-weight:500;max-width:220px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.xypro_describe_content{color:#606266;padding:18px 15px 0;width:100%;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;overflow-x:auto}
#xy_hide::-webkit-scrollbar{display:none}
.yq{max-width:100%;table-layout:fixed;color:#909399;margin-bottom:18px;border-top:1px solid #ebeef5;border-left:1px solid #ebeef5}
.yq thead th{font-weight:500;background:#ebeef5;text-align:center;padding:8px;border-bottom:1px solid #ebeef5;border-right:1px solid #ebeef5}
.yq_link td{text-align:center;padding:8px;border-bottom:1px solid #ebeef5;border-right:1px solid #ebeef5;text-overflow:ellipsis;white-space:nowrap;overflow:hidden}
.pagination{margin:0;text-align:center;font-size:12px;display:block;border-radius:0}
.pagination ul{display:inline-block!important;margin-left:0;margin-bottom:0;padding:0}
.pagination ul>li{display:inline}
.pagination ul>li>a,.pagination ul>li>span{margin:0 2px;padding:8px 12px;background-color:#ddd;color:#666;border-radius:2px;opacity:.88}
.pagination ul>.active>span{background-color:#000;color:#fff}
@media screen and (max-width:700px){.yq{width:600px!important}}
</style>
<main class="container">
<div class="content-wrap">
<div class="content-layout xy-article">
<div class="nopw-sm box-body theme-box radius8 main-bg main-shadow">
<article class="article wp-posts-content">
<div class="wp-block-zibllblock-quote">
<div class="quote_q" data-color="#fb2121" style="--quote-color:#fb2121">
<i class="fa fa-quote-left"></i>
<p>本站严禁发布违法违规以及恶意评论等内容,如有违反,将进行封禁处理,以下是本站封禁用户列表,请大家珍惜自己的账号。</p>
</div>
</div>
<div style="padding:0 20px;margin-bottom:20px;">
<p><strong>封禁类型说明:</strong></p>
<p>1. 小黑屋:用户被拉入小黑屋后,将失去发布、评论、下载等部分操作权限。</p>
<p>2. 封号:用户将不能登录,并失去全部权限。</p>
<p class="mb10-sm" style="color:#fb2121;">
累计封禁用户:<?php echo esc_html($total); ?> 个,
数据截止日期:<?php echo esc_html(current_time('Y-m-d')); ?>
</p>
</div>
<?php echo xy_block_banned(); ?>
<div style="text-align:center;color:var(--theme-color);">
- - - 善语结善缘,恶语伤人心 - - -
</div>
</article>
</div>
</div>
</div>
</main>
<?php get_footer(); ?>
2.放在主题根目录吓得func文件中
// 注册:XY-封禁用户展示小工具
add_action('widgets_init', 'xy_register_banned_users_widget');
function xy_register_banned_users_widget()
{
if (class_exists('WP_Widget')) {
register_widget('XY_Banned_Users_Widget');
}
}
if (!class_exists('XY_Banned_Users_Widget')) {
class XY_Banned_Users_Widget extends WP_Widget
{
public function __construct()
{
parent::__construct(
'xy_banned_users_widget',
'XY-封禁用户展示',
array(
'description' => '在侧边栏展示当前被封禁或小黑屋中的用户',
)
);
}
public function widget($args, $instance)
{
global $wpdb;
$title = !empty($instance['title']) ? $instance['title'] : '封禁用户';
$limit = !empty($instance['limit']) ? absint($instance['limit']) : 6;
$show_more = !empty($instance['show_more']);
$more_url = !empty($instance['more_url']) ? esc_url($instance['more_url']) : '';
if ($limit < 1) {
$limit = 6;
}
$total = (int) $wpdb->get_var(
"SELECT COUNT(user_id) FROM {$wpdb->usermeta}
WHERE meta_key = 'banned'
AND meta_value IN ('1', '2')"
);
$banned_users = $wpdb->get_results(
$wpdb->prepare(
"SELECT user_id, meta_value FROM {$wpdb->usermeta}
WHERE meta_key = %s
AND meta_value IN ('1', '2')
ORDER BY user_id DESC
LIMIT %d",
'banned',
$limit
)
);
echo $args['before_widget'];
echo $args['before_title'] . esc_html($title) . $args['after_title'];
?>
<div class="xy-ban-widget">
<div class="xy-ban-widget-count">
当前封禁用户:<?php echo esc_html($total); ?> 个
</div>
<?php if (!empty($banned_users)) : ?>
<ul class="xy-ban-widget-list">
<?php foreach ($banned_users as $ban_user) :
$user_id = isset($ban_user->user_id) ? (int) $ban_user->user_id : 0;
if (!$user_id) {
continue;
}
$ban_info = function_exists('zib_get_user_ban_info') ? zib_get_user_ban_info($user_id) : array();
$ban_info = is_array($ban_info) ? $ban_info : array();
$type = !empty($ban_info['type']) && (int) $ban_info['type'] === 2 ? '封号' : '小黑屋';
$reason = !empty($ban_info['reason']) ? $ban_info['reason'] : '违规处理';
$end_time = !empty($ban_info['banned_time']) ? $ban_info['banned_time'] : '永久';
$user_name = get_the_author_meta('display_name', $user_id);
$user_name = $user_name ? $user_name : '用户 #' . $user_id;
$user_url = get_author_posts_url($user_id);
?>
<li class="xy-ban-widget-item">
<a class="xy-ban-widget-avatar" href="<?php echo esc_url($user_url); ?>">
<?php echo get_avatar($user_id, 36); ?>
</a>
<div class="xy-ban-widget-info">
<div class="xy-ban-widget-name">
<a href="<?php echo esc_url($user_url); ?>">
<?php echo esc_html($user_name); ?>
</a>
<span><?php echo esc_html($type); ?></span>
</div>
<div class="xy-ban-widget-meta">
<?php echo esc_html($reason); ?> / <?php echo esc_html($end_time); ?>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php if ($show_more && $more_url) : ?>
<a class="xy-ban-widget-more" href="<?php echo esc_url($more_url); ?>">
查看完整封禁列表
</a>
<?php endif; ?>
<?php else : ?>
<div class="xy-ban-widget-empty">
暂无封禁用户
</div>
<?php endif; ?>
</div>
<style>
.xy-ban-widget-count{font-size:13px;color:var(--muted-color);margin-bottom:10px}
.xy-ban-widget-list{list-style:none;margin:0;padding:0}
.xy-ban-widget-item{display:flex;align-items:center;gap:10px;padding:8px 0;border-bottom:1px solid var(--main-border-color)}
.xy-ban-widget-item:last-child{border-bottom:0}
.xy-ban-widget-avatar img{width:36px;height:36px;border-radius:50%;display:block}
.xy-ban-widget-info{min-width:0;flex:1}
.xy-ban-widget-name{display:flex;align-items:center;gap:6px;font-size:13px;line-height:1.4}
.xy-ban-widget-name a{max-width:110px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.xy-ban-widget-name span{font-size:12px;color:#fff;background:#f56c6c;border-radius:3px;padding:1px 5px}
.xy-ban-widget-meta{font-size:12px;color:var(--muted-2-color);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-top:2px}
.xy-ban-widget-empty{text-align:center;color:var(--muted-2-color);font-size:13px;padding:12px 0}
.xy-ban-widget-more{display:block;text-align:center;margin-top:10px;font-size:13px}
</style>
<?php
echo $args['after_widget'];
}
public function form($instance)
{
$title = !empty($instance['title']) ? $instance['title'] : '封禁用户';
$limit = !empty($instance['limit']) ? absint($instance['limit']) : 6;
$show_more = !empty($instance['show_more']);
$more_url = !empty($instance['more_url']) ? esc_url($instance['more_url']) : '';
?>
<p>
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>">标题:</label>
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>">
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('limit')); ?>">显示数量:</label>
<input class="tiny-text" id="<?php echo esc_attr($this->get_field_id('limit')); ?>" name="<?php echo esc_attr($this->get_field_name('limit')); ?>" type="number" min="1" value="<?php echo esc_attr($limit); ?>">
</p>
<p>
<input class="checkbox" id="<?php echo esc_attr($this->get_field_id('show_more')); ?>" name="<?php echo esc_attr($this->get_field_name('show_more')); ?>" type="checkbox" value="1" <?php checked($show_more); ?>>
<label for="<?php echo esc_attr($this->get_field_id('show_more')); ?>">显示“查看更多”按钮</label>
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('more_url')); ?>">封禁列表页面链接:</label>
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('more_url')); ?>" name="<?php echo esc_attr($this->get_field_name('more_url')); ?>" type="url" value="<?php echo esc_attr($more_url); ?>">
</p>
<?php
}
public function update($new_instance, $old_instance)
{
$instance = array();
$instance['title'] = !empty($new_instance['title']) ? sanitize_text_field($new_instance['title']) : '封禁用户';
$instance['limit'] = !empty($new_instance['limit']) ? absint($new_instance['limit']) : 6;
$instance['show_more'] = !empty($new_instance['show_more']) ? 1 : 0;
$instance['more_url'] = !empty($new_instance['more_url']) ? esc_url_raw($new_instance['more_url']) : '';
return $instance;
}
}
}
使用教程:
后台新建一个页面侧边栏页面模版选择用户封禁
预览图
小工具

封禁页面展示



没有回复内容