文章目录
本文最后更新于 2020-10-19,已超过 365 天未更新,内容可能已失效。
这个主要基于riplus会员等级做的,根据简码设定的会员权限来判断内容是否有权限查看。这个对做内容的非常有用,原主题只有付费查看内容,对会员权限没有区分!

分类权限可以点下面的查看

[wm_embed_post ids=”4818″][/wm_embed_post]

 

好了教程开始

第一步:

找到riplus/inc/admin/csf/riplus-opt/shortcoder.php。在代码最后添加

[rihide]

CSF::createSection($prefix, array(
        'title'     => '[riplus]会员等级查看',
        'view'      => 'normal',
        'shortcode' => 'riplus-levelhide',
        'fields'    => array(
            array(
            'id'      => 'level',
            'type'    => 'select',
            'title'   => '选择查看会员等级',
            'options' => array(
                '0' => '网站游客',
                '1' => '普通会员',
                '2' => '月卡会员',
                '3' => '年卡会员',
                '4' => '终身会员',
            ),
        ),
            array(
                'id'    => 'content',
                'type'  => 'wp_editor',
                'title' => '',
                'desc'  => '查看内容',
            ),

        ),
));

[/rihide]

第二步:

riplus/inc/shop-func.php代码最后添加

[rihide]

function _riplus_viphide_shortcode($atts, $content = '') {
    extract( shortcode_atts(  array( 'level' => '', ), $atts ) );
    global $wpdb;
    $dluid = get_current_user_id();
    $type = "SELECT meta_value FROM wp_usermeta WHERE user_id='$dluid' and meta_key='_riplus_vip_type'";//当前用户等级
    $type  = $wpdb->get_var($type);
    if($type=='no_vip'){
        $typeid=1;
    }elseif($type=='month_vip'){
        $typeid=2;
    }elseif($type=='year_vip'){
        $typeid=3;
    }elseif($type=='permanent_vip'){
        $typeid=4;
    }else{
        $typeid=0;
    }
    if($level == 1){
        $vip_infotext='普通会员';
    }elseif($level == 2){
        $vip_infotext='月卡会员';
    }elseif($level == 3){
        $vip_infotext='年卡会员';
    }elseif($level == 4){
        $vip_infotext='永久VIP会员';
    }
    
    $lnotice = '<div class="card text-center mb-4"> <div class="card-header text-muted"><i class="mdi mdi-lock"></i> ' . $vip_infotext . '权限查看内容</div> <div class="card-body"> <h5 class="card-title">' . __('此处内容<a href="/vipinfo" >开通'.$vip_infotext.'</a>后可见', 'riplus') . '</h5> <p class="card-text">' . esc_html__('温馨提示:此处为隐藏内容,需要开通对应的权限查看', 'riplus') . '</p> <a href="/vipinfo" class="btn btn-success btn-sm"><i class="mdi mdi-diamond-stone"></i> 开通' . $vip_infotext . '</a> </div> </div>';
    $lcontent = '<div class="card mb-4"><div class="card-header text-center text-muted"><i class="mdi mdi-lock-open"></i> ' . esc_html__('免费权限查看隐藏内容', 'riplus') . '</div><div class="card-body">'.do_shortcode($content).'</div></div>';
   
   if ($typeid>= $level) {
        return $lcontent;
    } else {
        return $lnotice;
    }
}
add_shortcode('riplus-levelhide', '_riplus_viphide_shortcode');

[/rihide]

效果

QQ截图20201019221750

QQ截图20201019220058

CC 许可协议
署名-非商业性使用-相同方式共享 4.0 国际 了解协议
文章链接:https://zptheme.com/4828.html
本文作者:子佩·来源:子佩工作室

除非注明,子佩工作室 文章均为原创,转载请以链接形式标明本文地址。

相关推荐

登录后即可发表评论

社交账号登录

全部评论 (0)