子比主题V6.0社区思考如何设计一个仅VIP会员,仅认证用户可见的页面

子比主题V6.0社区思考如何设计一个仅VIP会员,仅认证用户可见的页面[WP教程]
  • wordpress子比主题V6.0论坛用户等级权限的二次开发,玩出新花样
    这里推荐购买子比主题:点击前往

前言

作为内测用户,除了提交子比V6.0的相关bug之外。

最近也在做一些二次开发的页面,由于本人的专业是网络安全,因此有很多工具,如Fofa高级查询等等一系列的功能是不能对外开放的,因此就需要对页面的权限进行判断,也就有了本篇文章。

声明

我不是专门做二次开发的,如果代码有所疏漏还希望专家们能够多多指正

效果展示

利用了wordpress子比主题V6.0新的用户等级权限功能,实现仅某个用户组才能阅读某个页面的权限功能。

认证用户组显示界面

子比主题V6.0社区思考如何设计一个仅VIP会员,仅认证用户可见的页面[WP教程]-2

未登录状态下界面

子比主题V6.0社区思考如何设计一个仅VIP会员,仅认证用户可见的页面[WP教程]-3

登录且未认证提示界面

子比主题V6.0社区思考如何设计一个仅VIP会员,仅认证用户可见的页面[WP教程]-4

开发思路

基于页面功能

主要是基于Wordpress的创建页面功能,我们需要在wp-content/themes/zibll/pages文件夹下,新建一个php文件

比方说,我这里建的是fofa.php,模板如下

<?php

/**
 * Template name: FoFa-高级查询
 * Description:   Fofa搜索引擎高级查询
 */

get_header();#需要头部就写,不需要这行就删掉
?>

 <!--这里需要填写你的网页内容-->

<?php
get_footer();

判断未登录用户方法

  • !is_user_logged_in() 表示没有登录的用户
  • zib_get_nocan_info($user_id, $capability, $msg = ”) 该函数主要用来提醒权限不足,第二个是权限能力名称,第三个msg是用来提示用户的,当然我们这里后两者不需要调用,随便填也可以

相关核心代码

    <?php if (!is_user_logged_in()){
    echo '<div class="flex jc" style="min-height:50vh;">';
            echo zib_get_nocan_info($cuid, 'fofa_api', '您都没登陆咋用FOFA高级查询');
            echo '</div>';
    }?>

判断已登录但没有认证的用户方法

  • is_user_logged_in() 表示已经登录的用户
  • !zib_is_user_auth() 表示没有认证的用户

相关核心代码

 <?php if (is_user_logged_in() && !zib_is_user_auth()) { 
            echo '<div class="mb20 wp-posts-content"><div class="hide-post mt6"><div class=""><i class="fa fa-unlock-alt mr6"></i>Fofa高级查询仅对内部人员开放</div><div class="text-center em09 mt20"><p class="separator muted-3-color mb20">以下用户组可查看</p><p><a class="but mm3" href="https://www.iculture.cc/user/auth"><svg class="mr6 em12" aria-hidden="true"><use xlink:href="#icon-user-auth"></use></svg>认证用户</a></p></div></div></div>';
            echo '</div>';
     }?>

判断认证的用户

  • zib_is_user_auth() 表示已经认证的用户

相关核心代码

 <?php if (zib_is_user_auth()) { ?>
 <!--这里填你想给认证用户组展现的内容-->
<?php
} ?>

案例

这里把之前群友分享的抖音等等去水印的页面拿过来,稍作修改便实现了下面的效果

效果展示

  • 未登录状态
子比主题V6.0社区思考如何设计一个仅VIP会员,仅认证用户可见的页面[WP教程]-5
  • 已登录但非VIP1以上的用户提示
子比主题V6.0社区思考如何设计一个仅VIP会员,仅认证用户可见的页面[WP教程]-6
  • VIP1以上的用户
子比主题V6.0社区思考如何设计一个仅VIP会员,仅认证用户可见的页面[WP教程]-7

开发思路

我们需要在原来的代码基础上,进行完善,首先是增加登录判断

                     <?php if (!is_user_logged_in()){
                        echo '<div class="flex jc" style="min-height:50vh;">';
                        echo zib_get_nocan_info($cuid, 'watermark', '您都没登陆就想去水印啊');
                        echo '</div>';
                    
                    }?>

