子比主题美化-添加用户封禁功能小黑屋模块

美化教程6个月前发布 忆余函
625 0 0

由于网站站的用户越来越多,有些用户真的没有一点素质,本站大部份资源都是免费分享的,就设置的隐藏内容评论后显示,但有些用户在评论区肆无忌惮,更有些甚至直接说脏话、谩骂等,故添加了wordpress的用户封禁小黑屋功能,在此记录添加小黑屋功能的方法,方便以后查看。

小黑屋单独页面

子比主题美化-添加用户封禁功能小黑屋模块

侧边栏显示效果

子比主题美化-添加用户封禁功能小黑屋模块

添加教程
在主题目录下新建一个xy_block.php文件,我用的是子比主题,文件路径为:网站->wp-content->themes->zibll

把下面代码复制到xy_block.php文件中

<?php

add_action(‘widgets_init’, ‘widget_block_top’);
function widget_block_top()
{
register_widget(‘widget_ui_block’);
}

/////用户列表—–
class widget_ui_block extends WP_Widget
{
public function __construct()
{
$widget = array(
‘w_id’ => ‘widget_ui_block’,
‘w_name’ => _name(‘用户封禁情况’),
‘classname’ => ”,
‘description’ => ‘显示网站用户被封禁情况,建议侧边栏显示。’,
);
parent::__construct($widget[‘w_id’], $widget[‘w_name’], $widget);
}
public function widget($args, $instance)
{
extract($args);
echo “<style>
.font-hidden{overflow: hidden;white-space: nowrap;text-overflow: ellipsis;}
.xy_tc_mb-5{text-align:center;margin-bottom: -5px;}
.xy-widget-title {position: relative;padding: 0 0 14px 20px !important;margin-top: 5px;border-bottom: 1px solid #f5f6f7;font-size: 16px;font-weight: 600;color: #18191a;width: 100%;}
.xy-widget-title:after {left: 12px !important;}
.xy-widget-title:before, .xy-widget-title:after {position: absolute;transform: skewX(-15deg);content: ”;width: 3px;height: 16px;background: var(–theme-color);top: 0;left: 4px;bottom: 10%;transition: .4s;}
</style>”;
$defaults = array(
‘title’ => ”,
‘mini_title’ => ”,
‘more_but’ => ‘<i class=”fa fa-angle-right fa-fw”></i>更多’,
‘more_but_url’ => ”,
‘in_affix’ => ”,
‘include’ => ”,
‘exclude’ => ”,
‘hide_box’ => false,
‘number’ => 10,
‘orderby’ => ‘block’,
‘order’ => ‘DESC’,
);
$instance = wp_parse_args((array) $instance, $defaults);
$mini_title = $instance[‘mini_title’];
if ($mini_title) {
$mini_title = ‘<small class=”ml10″>’ . $mini_title . ‘</small>’;
}
$title = $instance[‘title’];
$more_but = ”;
if ($instance[‘more_but’] && $instance[‘more_but_url’]) {
$more_but = ‘<div class=”pull-right em09 mt3″><a href=”‘ . $instance[‘more_but_url’] . ‘” class=”muted-2-color”>’ . $instance[‘more_but’] . ‘</a></div>’;
}
$mini_title .= $more_but;
/*if ($title) {
$title = ‘<div class=”box-body notop”><div class=”title-theme”>’ . $title . $mini_title . ‘</div></div>’;
}*/
$in_affix = $instance[‘in_affix’] ? ‘ data-affix=”true”‘ : ”;

$class = !$instance[‘hide_box’] ? ‘ zib-widget’ : ”;
echo ‘<div’ . $in_affix . ‘ class=”theme-box”>’;

echo ‘<div class=”user_lists’ . $class . ‘”>’;
$shu = $instance[‘number’];
$orderby = $instance[‘orderby’];
$isorderby = ‘拉黑名单’;
$order = $instance[‘order’];
global $wpdb;
$used = $wpdb->get_results(“SELECT meta_value,user_id,meta_key FROM {$wpdb->usermeta} WHERE meta_key=’$orderby’ AND meta_value !=’0′ ORDER BY user_id $order LIMIT $shu”);

if ($title) {
if($instance[‘mini_title’]){
$xbt = ‘<small class=”ml10″>’.$instance[‘mini_title’].'</small>’;
}
echo ‘<h2 class=”xy-widget-title font-hidden”>’.$instance[‘title’].”.$xbt.'</h2>’;
}

foreach ($used as $k){
$user = zib_get_user_name_link($k->user_id);
$is_ban = zib_get_user_ban_info($k->user_id);
$userimg = zib_get_avatar_box($k->user_id, ‘avatar-img forum-avatar’);

$time = $is_ban[‘time’];
$datetime = date(“jS H:i”,strtotime(“$time”));;

$html = ‘<div class=”posts-mini border-bottom relative “>’;
$html .= $userimg;
$html .='<div class=”posts-mini-con em09 ml10 flex xx jsb”> <p class=”flex jsb”>’;
$html .= ‘<span class=”flex1 flex”><name class=”inflex ac relative-h”><a href=”‘ . zib_get_user_home_url($k->user_id) . ‘”>’ . $user . ‘</a></name><span class=”flex0 icon-spot muted-3-color” title=”封禁时间:’ . ($is_ban[‘banned_time’] ? $is_ban[‘banned_time’] : ‘永久’) . ‘”>’ . $datetime. ‘</span></p>’;
$html .= ‘<div class=”flex jsb muted-2-color font-hidden”>’.$is_ban[‘reason’].'</div></div> ‘;
$html .= ‘<div class=”flex jsb xx text-right flex0 ml10″><div class=”text-right em5″><span class=”badge pull-right cursor” title=”封禁状态”>’ . (2 == $is_ban[‘type’] ? ‘禁封中’ : ‘小黑屋’) . ‘</span></div></div></div>’;
echo $html;
}
if($used){
echo ‘<div class=”mt10 xy_tc_mb-5″><a href=”‘.$instance[‘more_but_url’].'” class=”muted-2-color c-blue”>’.$instance[‘more_but’].'</a></div>’;
}else{
echo zib_get_ajax_null(‘暂无’.$instance[‘title’].’成员’, 0);
}
echo ‘</div></div>’;
}

public function form($instance)
{
$defaults = array(
‘title’ => ”,
‘mini_title’ => ”,
‘more_but’ => ‘<i class=”fa fa-angle-right fa-fw”></i>更多’,
‘more_but_url’ => ”,
‘in_affix’ => ”,
‘include’ => ”,
‘exclude’ => ”,
‘number’ => 10,
‘hide_box’ => ”,
‘orderby’ => ‘points’,
‘order’ => ‘DESC’,
);

$instance = wp_parse_args((array) $instance, $defaults);

$page_input[] = array(
‘name’ => __(‘标题:’, ‘zib_language’),
‘id’ => $this->get_field_name(‘title’),
‘std’ => $instance[‘title’],
‘style’ => ‘margin: 10px auto;’,
‘type’ => ‘text’,
);
$page_input[] = array(
‘name’ => __(‘副标题:’, ‘zib_language’),
‘id’ => $this->get_field_name(‘mini_title’),
‘std’ => $instance[‘mini_title’],
‘style’ => ‘margin: 10px auto;’,
‘type’ => ‘text’,
);
$page_input[] = array(
‘name’ => __(‘跳转页面->文案:’, ‘zib_language’),
‘id’ => $this->get_field_name(‘more_but’),
‘std’ => $instance[‘more_but’],
‘style’ => ‘margin: 10px auto;’,
‘type’ => ‘text’,
);
$page_input[] = array(
‘name’ => __(‘跳转页面->链接:’, ‘zib_language’),
‘id’ => $this->get_field_name(‘more_but_url’),
‘std’ => $instance[‘more_but_url’],
‘desc’ => ‘设置为任意链接’,
‘style’ => ‘margin: 10px auto;’,
‘type’ => ‘text’,
);
$page_input[] = array(
// ‘name’ => __(‘显示背景盒子’, ‘zib_language’),
‘id’ => $this->get_field_name(‘hide_box’),
‘std’ => $instance[‘hide_box’],
‘desc’ => ‘不显示背景盒子’,
‘style’ => ‘margin: 10px auto;’,
‘type’ => ‘checkbox’,
);

echo zib_edit_input_construct($page_input);
?>

<p>
<label>
<input style=”vertical-align:-3px;margin-right:4px;” class=”checkbox” type=”checkbox” <?php checked($instance[‘in_affix’], ‘on’);?> id=”<?php echo $this->get_field_id(‘in_affix’); ?>” name=”<?php echo $this->get_field_name(‘in_affix’); ?>”> 侧栏随动(仅在侧边栏有效)
</label>
</p>
<p>
<label>
显示数目:
<input style=”width:100%;” id=”<?php echo $this->get_field_id(‘number’);
?>” name=”<?php echo $this->get_field_name(‘number’);
?>” type=”number” value=”<?php echo $instance[‘number’];
?>” size=”24″ />
</label>
</p>
<p>
<label>
显示类型:
<select style=”width:100%;” id=”<?php echo $this->get_field_id(‘orderby’);
?>” name=”<?php echo $this->get_field_name(‘orderby’);
?>”>
<option value=”banned” <?php selected(‘banned’, $instance[‘orderby’]);
?>>黑名单</option>
</select>
</label>
</p>
<p>
<label>
排序顺序:
<select style=”width:100%;” id=”<?php echo $this->get_field_id(‘order’);
?>” name=”<?php echo $this->get_field_name(‘order’);
?>”>
<option value=”ASC” <?php selected(‘ASC’, $instance[‘order’]);
?>>升序</option>
<option value=”DESC” <?php selected(‘DESC’, $instance[‘order’]);
?>>降序</option>
</select>
</label>
</p>

<?php
}
}

在主题的pages目录里新建block_banned.php文件,文件路径例如:网站->wp-content->themes->zibll->pages

<?php
/**
* Template name: 用户封禁
* Description: block page
*/
get_header();

global $wpdb;
$total = $wpdb->get_var( “SELECT COUNT(`meta_value`) FROM $wpdb->usermeta WHERE meta_key=’banned’ AND meta_value !=’0′” );

function block_banned(){
$instance = wp_parse_args((array) $instance, $defaults);
global $wpdb;

//获取分页数据 :每页显示的数量 默认为50
$limit = 20;
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;

//计算每一页第一条记录的显示偏移量
//偏移量 = (页码 -1) \* 每页的显示数量

$offset = ( $paged – 1 ) * $limit;
$total = $wpdb->get_var( “SELECT COUNT(`meta_value`) FROM $wpdb->usermeta WHERE meta_key=’banned’ AND meta_value !=’0′” );
$pages = ceil( $total / $limit );

//调用
$banned = $wpdb->get_results(“SELECT meta_value,user_id,meta_key FROM {$wpdb->usermeta} WHERE meta_key=’banned’ AND meta_value !=’0′ ORDER BY user_id DESC LIMIT $limit OFFSET {$offset}”);

$html = ‘
<div class=”zib-widget”>
<div class=”xypro_describe”>
<div class=”xypro_describe_title”>
封禁列表(’.$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>’;
$html .= ‘ <tbody class=”link-list”>’;

foreach ($banned as $k => $v){
$is_ban = zib_get_user_ban_info($v->user_id);
$name = zib_get_user_name_link($v->user_id);
$time = strtotime($is_ban[‘banned_time’]) – strtotime($is_ban[‘time’]);
$time = $time / 86400 .’天’;
$no_appeal = !empty($is_ban[‘no_appeal’]); //禁止申诉 不能申诉
if($no_appeal){
$no_appeal = ‘(不可申诉)’;
}else{
$no_appeal = ‘(可申诉)’;
}

$html .= ‘<tr class=”yq_link”>
<td>’.$name.'</td>
<td>’.$is_ban[‘time’].'</td>
<td>’.(2 == $is_ban[‘type’] ? ‘禁封中’ : ‘小黑屋’) .'</td>
<td>’.($is_ban[‘banned_time’] ? $time : ‘永久’) .'<span style=”color:var(–theme-color);”>’.$no_appeal.'</span></td>
<td>’.$is_ban[‘reason’] .'</td>
<td>’.$is_ban[‘desc’].'</td>
</tr>’;
}

$html .= ‘</tbody></table>’;
$html .= $banned ? xy2_pages($pages,$paged) : ‘<div class=”text-center ajax-item “><img style=”width:280px;opacity: .7;border: none;” src=”‘.ZIB_TEMPLATE_DIRECTORY_URI.’/img/null.svg”><p class=”em09 muted-3-color separator”>暂无封禁用户</p></div>’;
$html .= ‘</div></div></div>’;
return $html;
}
/**
* 数字分页函数
* 因为wordpress默认仅仅提供简单分页
* 所以要实现数字分页,需要自定义函数
*/
function xy2_pages($max_page,$paged) {
$html = ”;
$html.= ‘<style>
.pagination{margin:0;text-align:center;font-size:12px;display:block;border-radius:0}
.excerpts .pagination{margin-bottom: 10px;}
.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 > li > a:hover,.pagination ul > li > a:focus{opacity:1}
.pagination ul > .active > a,.pagination ul > .active > span{background-color:#000;color:#fff}
.pagination ul > .active > a,.pagination ul > .active > span{cursor:default}
.pagination ul > li > span,.pagination ul > .disabled > span,.pagination ul > .disabled > a,.pagination ul > .disabled > a:hover,.pagination ul > .disabled > a:focus{color:#999999;background-color:transparent;cursor:default}
</style>’;

$p = 2;
if ( $max_page == 1 ) {
return;
}
$html.= ‘<span class=”pagination”><ul>’;
$paged = !empty( $paged ) ? $paged : 1;

if ( $paged > 1 ) {
$html.= ‘<li><a href=”‘.esc_html( get_pagenum_link( 1 ) ).'”>首页</a></li>’;
}

$html.= ‘<li class=”prev-page”>’;
$html.= ‘</li>’;
for ( $i = $paged – $p; $i <= $paged + $p; $i++ ) {
if ( $i > 0 && $i <= $max_page ) {
if($i == $paged){
$html.= “<li class=\”active\”><span>{$i}</span></li>”;
}else{
$html.= ‘<li><a href=”‘.esc_html( get_pagenum_link( $i ) ).'”>’. $i .'</a></li>’;
}
}
}
$html.= ‘<li class=”next-page”>’;
$html.= ‘</li>’;
$html.= ‘<li><a href=”‘.esc_html( get_pagenum_link( $max_page ) ).'”>尾页</a></li>’;
//$html.= ‘<li><span>共 ‘.$max_page.’ 页</span></li>’;
$html.= ‘</ul></span>’;
return $html;
}
?>
<style>
.wp-posts-content p{margin: 0 0 10px;}
.xypro_describe {position: relative;border: 1px dashed #dcdfe6;line-height: 26px;margin-top: 10px;}
.xypro_describe_title {position: absolute;top: 0;left: 8px;-webkit-transform: translateY(-50%);transform: translateY(-50%);background:var(–main-bg-color);padding: 0 5px;font-weight: 500;max-width: 200px;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: scroll;}
.yq{max-width: 100%;table-layout: fixed;color: #909399;margin-bottom: 18px;border-top: 1px solid #ebeef5;border-left: 1px solid #ebeef5;}
#xy_hide::-webkit-scrollbar {
display: none;
}
.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;}
@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 $total ? $total : 0;?>个 数据截止日期:<?php echo date(“Y-m-d”, time()+8*60*60);?></p>
</div>
<?php echo block_banned();?>
<div style=”text-align:center;color:var(–theme-color);”>
– – – 善语结善缘,恶语伤人心 – – –
</div>
</div>

</article>
</div>
</div>
</div>
</main>
<?php
get_footer();

在主题下的functions.php文件中添加如下代码:

if (file_exists(get_theme_file_path(‘/xy_block.php’))) {
require_once get_theme_file_path(‘/xy_block.php’);
}

然后在网站后台新建页面,在默认模板里找到 用户封禁 然后发布

小工具找到 Zibll用户封禁情况 然后填写信息 发布(这里推荐放在侧边栏)

© 版权声明

相关文章

暂无评论

暂无评论...

欢迎进入官方群聊(关注最新消息)

QQ群514518527 点击进入  


登录即可开启个人书签等新功能! 点击登录

如果网站对您有帮助的话,希望您能把快导航网分享给身边朋友,感激不尽!


(登录后有效期内不再显示)

点击下方关闭此窗口