详情
评论
问答

春晓开启会员免评论查看功能

定位:/wp-content/themes/zibll/func.php文件,没有这个文件记得自己创建一个,记得加上php头,要不然会报错,将下面的代码放到里面即可!

第一步

/*
 * ========================================
 * 会员免评论查看功能
 * ========================================
 * 功能说明:为一级和二级会员用户提供免评论查看"评论可见"内容的特权
 * 支持单独控制一级和二级会员的权限
 */
function zib_vip_can_view_without_comment($user_id = 0)
{
    if (!$user_id) {
        $user_id = get_current_user_id();
    }
    if (!$user_id) {
        return false;
    }
    // 检查用户是否为会员
    if (function_exists('zib_get_user_vip_level')) {
        $vip_level = zib_get_user_vip_level($user_id);
        if ($vip_level == 1) {
            // 一级会员,检查一级会员开关
            return _pz('vip1_skip_comment_view', false);
        } elseif ($vip_level == 2) {
            // 二级会员,检查二级会员开关
            return _pz('vip2_skip_comment_view', false);
        }
    }
    return false;
}
function vip_skip_comment_view_filter($show, $type)
{
    // 只处理 reply 类型的隐藏内容
    if ($type === 'reply' && function_exists('zib_vip_can_view_without_comment')) {
        return zib_vip_can_view_without_comment();
    }
    return $show;
}
add_filter('hidecontent_is_show', 'vip_skip_comment_view_filter', 10, 2);
/**
 * 修改旧版 reply 短代码的显示逻辑
 * 通过重新定义 reply_to_read 函数来实现会员免评论查看
 */
function vip_reply_to_read($atts, $content = null)
{
    $a = '#commentform';
    extract(shortcode_atts(array("notice" => '<a class="hidden-text" href="javascript:(scrollTopTo(\'' . $a . '\',-50));"><i class="fa fa-exclamation-circle"></i>  此处内容已隐藏,请评论后刷新页面查看.</a>'), $atts));
    $_hide = '<div class="hidden-box">' . $notice . '</div>';
    $_show = '<div class="hidden-box show"><div class="hidden-text">本文隐藏内容</div>' . do_shortcode($content) . '</div>';
    if (is_super_admin()) {
        //管理员登陆直接显示内容
        return '<div class="hidden-box show"><div class="hidden-text">本文隐藏内容 - 管理员可见</div>' . do_shortcode($content) . '</div>';
    } elseif (function_exists('zib_vip_can_view_without_comment') && zib_vip_can_view_without_comment()) {
        //会员用户免评论查看
        $vip_level = function_exists('zib_get_user_vip_level') ? zib_get_user_vip_level() : 0;
        $vip_name = _pz('pay_user_vip_' . $vip_level . '_name', '会员');
        return '<div class="hidden-box show"><div class="hidden-text">本文隐藏内容 - ' . $vip_name . '专享</div>' . do_shortcode($content) . '</div>';
    } else {
        if (function_exists('zib_user_is_commented') && zib_user_is_commented()) {
            return $_show;
        } else {
            return $_hide;
        }
    }
}
remove_shortcode('reply');
add_shortcode('reply', 'vip_reply_to_read');

第二步

定位:/wp-content/themes/zibll/inc/options/admin-options.php文件,然后我们在这个文件搜:

'id'         => 'pay_user_vip_1_name',

如下图,将下面的代码放我图片指示的地方即可!

图片[1]-春晓开启会员免评论查看功能-春眠不觉晓

array(
                'title'   => '会员专属功能',
                'id'      => 'vip1_skip_comment_view',
                'label'   => '启用一级会员免评论查看功能',
                'desc'    => '开启后,一级会员用户无需评论即可查看"评论可见"的内容',
                'default' => false,
                'type'    => 'switcher',
            ),
            array(
                'dependency' => array('pay_user_vip_2_s', '!=', ''),
                'title'   => ' ',
                'subtitle' => '二级会员免评论查看',
                'id'      => 'vip2_skip_comment_view',
                'label'   => '启用二级会员免评论查看功能',
                'desc'    => '开启后,二级会员用户无需评论即可查看"评论可见"的内容<br><span style="color:#f97113;">此功能会让会员用户拥有与管理员相同的查看权限,请谨慎开启</span>',
                'default' => false,
                'type'    => 'switcher',
                'class'   => 'compact',
            ),

 

温馨提示:文章具有时效性,若有错误或已失效,请在下方留言或联系站长
© 版权声明

THE END
喜欢就支持一下吧
点赞12 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容