其次,我们需要给登录但不是LV1以上用户,做一个提示

                    <?php if (is_user_logged_in() && zib_get_user_vip_level($user_id)<1){ 
                    echo '<div class="mb20 wp-posts-content"><div class="hide-post mt6"><div class=""><i class="fa fa-unlock-alt mr6"></i>在线去水印功能已隐藏</div><div class="text-center em09 mt20"><p class="separator muted-3-color mb20">以下用户组可使用</p><p><a class="but mm3 pay-vip" vip-level="1" href="javascript:;"><img class="img-icon mr6 em12 ls-is-cached lazyloaded" src="https://www.iculture.cc/wp-content/themes/fancypig/img/vip-1.svg" data-src="https://www.iculture.cc/wp-content/themes/fancypig/img/vip-1.svg" data-toggle="tooltip" title="" alt="披萨会员" data-original-title="披萨会员">披萨会员及以上会员</a></p></div></div></div>';
                    } ?>

最后,对于登录且是LV1以上的用户,我们让这类用户可以使用去水印的功能

  <?php if (is_user_logged_in() && zib_get_user_vip_level($user_id)>=1){ ?>
                    <!---->
                              <div class="inputUrl">
                              <input class="textUrl" type="text" placeholder="请粘贴视频链接" id="input1" class="longurl">
                              <input class="btn sendBtn" type="button" onclick="setValue()" value="解析">
                              </div>
                            </form>
                            <div class="down"></div>
                              <div id="myDiv"></div>
                        </div>
                        <script>
                        function  setValue(){
                        var v =  document.getElementById("input1").value;
                            var xmlhttp;
                            if(window.XMLHttpRequest){
                              xmlhttp=new XMLHttpRequest();
                              }
                            else{
                            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
                            xmlhttp.open("GET","https://tenapi.cn/video?url="+v,false);
                            xmlhttp.send();
                            document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
                           var jsonObj = JSON.parse(xmlhttp.responseText); 
                            $(".down").html('<h4 id="form-title" style="font-weight: 700;">'+jsonObj.title+'</h4><a id="form-cover" href="'+jsonObj.cover+'" target="_blank" download="video">下载封面</a><a id="form-video" href="'+jsonObj.url+'" target="_blank" download="video">下载视频</a><a id="form-music" href="'+jsonObj.music+'" target="_blank" download="video">下载音乐</a>');
                        }
                        </script>
                    </html>
                <!---->
                           <?php
} ?>

项目完整代码

<?php

/**
 * Template name: FancyPig-在线去水印
 * Description:   在线去水印仅对VIP用户开放
 */

// 获取链接列表
get_header();
$header_style = zib_get_page_header_style();
?>
<main class="container">
    <div class="content-wrap">
        <div class="content-layout">
            
            <?php while (have_posts()) : the_post(); ?>
                <?php if ($header_style != 1) {
                    echo zib_get_page_header();
                } ?>
                <div class="box-body theme-box radius8 main-bg main-shadow">
                    <?php if ($header_style == 1) {
                        echo zib_get_page_header();
                    } ?>
                                        <html>
                        <head>
                        <meta charset="utf-8">
                        <meta name="viewport" content="width=device-width, initial-scale=1">
                        <style>
                        .inputUrl{width: 100%; display: flex; justify-content: flex-end; align-items: center; flex-direction: column;} .textUrl{width: 90%; height: 45px; outline: none; padding: 4px 8px; border-radius: 8px; border: 1.5px solid #c0c0c0; outline: none; background: #00000000; font-weight: 700; box-shadow: 0px 0px 2px #eeeeee;} .sendBtn{width: 90%; height: 40px; margin: 15px; border-radius: 8px; background-color:#ff64ac;font-weight: 700;user-select: none;}  .down{text-align: center;} .down a{display: inline-block; padding: 0 1em; margin: 0.5em; height: 2.75em; border: solid 1px #c8cccf; border-radius: 4px; background-color: transparent; color: #414f57!important; text-align: center; text-decoration: none; white-space: nowrap; line-height: 2.75em; font-weight: 700;} #myDiv{color: #0089fff0; overflow-y: hidden; background-color: #f0f1f1fa; margin: 10px; border-radius: 8px; word-wrap: break-word;} #myDiv1{text-align: center;font-weight: 700;padding: 10px;}
                        </style>
                        </head>
                        <!--<div id="wrapper">-->
                            <!--<form method="post">-->
                              <center><h3>抖音/快手/微博小视频去水印功能</h3><center>
                              <div id="myDiv1">
                                <p>
                                  目前支持:抖音/皮皮虾/火山/微视/微博/绿洲/最右/轻视频/instagram/哔哩哔哩/快手/全民小视频/皮皮搞笑
                                  <br>
                                  温馨提示:粘贴视频地址时无需删除文案 但如果视频链接正确但解析失败请删掉文案后重试
                                </p>
                              </div>
                              
                     <?php if (!is_user_logged_in()){
                        echo '<div class="flex jc" style="min-height:50vh;">';
                        echo zib_get_nocan_info($cuid, 'watermark', '您都没登陆就想去水印啊');
                        echo '</div>';
                    
                    }?>
                    <?php if (is_user_logged_in() && zib_get_user_vip_level($user_id)<1){ 
                    echo '<div class="mb20 wp-posts-content"><div class="hide-post mt6"><div class=""><i class="fa fa-unlock-alt mr6"></i>在线去水印功能已隐藏</div><div class="text-center em09 mt20"><p class="separator muted-3-color mb20">以下用户组可使用</p><p><a class="but mm3 pay-vip" vip-level="1" href="javascript:;"><img class="img-icon mr6 em12 ls-is-cached lazyloaded" src="https://www.iculture.cc/wp-content/themes/fancypig/img/vip-1.svg" data-src="https://www.iculture.cc/wp-content/themes/fancypig/img/vip-1.svg" data-toggle="tooltip" title="" alt="披萨会员" data-original-title="披萨会员">披萨会员及以上会员</a></p></div></div></div>';
                    } ?>
                    
                    <?php if (is_user_logged_in() && zib_get_user_vip_level($user_id)>=1){ ?>
                    <!---->
                              <div class="inputUrl">
                              <input class="textUrl" type="text" placeholder="请粘贴视频链接" id="input1" class="longurl">
                              <button class="btn sendBtn" type="button" onclick="setValue()" style="color:#fff">解析</button>
                              </div>
                            </form>
                            <div class="down"></div>
                              <div id="myDiv"></div>
                        </div>
                        <script>
                        function  setValue(){
                        var v =  document.getElementById("input1").value;
                            var xmlhttp;
                            if(window.XMLHttpRequest){
                              xmlhttp=new XMLHttpRequest();
                              }
                            else{
                            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
                            xmlhttp.open("GET","https://tenapi.cn/video?url="+v,false);
                            xmlhttp.send();
                            document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
                           var jsonObj = JSON.parse(xmlhttp.responseText); 
                            $(".down").html('<h4 id="form-title" style="font-weight: 700;">'+jsonObj.title+'</h4><a id="form-cover" href="'+jsonObj.cover+'" target="_blank" download="video">下载封面</a><a id="form-video" href="'+jsonObj.url+'" target="_blank" download="video">下载视频</a><a id="form-music" href="'+jsonObj.music+'" target="_blank" download="video">下载音乐</a>');
                        }
                        
                        function  setValue(){
var data =  document.getElementById("input1").value;
let regex = /http[s]?://[w.]+[w/]*[w.]*??[w=&:-+%]*[/]*/;
var v =  data.match(regex)[0];
console.log(v);
var xmlhttp;
if(window.XMLHttpRequest){
  xmlhttp=new XMLHttpRequest();
  }
else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.open("GET","https://tenapi.cn/video/?url="+v,false);
xmlhttp.send();
var jsonObj = JSON.parse(xmlhttp.responseText); 
console.log(jsonObj);
var code = jsonObj.code;
// if(code == '200'){
//   mdui.snackbar({
//   message: '解析成功'
// });
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
var jsonObj = JSON.parse(xmlhttp.responseText); 
$(".down").html('<h4>'+jsonObj.title+' </h4><a id="form-cover" href="'+jsonObj.cover+'" target="_blank" download="video">下载封面</a><a id="form-video" href="'+jsonObj.url+'" target="_blank" download="video">下载视频</a><a id="form-music"  href="'+jsonObj.music+'" target="_blank" download="video">下载音乐(抖音)</a> ');
// }else{
//   mdui.snackbar({
//   message: '解析失败,视频不存在或者链接不正确'
// });
// }
}
                        </script>
                    </html>
                <!---->
                           <?php
} ?>
                <?php endwhile;  ?>
                </div>
                <?php comments_template('/template/comments.php', true); ?>
        </div>
    </div>
    <?php get_sidebar(); ?>
</main>
<?php
get_footer();
🎉 恭喜你发现了宝藏!>>点此前往<<

👋 感谢您的观看,对您有用就分享出去吧 !

如您有好的资源/素材,可参与创作者激励计划享投稿分成。分成介绍
投稿成功收录,即可获得 1-10元/篇奖励。(重复内容无奖励)
本站代码模板仅供学习交流使用请勿商业运营,严禁从事违法,侵权等任何非法活动,否则后果自负!
© 版权声明
THE END
文章不错?点个赞呗
点赞2赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容

随机看看好帖需要善于发现
热门圈子总有聊不完的话题